From f4e55999a5282dc1d2b94e0ca14081de6aae93ba Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 20 Oct 2018 00:33:51 +0200 Subject: [PATCH 1/8] begin porting and decomping battle tower --- asm/battle_tower.s | 278 ++--------------------------------------- include/battle_tower.h | 6 +- include/global.h | 29 +---- src/battle_tower.c | 93 +++++++++++++- src/recorded_battle.c | 30 ++--- src/tv.c | 2 +- 6 files changed, 125 insertions(+), 313 deletions(-) diff --git a/asm/battle_tower.s b/asm/battle_tower.s index ae01e0b5e..8eedaf72f 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -6,270 +6,6 @@ .text - - - thumb_func_start sub_81621C0 -sub_81621C0: @ 81621C0 - push {r4,r5,lr} - ldr r0, =gTrainerBattleOpponent_A - ldrh r1, [r0] - movs r0, 0xFA - lsls r0, 1 - cmp r1, r0 - bne _081621DA - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bec - adds r0, r1 - bl sub_816534C -_081621DA: - ldr r5, =gSaveBlock2Ptr - ldr r0, [r5] - ldr r1, =0x00000d04 - adds r2, r0, r1 - ldrh r1, [r2] - ldr r0, =0x0000270e - cmp r1, r0 - bhi _081621EE - adds r0, r1, 0x1 - strh r0, [r2] -_081621EE: - ldr r1, [r5] - ldr r4, =0x00000cb2 - adds r1, r4 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - bl sub_8163E90 - ldr r1, =gSpecialVar_Result - ldr r0, [r5] - adds r0, r4 - ldrh r0, [r0] - strh r0, [r1] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81621C0 - - thumb_func_start sub_816222C -sub_816222C: @ 816222C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x3C - movs r0, 0 - str r0, [sp, 0x24] - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - mov r10, r0 - ldr r0, =0x000040ce - bl VarGet - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x2C] - ldr r0, =0x000040cf - bl VarGet - lsls r0, 16 - cmp r0, 0 - beq _08162266 - b _0816239C -_08162266: - mov r0, r10 - ldr r1, [sp, 0x2C] - bl sub_8164FCC - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x28] - movs r7, 0 - mov r2, sp - str r2, [sp, 0x34] -_0816227A: - movs r3, 0xEC - adds r0, r7, 0 - muls r0, r3 - movs r4, 0xE7 - lsls r4, 3 - adds r0, r4 - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - movs r2, 0 - mov r8, r2 - mov r9, r2 - movs r5, 0 - adds r3, r7, 0x1 - str r3, [sp, 0x30] - adds r1, r0 -_08162298: - ldm r1!, {r0} - mov r4, r8 - orrs r4, r0 - mov r8, r4 - add r9, r0 - adds r5, 0x1 - cmp r5, 0x39 - bls _08162298 - movs r6, 0 - movs r5, 0 - movs r0, 0xEC - adds r2, r7, 0 - muls r2, r0 -_081622B2: - ldr r3, =gSaveBlock2Ptr - ldr r1, [r3] - movs r0, 0x2C - muls r0, r5 - adds r0, r2 - adds r1, r0 - ldr r4, =0x0000076c - adds r0, r1, r4 - ldrh r0, [r0] - cmp r0, 0 - beq _081622E4 - movs r0, 0xEF - lsls r0, 3 - adds r4, r1, r0 - mov r0, r10 - str r2, [sp, 0x38] - bl GetFrontierEnemyMonLevel - ldrb r1, [r4] - lsls r0, 24 - lsrs r0, 24 - ldr r2, [sp, 0x38] - cmp r1, r0 - bhi _081622E4 - adds r6, 0x1 -_081622E4: - adds r5, 0x1 - cmp r5, 0x3 - ble _081622B2 - ldr r0, =gUnknown_085DF9F6 - ldr r1, [sp, 0x2C] - adds r0, r1, r0 - ldrb r0, [r0] - cmp r6, r0 - blt _0816233E - ldr r3, =gSaveBlock2Ptr - ldr r2, [r3] - movs r4, 0xEC - adds r3, r7, 0 - muls r3, r4 - adds r1, r2, r3 - ldr r5, =0x0000073a - adds r0, r1, r5 - ldrh r0, [r0] - ldr r4, [sp, 0x28] - cmp r0, r4 - bne _0816233E - subs r5, 0x2 - adds r0, r1, r5 - ldrb r0, [r0] - cmp r0, r10 - bne _0816233E - mov r0, r8 - cmp r0, 0 - beq _0816233E - movs r1, 0x82 - lsls r1, 4 - adds r0, r2, r1 - adds r0, r3 - ldr r0, [r0] - cmp r0, r9 - bne _0816233E - movs r2, 0x96 - lsls r2, 1 - adds r0, r7, r2 - ldr r3, [sp, 0x34] - stm r3!, {r0} - str r3, [sp, 0x34] - ldr r4, [sp, 0x24] - adds r4, 0x1 - str r4, [sp, 0x24] -_0816233E: - ldr r7, [sp, 0x30] - cmp r7, 0x4 - ble _0816227A - ldr r5, [sp, 0x2C] - cmp r5, 0 - bne _08162396 - bl sub_8165B20 - movs r7, 0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r4, =gUnknown_085DF9EC - adds r2, r0, 0 - adds r2, 0xDC - ldr r1, [sp, 0x24] - lsls r0, r1, 2 - mov r5, sp - adds r3, r0, r5 -_08162362: - ldrb r0, [r2] - lsls r1, r0, 25 - lsrs r0, r1, 30 - cmp r0, 0 - beq _0816238E - ldrb r0, [r2, 0x1] - adds r0, r4 - ldrb r0, [r0] - ldr r5, [sp, 0x28] - cmp r0, r5 - bne _0816238E - lsrs r0, r1, 30 - subs r0, 0x1 - cmp r0, r10 - bne _0816238E - movs r1, 0xC8 - lsls r1, 1 - adds r0, r7, r1 - stm r3!, {r0} - ldr r5, [sp, 0x24] - adds r5, 0x1 - str r5, [sp, 0x24] -_0816238E: - adds r2, 0x44 - adds r7, 0x1 - cmp r7, 0x3 - ble _08162362 -_08162396: - ldr r0, [sp, 0x24] - cmp r0, 0 - bne _081623C0 -_0816239C: - movs r0, 0 - b _081623DA - .pool -_081623C0: - ldr r4, =gTrainerBattleOpponent_A - bl Random - lsls r0, 16 - lsrs r0, 16 - ldr r1, [sp, 0x24] - bl __modsi3 - lsls r0, 2 - add r0, sp - ldr r0, [r0] - strh r0, [r4] - movs r0, 0x1 -_081623DA: - add sp, 0x3C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_816222C - thumb_func_start sub_81623F0 sub_81623F0: @ 81623F0 push {r4-r7,lr} @@ -329,7 +65,7 @@ _08162414: b _08162530 .pool _08162488: - bl sub_816222C + bl ChooseSpecialBattleTowerTrainer lsls r0, 24 cmp r0, 0 beq _081624B4 @@ -3334,7 +3070,7 @@ sub_8163E90: @ 8163E90 lsrs r4, 24 adds r0, r5, 0 adds r1, r4, 0 - bl sub_8164FCC + bl GetCurrentBattleTowerWinStreak lsls r0, 16 lsrs r2, r0, 16 ldr r0, [r6] @@ -3420,7 +3156,7 @@ _08163F52: bl StringCopy7 adds r0, r6, 0 adds r1, r7, 0 - bl sub_8164FCC + bl GetCurrentBattleTowerWinStreak strh r0, [r5, 0x2] movs r4, 0 movs r2, 0x10 @@ -5289,8 +5025,8 @@ _08164FBE: bx r0 thumb_func_end sub_8164FB8 - thumb_func_start sub_8164FCC -sub_8164FCC: @ 8164FCC + thumb_func_start GetCurrentBattleTowerWinStreak +GetCurrentBattleTowerWinStreak: @ 8164FCC push {lr} lsls r0, 24 lsls r1, 24 @@ -5312,7 +5048,7 @@ _08164FEE: pop {r1} bx r1 .pool - thumb_func_end sub_8164FCC + thumb_func_end GetCurrentBattleTowerWinStreak thumb_func_start sub_8164FFC sub_8164FFC: @ 8164FFC @@ -5378,7 +5114,7 @@ _0816506A: strh r0, [r1] adds r0, r5, 0 adds r1, r4, 0 - bl sub_8164FCC + bl GetCurrentBattleTowerWinStreak lsls r0, 16 lsrs r0, 16 cmp r0, 0x37 diff --git a/include/battle_tower.h b/include/battle_tower.h index 5879a73bb..6af87210b 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -1,6 +1,10 @@ #ifndef GUARD_BATTLE_TOWER_H #define GUARD_BATTLE_TOWER_H +#define BATTLE_TOWER_EREADER_TRAINER_ID 200 +#define BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID 300 +#define BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID 400 + struct RSBattleTowerRecord { /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 @@ -46,7 +50,7 @@ struct FacilityMon extern const struct BattleFrontierTrainer *gFacilityTrainers; extern const struct FacilityMon *gFacilityTrainerMons; -u16 sub_8164FCC(u8, u8); +u16 GetCurrentBattleTowerWinStreak(u8, u8); void sub_81659DC(struct RSBattleTowerRecord *a0, struct RSBattleTowerRecord *a1); bool32 sub_816587C(union BattleTowerRecord *, union BattleTowerRecord *); void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *); diff --git a/include/global.h b/include/global.h index b92f1097f..35e34e722 100644 --- a/include/global.h +++ b/include/global.h @@ -275,26 +275,6 @@ struct BerryCrush u32 unk; }; -struct UnknownSaveBlock2Struct -{ - u8 field_0; - u8 field_1; - u8 field_2[2]; - u8 field_4[8]; - u8 field_C[16]; - u16 field_1C[6]; - u16 field_28[6]; - u8 field_34[176]; - u8 field_E4; - u8 field_E5; - u8 field_E6; - u8 field_E7; - u8 field_E8; - u8 field_E9; - u8 field_EA; - u8 field_EB; -}; // sizeof = 0xEC - struct ApprenticeMon { u16 species; @@ -345,7 +325,7 @@ struct UnknownPokemonStruct struct EmeraldBattleTowerRecord { - /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 + /*0x00*/ u8 lvlMode; // 0 = level 50, 1 = level 100 /*0x01*/ u8 trainerClass; /*0x02*/ u16 winStreak; /*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1]; @@ -387,7 +367,7 @@ struct BattleDomeTrainer struct BattleFrontier { /*0x64C*/ struct EmeraldBattleTowerRecord battleTower; - /*0x738*/ struct UnknownSaveBlock2Struct field_738[5]; // No idea here, it's probably wrong, no clue. + /*0x738*/ struct EmeraldBattleTowerRecord records[5]; // No idea here, it's probably wrong, no clue. /*0xBD4*/ u16 field_BD4; /*0xBD6*/ u16 field_BD6; /*0xBD8*/ u8 field_BD8[11]; @@ -415,7 +395,10 @@ struct BattleFrontier /*0xCF0*/ u16 field_CF0[2]; /*0xCF4*/ u16 field_CF4[2]; /*0xCF8*/ u16 field_CF8[2]; - /*0xCFC*/ u16 field_CFC[5]; + /*0xCFC*/ u16 field_CFC[2]; + /*0xD06*/ u16 field_D00; + /*0xD06*/ u16 field_D02; + /*0xD06*/ u16 field_D04; /*0xD06*/ u8 field_D06; /*0xD07*/ u8 field_D07; /*0xD08*/ u8 field_D08_0:1; diff --git a/src/battle_tower.c b/src/battle_tower.c index e70d4af91..a6983897f 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -4,16 +4,24 @@ #include "overworld.h" #include "random.h" #include "battle_tower.h" +#include "battle_frontier_1.h" +#include "constants/battle_frontier.h" extern void sub_81A3ACC(void); +extern u8 GetFrontierEnemyMonLevel(u8); extern const u32 gUnknown_085DF9AC[][2]; extern const u32 gUnknown_085DF9CC[][2]; extern void (* const gUnknown_085DF96C[])(void); +extern const u8 gUnknown_085DF9F6[]; +extern const u8 gUnknown_085DF9EC[]; // This file's functions. void sub_8164ED8(void); -u16 sub_8164FCC(u8, u8); +void sub_8163E90(void); +void sub_8165B20(void); +u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode); +void sub_816534C(void *); // code void sub_8161F74(void) @@ -49,7 +57,7 @@ void sub_8162054(void) case 0: break; case 1: - gSpecialVar_Result = sub_8164FCC(lvlMode, battleMode); + gSpecialVar_Result = GetCurrentBattleTowerWinStreak(lvlMode, battleMode); break; case 2: gSpecialVar_Result = ((gSaveBlock2Ptr->frontier.field_CDC & gUnknown_085DF9AC[battleMode][lvlMode]) != 0); @@ -83,3 +91,84 @@ void sub_81620F4(void) break; } } + +void sub_81621C0(void) +{ + if (gTrainerBattleOpponent_A == 500) + sub_816534C(&gSaveBlock2Ptr->frontier.filler_BEC); + + if (gSaveBlock2Ptr->frontier.field_D04 < 9999) + gSaveBlock2Ptr->frontier.field_D04++; + + gSaveBlock2Ptr->frontier.field_CB2++; + sub_8163E90(); + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CB2; +} + +bool8 ChooseSpecialBattleTowerTrainer(void) +{ + s32 i, j, validMons; + s32 trainerIds[9]; + s32 idsCount = 0; + s32 winStreak = 0; + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + + if (VarGet(VAR_FRONTIER_FACILITY) != FRONTIER_FACILITY_TOWER) + return FALSE; + + winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode); + for (i = 0; i < 5; i++) + { + u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.records[i]); + u32 recordHasData = 0; + u32 checksum = 0; + for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself. + { + recordHasData |= record[j]; + checksum += record[j]; + } + validMons = 0; + for (j = 0; j < 4; j++) + { + if (gSaveBlock2Ptr->frontier.records[i].party[j].species != 0 + && gSaveBlock2Ptr->frontier.records[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode)) + validMons++; + } + + if (validMons >= gUnknown_085DF9F6[battleMode] + && gSaveBlock2Ptr->frontier.records[i].winStreak == winStreak + && gSaveBlock2Ptr->frontier.records[i].lvlMode == lvlMode + && recordHasData + && gSaveBlock2Ptr->frontier.records[i].checksum == checksum) + { + trainerIds[idsCount] = i + BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID; + idsCount++; + } + } + + if (battleMode == FRONTIER_MODE_SINGLES) + { + sub_8165B20(); + for (i = 0; i < 4; i++) + { + if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0 + && gUnknown_085DF9EC[gSaveBlock2Ptr->apprentices[i].field_1] == winStreak + && gSaveBlock2Ptr->apprentices[i].lvlMode - 1 == lvlMode) + { + trainerIds[idsCount] = i + BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID; + idsCount++; + } + } + } + + if (idsCount != 0) + { + gTrainerBattleOpponent_A = trainerIds[Random() % idsCount]; + return TRUE; + } + else + { + return FALSE; + } +} diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 355ed5e07..0a199f289 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -402,73 +402,73 @@ u32 MoveRecordedBattleToSaveData(void) { for (i = 0; i < 8; i++) { - battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_4[i]; + battleSave->field_504[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_4[i]; } - battleSave->field_50C = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_1; + battleSave->field_50C = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_1; if (sUnknown_0203CCE8 == 1) { for (i = 0; i < 6; i++) { - battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_28[i]; + battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_28[i]; } } else { for (i = 0; i < 6; i++) { - battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_1C[i]; + battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_1C[i]; } } - battleSave->field_51A = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_E4; + battleSave->field_51A = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_E4; } else if (gTrainerBattleOpponent_B >= 300 && gTrainerBattleOpponent_B <= 399) { for (i = 0; i < 8; i++) { - battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_4[i]; + battleSave->field_504[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_4[i]; } - battleSave->field_50C = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_1; + battleSave->field_50C = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_1; if (sUnknown_0203CCE8 == 1) { for (i = 0; i < 6; i++) { - battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_28[i]; + battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_28[i]; } } else { for (i = 0; i < 6; i++) { - battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_1C[i]; + battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_1C[i]; } } - battleSave->field_51A = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_E4; + battleSave->field_51A = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_E4; } else if (gPartnerTrainerId >= 300 && gPartnerTrainerId <= 399) { for (i = 0; i < 8; i++) { - battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_4[i]; + battleSave->field_504[i] = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_4[i]; } - battleSave->field_50C = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_1; + battleSave->field_50C = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_1; if (sUnknown_0203CCE8 == 1) { for (i = 0; i < 6; i++) { - battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_28[i]; + battleSave->field_50E[i] = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_28[i]; } } else { for (i = 0; i < 6; i++) { - battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_1C[i]; + battleSave->field_50E[i] = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_1C[i]; } } - battleSave->field_51A = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_E4; + battleSave->field_51A = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_E4; } */ diff --git a/src/tv.c b/src/tv.c index fb309f6e3..3625c6cee 100644 --- a/src/tv.c +++ b/src/tv.c @@ -1544,7 +1544,7 @@ static void InterviewAfter_BravoTrainerBattleTowerProfile(void) StringCopy(show->bravoTrainerTower.pokemonName, gSaveBlock2Ptr->frontier.field_BD8); show->bravoTrainerTower.species = gSaveBlock2Ptr->frontier.field_BD4; show->bravoTrainerTower.defeatedSpecies = gSaveBlock2Ptr->frontier.field_BD6; - show->bravoTrainerTower.numFights = sub_8164FCC(gSaveBlock2Ptr->frontier.field_D07, 0); + show->bravoTrainerTower.numFights = GetCurrentBattleTowerWinStreak(gSaveBlock2Ptr->frontier.field_D07, 0); show->bravoTrainerTower.wonTheChallenge = gSaveBlock2Ptr->frontier.field_D06; if (gSaveBlock2Ptr->frontier.field_D07 == 0) { From 16026fe91d5628f138be434841ae764534946b2c Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 21 Oct 2018 00:06:42 +0200 Subject: [PATCH 2/8] More battle tower. --- asm/battle_frontier_2.s | 28 +- asm/battle_tower.s | 2546 +---------------- data/battle_tower.s | 10 +- .../scripts.inc | 2 +- data/specials.inc | 2 +- include/battle_frontier_2.h | 1 + include/battle_tower.h | 24 +- include/global.h | 32 +- src/apprentice.c | 58 +- src/battle_dome.c | 62 +- src/battle_frontier_1.c | 6 +- src/battle_setup.c | 4 +- src/battle_tent.c | 22 +- src/battle_tower.c | 977 ++++++- src/map_name_popup.c | 2 +- src/record_mixing.c | 2 +- src/start_menu.c | 4 +- src/wild_encounter.c | 4 +- 18 files changed, 1126 insertions(+), 2660 deletions(-) diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 3f6591927..48673d4fa 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -6195,8 +6195,8 @@ _081A4D90: .pool thumb_func_end CopyFrontierBrainTrainerName - thumb_func_start sub_81A4DB8 -sub_81A4DB8: @ 81A4DB8 + thumb_func_start IsFrontierBrainFemale +IsFrontierBrainFemale: @ 81A4DB8 push {lr} ldr r0, =0x000040cf bl VarGet @@ -6209,10 +6209,10 @@ sub_81A4DB8: @ 81A4DB8 pop {r1} bx r1 .pool - thumb_func_end sub_81A4DB8 + thumb_func_end IsFrontierBrainFemale - thumb_func_start sub_81A4DD8 -sub_81A4DD8: @ 81A4DD8 + thumb_func_start SetFrontierBrainTrainerGfxId +SetFrontierBrainTrainerGfxId: @ 81A4DD8 push {lr} ldr r0, =0x000040cf bl VarGet @@ -6227,10 +6227,10 @@ sub_81A4DD8: @ 81A4DD8 pop {r0} bx r0 .pool - thumb_func_end sub_81A4DD8 + thumb_func_end SetFrontierBrainTrainerGfxId - thumb_func_start sub_81A4E04 -sub_81A4E04: @ 81A4E04 + thumb_func_start CreateFrontierBrainPokemon +CreateFrontierBrainPokemon: @ 81A4E04 push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -6460,7 +6460,7 @@ _081A4FD0: pop {r0} bx r0 .pool - thumb_func_end sub_81A4E04 + thumb_func_end CreateFrontierBrainPokemon thumb_func_start sub_81A4FF0 sub_81A4FF0: @ 81A4FF0 @@ -8755,7 +8755,7 @@ sub_81A63B8: @ 81A63B8 ldr r0, =gTrainerBattleOpponent_A ldrh r0, [r0] movs r1, 0 - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId pop {r0} bx r0 .pool @@ -12662,7 +12662,7 @@ _081A831A: str r0, [r1] ldrh r0, [r5] movs r1, 0 - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0x00000cb2 @@ -12747,7 +12747,7 @@ _081A83EE: strh r4, [r5] ldrh r0, [r5] movs r1, 0 - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId ldr r3, =gSaveBlock2Ptr ldr r1, [r3] ldr r0, =0x00000cb2 @@ -12808,7 +12808,7 @@ _081A8466: strh r4, [r5] ldrh r0, [r5] movs r1, 0x1 - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0x00000cb2 @@ -17319,7 +17319,7 @@ _081AA8DC: lsrs r7, r0, 16 adds r4, r7, 0 adds r0, r4, 0 - bl sub_81627A4 + bl GetBattleFacilityTrainerGfxId strb r0, [r5, 0x1] ldr r0, =gSaveBlock2Ptr ldr r0, [r0] diff --git a/asm/battle_tower.s b/asm/battle_tower.s index 8eedaf72f..fd011c555 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -6,2508 +6,8 @@ .text - thumb_func_start sub_81623F0 -sub_81623F0: @ 81623F0 - push {r4-r7,lr} - ldr r6, =gSaveBlock2Ptr - ldr r0, [r6] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - cmp r0, 0x2 - bne _08162414 - bl sub_8165E18 - b _08162530 - .pool -_08162414: - ldr r0, =0x000040ce - bl VarGet - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - bl sub_81A39C4 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r5, r0, 16 - bl GetFacilityEnemyMonLevel - subs r4, 0x2 - cmp r4, 0x1 - bhi _08162488 - ldr r1, [r6] - ldr r2, =0x00000cb2 - adds r0, r1, r2 - ldrh r3, [r0] - ldr r2, =gTrainerBattleOpponent_A - lsls r0, r3, 2 - ldr r4, =0x00000cb4 - adds r1, r4 - adds r0, r1, r0 - ldrh r0, [r0] - strh r0, [r2] - ldr r4, =gTrainerBattleOpponent_B - lsls r0, r3, 1 - adds r0, 0x1 - lsls r0, 1 - adds r1, r0 - ldrh r0, [r1] - strh r0, [r4] - ldrh r0, [r2] - movs r1, 0 - bl sub_8162614 - ldrh r0, [r4] - movs r1, 0x1 - bl sub_8162614 - b _08162530 - .pool -_08162488: - bl ChooseSpecialBattleTowerTrainer - lsls r0, 24 - cmp r0, 0 - beq _081624B4 - ldr r4, =gTrainerBattleOpponent_A - ldrh r0, [r4] - movs r1, 0 - bl sub_8162614 - ldr r1, [r6] - ldr r2, =0x00000cb2 - adds r0, r1, r2 - ldrh r0, [r0] - lsls r0, 1 - adds r2, 0x2 - b _08162528 - .pool -_081624B4: - lsls r7, r5, 24 - adds r5, r6, 0 - ldr r6, =0x00000cb2 -_081624BA: - ldr r0, [r5] - adds r0, r6 - ldrb r1, [r0] - lsrs r0, r7, 24 - bl sub_8162548 - lsls r0, 16 - lsrs r3, r0, 16 - movs r4, 0 - ldr r1, [r5] - adds r0, r1, r6 - ldrh r0, [r0] - cmp r4, r0 - bge _081624FC - ldr r2, =0x00000cb4 - adds r0, r1, r2 - ldrh r0, [r0] - cmp r0, r3 - beq _081624FC - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - subs r2, 0x2 - adds r0, r1, r2 - ldrh r2, [r0] - ldr r0, =0x00000cb4 - adds r1, r0 -_081624EE: - adds r1, 0x2 - adds r4, 0x1 - cmp r4, r2 - bge _081624FC - ldrh r0, [r1] - cmp r0, r3 - bne _081624EE -_081624FC: - ldr r0, [r5] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - cmp r4, r0 - bne _081624BA - ldr r4, =gTrainerBattleOpponent_A - strh r3, [r4] - ldrh r0, [r4] - movs r1, 0 - bl sub_8162614 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000cb2 - adds r0, r1, r2 - ldrh r2, [r0] - adds r0, r2, 0x1 - cmp r0, 0x6 - bgt _08162530 - lsls r0, r2, 1 - ldr r2, =0x00000cb4 -_08162528: - adds r1, r2 - adds r1, r0 - ldrh r0, [r4] - strh r0, [r1] -_08162530: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81623F0 - thumb_func_start sub_8162548 -sub_8162548: @ 8162548 - push {r4,r5,lr} - lsls r0, 24 - lsrs r0, 24 - adds r3, r0, 0 - lsls r1, 24 - lsrs r1, 24 - cmp r0, 0x7 - bhi _08162584 - cmp r1, 0x6 - bne _08162570 - ldr r2, =gUnknown_085DFA1A - lsls r1, r0, 2 - adds r0, r2, 0x2 - adds r0, r1, r0 - adds r1, r2 - ldrh r0, [r0] - ldrh r4, [r1] - b _0816258A - .pool -_08162570: - ldr r2, =gUnknown_085DF9FA - lsls r1, r3, 2 - adds r0, r2, 0x2 - adds r0, r1, r0 - adds r1, r2 - ldrh r0, [r0] - ldrh r4, [r1] - b _0816258A - .pool -_08162584: - ldr r1, =gUnknown_085DF9FA - ldrh r0, [r1, 0x1E] - ldrh r4, [r1, 0x1C] -_0816258A: - subs r0, r4 - adds r0, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r5, 0 - bl __umodsi3 - adds r4, r0 - lsls r4, 16 - lsrs r5, r4, 16 - adds r0, r5, 0 - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8162548 - thumb_func_start sub_81625B4 -sub_81625B4: @ 81625B4 - push {r4,lr} - adds r4, r2, 0 - lsls r0, 24 - lsrs r0, 24 - adds r2, r0, 0 - lsls r1, 24 - lsrs r1, 24 - cmp r0, 0x7 - bhi _081625F4 - cmp r1, 0x6 - bne _081625D4 - ldr r1, =gUnknown_085DFA1A - lsls r2, r0, 2 - b _081625D8 - .pool -_081625D4: - ldr r1, =gUnknown_085DF9FA - lsls r2, 2 -_081625D8: - adds r0, r1, 0x2 - adds r0, r2, r0 - adds r2, r1 - ldrh r0, [r0] - ldrh r1, [r2] - subs r0, r1 - adds r0, 0x1 - lsls r0, 16 - lsrs r1, r0, 16 - ldrh r0, [r2] - b _08162604 - .pool -_081625F4: - ldr r0, =gUnknown_085DF9FA - ldrh r1, [r0, 0x1E] - ldrh r2, [r0, 0x1C] - subs r1, r2 - adds r1, 0x1 - lsls r1, 16 - lsrs r1, 16 - ldrh r0, [r0, 0x1C] -_08162604: - strh r0, [r4] - strb r1, [r3] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81625B4 - - thumb_func_start sub_8162614 -sub_8162614: @ 8162614 - push {r4-r6,lr} - lsls r0, 16 - lsrs r4, r0, 16 - adds r6, r4, 0 - lsls r1, 24 - lsrs r5, r1, 24 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r4, r0 - bne _08162640 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bed - adds r0, r1 - b _081626BA - .pool -_08162640: - ldr r0, =0x000003fe - cmp r4, r0 - bne _08162650 - bl sub_81A4DD8 - b _08162788 - .pool -_08162650: - ldr r0, =0x0000012b - cmp r4, r0 - bhi _0816266C - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r4 - adds r0, r1 - b _081626BA - .pool -_0816266C: - ldr r0, =0x0000018f - cmp r4, r0 - bhi _08162698 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0xfffffed4 - adds r2, r4, r1 - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - ldr r1, =0x00000739 - adds r0, r1 - b _081626BA - .pool -_08162698: - ldr r3, =gApprentices - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r2, r6, r0 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r1, r0 - adds r1, 0xDC - ldrb r0, [r1] - lsls r0, 27 - lsrs r0, 27 - movs r1, 0x58 - muls r0, r1 - adds r0, r3 - adds r0, 0x32 -_081626BA: - ldrb r2, [r0] - movs r1, 0 - ldr r3, =gUnknown_085DCEDC - ldrb r0, [r3] - cmp r0, r2 - beq _081626D4 -_081626C6: - adds r1, 0x1 - cmp r1, 0x1D - bhi _081626D4 - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _081626C6 -_081626D4: - cmp r1, 0x1E - beq _08162700 - ldr r0, =gUnknown_085DCF0E - adds r0, r1, r0 - ldrb r1, [r0] - cmp r5, 0x1 - beq _08162744 - cmp r5, 0x1 - ble _0816272E - cmp r5, 0xF - bne _0816272E - b _08162750 - .pool -_08162700: - movs r1, 0 - ldr r3, =gUnknown_085DCEFA - ldrb r0, [r3] - cmp r0, r2 - beq _08162718 -_0816270A: - adds r1, 0x1 - cmp r1, 0x13 - bhi _08162718 - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _0816270A -_08162718: - cmp r1, 0x14 - beq _0816275C - ldr r0, =gUnknown_085DCF2C - adds r0, r1, r0 - ldrb r1, [r0] - cmp r5, 0x1 - beq _08162744 - cmp r5, 0x1 - ble _0816272E - cmp r5, 0xF - beq _08162750 -_0816272E: - ldr r0, =0x00004010 - bl VarSet - b _08162788 - .pool -_08162744: - ldr r0, =0x00004011 - bl VarSet - b _08162788 - .pool -_08162750: - ldr r0, =0x0000401e - bl VarSet - b _08162788 - .pool -_0816275C: - cmp r5, 0x1 - beq _08162770 - cmp r5, 0x1 - ble _08162768 - cmp r5, 0xF - beq _08162780 -_08162768: - ldr r0, =0x00004010 - b _08162772 - .pool -_08162770: - ldr r0, =0x00004011 -_08162772: - movs r1, 0x7 - bl VarSet - b _08162788 - .pool -_08162780: - ldr r0, =0x0000401e - movs r1, 0x7 - bl VarSet -_08162788: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8162614 - - thumb_func_start sub_8162794 -sub_8162794: @ 8162794 - push {lr} - movs r0, 0xFA - lsls r0, 1 - movs r1, 0 - bl sub_8162614 - pop {r0} - bx r0 - thumb_func_end sub_8162794 - - thumb_func_start sub_81627A4 -sub_81627A4: @ 81627A4 - push {r4,r5,lr} - lsls r0, 16 - lsrs r4, r0, 16 - adds r5, r4, 0 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r4, r0 - bne _081627CC - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bed - adds r0, r1 - b _08162836 - .pool -_081627CC: - ldr r0, =0x0000012b - cmp r4, r0 - bhi _081627E8 - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r4 - adds r0, r1 - b _08162836 - .pool -_081627E8: - ldr r0, =0x0000018f - cmp r4, r0 - bhi _08162814 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0xfffffed4 - adds r2, r4, r1 - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - ldr r1, =0x00000739 - adds r0, r1 - b _08162836 - .pool -_08162814: - ldr r3, =gApprentices - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r2, r5, r0 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r1, r0 - adds r1, 0xDC - ldrb r0, [r1] - lsls r0, 27 - lsrs r0, 27 - movs r1, 0x58 - muls r0, r1 - adds r0, r3 - adds r0, 0x32 -_08162836: - ldrb r2, [r0] - movs r1, 0 - ldr r3, =gUnknown_085DCEDC - ldrb r0, [r3] - cmp r0, r2 - beq _08162850 -_08162842: - adds r1, 0x1 - cmp r1, 0x1D - bhi _08162850 - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _08162842 -_08162850: - cmp r1, 0x1E - beq _0816286C - ldr r0, =gUnknown_085DCF0E - b _08162892 - .pool -_0816286C: - movs r1, 0 - ldr r3, =gUnknown_085DCEFA - ldrb r0, [r3] - cmp r0, r2 - beq _08162884 -_08162876: - adds r1, 0x1 - cmp r1, 0x13 - bhi _08162884 - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _08162876 -_08162884: - cmp r1, 0x14 - bne _08162890 - movs r0, 0x7 - b _08162896 - .pool -_08162890: - ldr r0, =gUnknown_085DCF2C -_08162892: - adds r0, r1, r0 - ldrb r0, [r0] -_08162896: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81627A4 - - thumb_func_start sub_81628A0 -sub_81628A0: @ 81628A0 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - movs r1, 0 - mov r8, r1 - mov r10, r0 - movs r5, 0 - ldr r2, =gSaveBlock2Ptr - ldr r0, [r2] - mov r4, r10 - ldrb r4, [r4, 0xC] - str r4, [sp, 0x18] - mov r9, r5 - movs r7, 0x4 - str r7, [sp, 0x1C] - ldr r1, =0x00000744 - adds r1, r0 - mov r12, r1 -_081628CA: - movs r6, 0 - movs r3, 0 - mov r2, r12 - ldrb r0, [r2] - ldr r4, [sp, 0x18] - cmp r0, r4 - bne _081628FA - mov r4, r9 - mov r2, r10 - adds r2, 0xC -_081628DE: - adds r3, 0x1 - cmp r3, 0x3 - bgt _081628FA - ldr r7, =gSaveBlock2Ptr - ldr r0, [r7] - adds r1, r3, r4 - ldr r7, =0x00000744 - adds r0, r7 - adds r0, r1 - adds r1, r2, r3 - ldrb r0, [r0] - ldrb r1, [r1] - cmp r0, r1 - beq _081628DE -_081628FA: - cmp r3, 0x4 - bne _08162944 - movs r6, 0 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r3, =0x0000073c - adds r0, r3 - ldr r2, [sp, 0x1C] - adds r0, r2 - ldrb r0, [r0] - mov r4, r10 - ldrb r4, [r4, 0x8] - cmp r0, r4 - bne _08162944 - adds r1, r0, 0 - mov r2, r9 - adds r2, 0x4 -_0816291C: - cmp r1, 0xFF - bne _08162930 - movs r6, 0x7 - b _08162944 - .pool -_08162930: - adds r6, 0x1 - cmp r6, 0x6 - bgt _08162944 - ldr r7, =gSaveBlock2Ptr - ldr r0, [r7] - adds r0, r3 - adds r0, r2 - ldrb r0, [r0] - cmp r0, r1 - beq _0816291C -_08162944: - cmp r6, 0x7 - beq _0816295A - movs r0, 0xEC - add r9, r0 - ldr r1, [sp, 0x1C] - adds r1, 0xEC - str r1, [sp, 0x1C] - add r12, r0 - adds r5, 0x1 - cmp r5, 0x4 - ble _081628CA -_0816295A: - cmp r5, 0x4 - bgt _08162974 - ldr r2, =gSaveBlock2Ptr - ldr r0, [r2] - movs r1, 0xEC - muls r1, r5 - adds r0, r1 - movs r4, 0xE7 - lsls r4, 3 - adds r0, r4 - b _081629B2 - .pool -_08162974: - movs r5, 0 - ldr r7, =gSaveBlock2Ptr - ldr r0, [r7] - ldr r1, =0x0000073a - adds r0, r1 - ldrh r0, [r0] - cmp r0, 0 - beq _0816299E - adds r3, r7, 0 - adds r2, r1, 0 - movs r1, 0 -_0816298A: - adds r1, 0xEC - adds r5, 0x1 - cmp r5, 0x4 - bgt _081629C4 - ldr r0, [r3] - adds r0, r1 - adds r0, r2 - ldrh r0, [r0] - cmp r0, 0 - bne _0816298A -_0816299E: - cmp r5, 0x4 - bgt _081629C4 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - movs r1, 0xEC - muls r1, r5 - adds r0, r1 - movs r2, 0xE7 - lsls r2, 3 - adds r0, r2 -_081629B2: - mov r1, r10 - movs r2, 0xEC - bl memcpy - b _08162A8A - .pool -_081629C4: - mov r2, sp - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r3, =0x0000073a - adds r0, r3 - ldrh r0, [r0] - movs r1, 0 - strh r0, [r2] - add r0, sp, 0xC - strh r1, [r0] - movs r7, 0x1 - add r8, r7 - movs r5, 0x1 - add r0, sp, 0xC - mov r9, r0 - mov r12, r3 -_081629E4: - movs r3, 0 - adds r7, r5, 0x1 - cmp r3, r8 - bge _08162A2E - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - movs r2, 0xEC - adds r1, r5, 0 - muls r1, r2 - adds r0, r1 - mov r1, r12 - adds r4, r0, r1 - mov r6, sp -_081629FE: - lsls r0, r3, 1 - add r0, sp - ldrh r2, [r4] - adds r1, r2, 0 - ldrh r0, [r0] - cmp r1, r0 - bcs _08162A24 - movs r3, 0 - movs r4, 0x1 - mov r8, r4 - strh r2, [r6] - mov r0, r9 - strh r5, [r0] - b _08162A2E - .pool -_08162A24: - cmp r1, r0 - bhi _08162A2E - adds r3, 0x1 - cmp r3, r8 - blt _081629FE -_08162A2E: - cmp r3, r8 - bne _08162A54 - mov r1, r8 - lsls r2, r1, 1 - mov r4, sp - adds r3, r4, r2 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - movs r4, 0xEC - adds r1, r5, 0 - muls r1, r4 - adds r0, r1 - add r0, r12 - ldrh r0, [r0] - strh r0, [r3] - add r2, r9 - strh r5, [r2] - movs r0, 0x1 - add r8, r0 -_08162A54: - adds r5, r7, 0 - cmp r5, 0x4 - ble _081629E4 - bl Random - lsls r0, 16 - lsrs r0, 16 - mov r1, r8 - bl __modsi3 - adds r5, r0, 0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - lsls r1, r5, 1 - add r1, sp - adds r1, 0xC - ldrh r2, [r1] - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - movs r1, 0xE7 - lsls r1, 3 - adds r0, r1 - mov r1, r10 - movs r2, 0xEC - bl memcpy -_08162A8A: - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81628A0 - - thumb_func_start GetFrontierTrainerFrontSpriteId -GetFrontierTrainerFrontSpriteId: @ 8162AA0 - push {r4,r5,lr} - lsls r0, 16 - lsrs r4, r0, 16 - adds r5, r4, 0 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r4, r0 - bne _08162AD0 - ldr r1, =gFacilityClassToPicIndex - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000bed - adds r0, r2 - ldrb r0, [r0] - adds r0, r1 - b _08162BC8 - .pool -_08162AD0: - ldr r0, =0x000003fe - cmp r4, r0 - bne _08162AE4 - bl GetFrontierBrainTrainerPicIndex - lsls r0, 24 - lsrs r0, 24 - b _08162BCA - .pool -_08162AE4: - ldr r0, =0x0000012b - cmp r4, r0 - bhi _08162B08 - ldr r2, =gFacilityClassToPicIndex - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r4 - adds r0, r1 - ldrb r0, [r0] - adds r0, r2 - b _08162BC8 - .pool -_08162B08: - ldr r0, =0x0000018f - cmp r4, r0 - bhi _08162B64 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08162B38 - ldr r4, =gFacilityClassToPicIndex - bl sub_818649C - lsls r0, 24 - lsrs r0, 24 - adds r0, r4 - b _08162BC8 - .pool -_08162B38: - ldr r3, =gFacilityClassToPicIndex - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0xfffffed4 - adds r2, r4, r1 - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - ldr r2, =0x00000739 - adds r0, r2 - ldrb r0, [r0] - adds r0, r3 - b _08162BC8 - .pool -_08162B64: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - bne _08162BB0 - ldr r4, =gFacilityClassToPicIndex - ldr r3, =gApprentices - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r2, r5, r0 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r1, r0 - adds r1, 0xDC - ldrb r0, [r1] - lsls r0, 27 - lsrs r0, 27 - movs r1, 0x58 - muls r0, r1 - adds r0, r3 - adds r0, 0x32 - ldrb r0, [r0] - adds r0, r4 - b _08162BC8 - .pool -_08162BB0: - ldr r5, =gFacilityClassToPicIndex - ldr r4, =gApprentices - bl sub_81864A8 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x58 - muls r0, r1 - adds r0, r4 - adds r0, 0x32 - ldrb r0, [r0] - adds r0, r5 -_08162BC8: - ldrb r0, [r0] -_08162BCA: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end GetFrontierTrainerFrontSpriteId - - thumb_func_start GetFrontierOpponentClass -GetFrontierOpponentClass: @ 8162BD8 - push {r4,r5,lr} - lsls r0, 16 - lsrs r4, r0, 16 - adds r5, r4, 0 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r4, r0 - bne _08162C08 - ldr r1, =gFacilityClassToTrainerClass - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000bed - adds r0, r2 - ldrb r0, [r0] - b _08162C26 - .pool -_08162C08: - ldr r0, =0x000003fe - cmp r4, r0 - bne _08162C1C - bl GetFrontierBrainTrainerClass - lsls r0, 24 - lsrs r0, 24 - b _08162D1E - .pool -_08162C1C: - ldr r0, =0x00000c03 - cmp r4, r0 - bne _08162C38 - ldr r0, =gTrainers - ldr r1, =0x00007da1 -_08162C26: - adds r0, r1 - ldrb r0, [r0] - b _08162D1E - .pool -_08162C38: - ldr r0, =0x0000012b - cmp r4, r0 - bhi _08162C60 - ldr r2, =gFacilityClassToTrainerClass - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r4 - adds r0, r1 - ldrb r0, [r0] - adds r0, r2 - ldrb r0, [r0] - b _08162D1E - .pool -_08162C60: - ldr r0, =0x0000018f - cmp r4, r0 - bhi _08162CBC - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08162C90 - ldr r4, =gFacilityClassToTrainerClass - bl sub_818649C - lsls r0, 24 - lsrs r0, 24 - adds r0, r4 - ldrb r0, [r0] - b _08162D1E - .pool -_08162C90: - ldr r3, =gFacilityClassToTrainerClass - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0xfffffed4 - adds r2, r4, r1 - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - ldr r2, =0x00000739 - adds r0, r2 - ldrb r0, [r0] - adds r0, r3 - ldrb r0, [r0] - b _08162D1E - .pool -_08162CBC: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08162CF4 - ldr r5, =gFacilityClassToTrainerClass - ldr r4, =gApprentices - bl sub_81864A8 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x58 - muls r0, r1 - adds r0, r4 - adds r0, 0x32 - ldrb r0, [r0] - adds r0, r5 - ldrb r0, [r0] - b _08162D1E - .pool -_08162CF4: - ldr r4, =gFacilityClassToTrainerClass - ldr r3, =gApprentices - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r2, r5, r0 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r1, r0 - adds r1, 0xDC - ldrb r0, [r1] - lsls r0, 27 - lsrs r0, 27 - movs r1, 0x58 - muls r0, r1 - adds r0, r3 - adds r0, 0x32 - ldrb r0, [r0] - adds r0, r4 - ldrb r0, [r0] -_08162D1E: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end GetFrontierOpponentClass - - thumb_func_start sub_8162D34 -sub_8162D34: @ 8162D34 - push {r4,r5,lr} - lsls r0, 16 - lsrs r4, r0, 16 - adds r5, r4, 0 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r4, r0 - bne _08162D5C - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bed - adds r0, r1 - b _08162E0A - .pool -_08162D5C: - ldr r0, =0x0000012b - cmp r4, r0 - bhi _08162D78 - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r4 - adds r0, r1 - b _08162E0A - .pool -_08162D78: - ldr r0, =0x0000018f - cmp r4, r0 - bhi _08162DC0 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08162DA0 - bl sub_818649C - lsls r0, 24 - lsrs r0, 24 - b _08162E0C - .pool -_08162DA0: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0xfffffed4 - adds r2, r4, r1 - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - ldr r1, =0x00000739 - adds r0, r1 - b _08162E0A - .pool -_08162DC0: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08162DE8 - ldr r4, =gApprentices - bl sub_81864A8 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x58 - muls r0, r1 - adds r0, r4 - b _08162E08 - .pool -_08162DE8: - ldr r3, =gApprentices - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r2, r5, r0 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r1, r0 - adds r1, 0xDC - ldrb r0, [r1] - lsls r0, 27 - lsrs r0, 27 - movs r1, 0x58 - muls r0, r1 - adds r0, r3 -_08162E08: - adds r0, 0x32 -_08162E0A: - ldrb r0, [r0] -_08162E0C: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8162D34 - - thumb_func_start GetFrontierTrainerName -GetFrontierTrainerName: @ 8162E20 - push {r4-r6,lr} - adds r6, r0, 0 - lsls r1, 16 - lsrs r5, r1, 16 - movs r4, 0 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r5, r0 - bne _08162E54 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r1, 0xBF - lsls r1, 4 - adds r2, r0, r1 -_08162E40: - adds r0, r6, r4 - adds r1, r2, r4 - ldrb r1, [r1] - strb r1, [r0] - adds r4, 0x1 - cmp r4, 0x6 - ble _08162E40 - b _08162F5C - .pool -_08162E54: - ldr r0, =0x000003fe - cmp r5, r0 - bne _08162E68 - adds r0, r6, 0 - bl CopyFrontierBrainTrainerName - b _08162F62 - .pool -_08162E68: - ldr r0, =0x00000c03 - cmp r5, r0 - bne _08162E88 - ldr r2, =gTrainers + 804 * 0x28 + 0x4 @ TRAINER_STEVEN name -_08162E70: - adds r0, r6, r4 - adds r1, r4, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r4, 0x1 - cmp r4, 0x6 - ble _08162E70 - b _08162F5C - .pool -_08162E88: - ldr r0, =0x0000012b - cmp r5, r0 - bhi _08162EB4 - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r5 - adds r0, r1 - adds r2, r0, 0x4 -_08162E9A: - adds r0, r6, r4 - adds r1, r2, r4 - ldrb r1, [r1] - strb r1, [r0] - adds r4, 0x1 - cmp r4, 0x6 - ble _08162E9A - b _08162F5C - .pool -_08162EB4: - ldr r0, =0x0000018f - cmp r5, r0 - bhi _08162F00 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08162ED8 - adds r0, r6, 0 - bl sub_8186468 - b _08162F62 - .pool -_08162ED8: - ldr r2, =gSaveBlock2Ptr - movs r0, 0xEC - adds r1, r5, 0 - muls r1, r0 - ldr r0, =0xfffef2a8 - adds r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r1, r0, 0x4 - adds r0, 0xE4 - ldrb r2, [r0] - adds r0, r6, 0 - bl TVShowConvertInternationalString - b _08162F62 - .pool -_08162F00: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08162F24 - bl sub_81864A8 - lsls r0, 24 - lsrs r5, r0, 24 - bl sub_81864C0 - lsls r0, 24 - lsrs r4, r0, 24 - b _08162F3E - .pool -_08162F24: - ldr r1, =gSaveBlock2Ptr - lsls r0, r5, 4 - adds r0, r5 - lsls r0, 2 - ldr r2, =0xffff969c - adds r0, r2 - ldr r1, [r1] - adds r1, r0 - ldrb r0, [r1] - lsls r0, 27 - lsrs r5, r0, 27 - adds r1, 0x3F - ldrb r4, [r1] -_08162F3E: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetApprenticeNameInLanguage - adds r1, r0, 0 - adds r0, r6, 0 - adds r2, r4, 0 - bl TVShowConvertInternationalString - b _08162F62 - .pool -_08162F5C: - adds r1, r6, r4 - movs r0, 0xFF - strb r0, [r1] -_08162F62: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end GetFrontierTrainerName - - thumb_func_start sub_8162F68 -sub_8162F68: @ 8162F68 - push {r4,r5,lr} - lsls r0, 16 - lsrs r4, r0, 16 - adds r5, r4, 0 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r4, r0 - bne _08162F90 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bed - adds r0, r1 - b _0816300E - .pool -_08162F90: - ldr r0, =0x000003fe - cmp r4, r0 - bne _08162FA4 - bl sub_81A4DB8 - lsls r0, 24 - lsrs r0, 24 - b _08163042 - .pool -_08162FA4: - ldr r0, =0x0000012b - cmp r4, r0 - bhi _08162FC0 - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r4 - adds r0, r1 - b _0816300E - .pool -_08162FC0: - ldr r0, =0x0000018f - cmp r4, r0 - bhi _08162FEC - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0xfffffed4 - adds r2, r4, r1 - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - ldr r1, =0x00000739 - adds r0, r1 - b _0816300E - .pool -_08162FEC: - ldr r3, =gApprentices - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r2, r5, r0 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r1, r0 - adds r1, 0xDC - ldrb r0, [r1] - lsls r0, 27 - lsrs r0, 27 - movs r1, 0x58 - muls r0, r1 - adds r0, r3 - adds r0, 0x32 -_0816300E: - ldrb r2, [r0] - movs r1, 0 - ldr r3, =gUnknown_085DCEFA - ldrb r0, [r3] - cmp r0, r2 - beq _08163028 -_0816301A: - adds r1, 0x1 - cmp r1, 0x13 - bhi _08163028 - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _0816301A -_08163028: - cmp r1, 0x14 - bne _08163040 - movs r0, 0 - b _08163042 - .pool -_08163040: - movs r0, 0x1 -_08163042: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8162F68 - - thumb_func_start sub_8163048 -sub_8163048: @ 8163048 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl ZeroEnemyPartyMons - ldr r0, =gTrainerBattleOpponent_A - ldrh r0, [r0] - movs r1, 0 - adds r2, r4, 0 - bl sub_81630C4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8163048 - - thumb_func_start sub_816306C -sub_816306C: @ 816306C - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl ZeroEnemyPartyMons - ldr r0, =gTrainerBattleOpponent_A - ldrh r0, [r0] - movs r1, 0 - adds r2, r4, 0 - bl sub_81630C4 - ldr r0, =gTrainerBattleOpponent_B - ldrh r0, [r0] - movs r1, 0x3 - adds r2, r4, 0 - bl sub_81630C4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_816306C - - thumb_func_start sub_81630A0 -sub_81630A0: @ 81630A0 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl ZeroEnemyPartyMons - ldr r0, =gTrainerBattleOpponent_A - ldrh r0, [r0] - movs r1, 0 - adds r2, r4, 0 - bl sub_8165EA4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81630A0 - - thumb_func_start sub_81630C4 -sub_81630C4: @ 81630C4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x40 - lsls r0, 16 - lsrs r5, r0, 16 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x18] - lsls r2, 24 - lsrs r2, 24 - str r2, [sp, 0x1C] - add r4, sp, 0x14 - movs r0, 0xFF - strb r0, [r4] - bl GetFacilityEnemyMonLevel - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x20] - ldr r0, =0x0000012b - cmp r5, r0 - bhi _08163138 - adds r0, r5, 0 - bl sub_8165D08 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x24] - ldr r0, =gTrainerBattleOpponent_A - ldrh r2, [r0] - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r2 - adds r0, r1 - ldr r0, [r0, 0x30] - str r0, [sp, 0x2C] - movs r0, 0 - str r0, [sp, 0x28] - ldr r2, [sp, 0x2C] - ldrh r1, [r2] - ldr r0, =0x0000ffff - cmp r1, r0 - bne _08163124 - b _08163278 -_08163124: - b _08163260 - .pool -_08163138: - movs r0, 0xFA - lsls r0, 1 - cmp r5, r0 - bne _08163180 - ldr r7, [sp, 0x18] - adds r0, r7, 0x3 - cmp r7, r0 - blt _0816314A - b _08163426 -_0816314A: - ldr r4, =gSaveBlock2Ptr -_0816314C: - movs r0, 0x64 - muls r0, r7 - ldr r1, =gEnemyParty - adds r0, r1 - ldr r5, [sp, 0x18] - subs r2, r7, r5 - movs r1, 0x2C - muls r2, r1 - movs r6, 0xC2 - lsls r6, 4 - adds r2, r6 - ldr r1, [r4] - adds r1, r2 - bl sub_806819C - adds r7, 0x1 - adds r0, r5, 0 - adds r0, 0x3 - cmp r7, r0 - blt _0816314C - b _08163426 - .pool -_08163180: - ldr r0, =0x000003fe - cmp r5, r0 - bne _08163190 - bl sub_81A4E04 - b _08163426 - .pool -_08163190: - ldr r0, =0x0000018f - cmp r5, r0 - bhi _08163218 - movs r6, 0 - ldr r7, [sp, 0x18] - ldr r1, [sp, 0x1C] - adds r0, r7, r1 - cmp r7, r0 - blt _081631A4 - b _08163426 -_081631A4: - ldr r2, =0xfffffed4 - adds r1, r5, r2 - movs r0, 0xEC - adds r2, r1, 0 - muls r2, r0 - mov r8, r2 - muls r0, r5 - ldr r5, =0xfffef2a8 - adds r4, r0, r5 -_081631B6: - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - movs r0, 0x2C - adds r2, r6, 0 - muls r2, r0 - mov r1, r8 - adds r0, r2, r1 - adds r1, r3, r0 - ldr r5, =0x0000076c - adds r0, r1, r5 - ldrh r0, [r0] - cmp r0, 0 - beq _081631F0 - adds r5, 0xC - adds r0, r1, r5 - ldrb r0, [r0] - ldr r1, [sp, 0x20] - cmp r0, r1 - bhi _081631F0 - movs r0, 0x64 - muls r0, r7 - ldr r1, =gEnemyParty - adds r0, r1 - adds r1, r3, r4 - adds r2, 0x34 - adds r1, r2 - movs r2, 0 - bl sub_8068338 -_081631F0: - adds r6, 0x1 - adds r7, 0x1 - ldr r2, [sp, 0x18] - ldr r5, [sp, 0x1C] - adds r0, r2, r5 - cmp r7, r0 - blt _081631B6 - b _08163426 - .pool -_08163218: - ldr r7, [sp, 0x18] - adds r0, r7, 0x3 - cmp r7, r0 - blt _08163222 - b _08163426 -_08163222: - ldr r6, =gSaveBlock2Ptr - lsls r0, r5, 4 - adds r0, r5 - lsls r0, 2 - ldr r1, =0xffff969c - adds r5, r0, r1 - movs r4, 0 -_08163230: - movs r0, 0x64 - muls r0, r7 - ldr r1, =gEnemyParty - adds r0, r1 - ldr r1, [r6] - adds r1, r5 - lsrs r2, r4, 24 - bl CreateApprenticeMon - movs r2, 0x80 - lsls r2, 17 - adds r4, r2 - adds r7, 0x1 - ldr r0, [sp, 0x18] - adds r0, 0x3 - cmp r7, r0 - blt _08163230 - b _08163426 - .pool -_08163260: - ldr r0, [sp, 0x28] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x28] - lsls r0, 1 - ldr r5, [sp, 0x2C] - adds r0, r5 - ldrh r1, [r0] - ldr r0, =0x0000ffff - cmp r1, r0 - bne _08163260 -_08163278: - movs r7, 0 - bl Random - adds r4, r0, 0 - bl Random - lsls r4, 16 - lsrs r4, 16 - lsls r0, 16 - orrs r4, r0 - str r4, [sp, 0x30] - ldr r6, [sp, 0x1C] - cmp r7, r6 - bne _08163296 - b _08163426 -_08163296: - bl Random - lsls r0, 16 - lsrs r0, 16 - ldr r1, [sp, 0x28] - bl __modsi3 - lsls r0, 1 - ldr r1, [sp, 0x2C] - adds r0, r1 - ldrh r4, [r0] - ldr r2, [sp, 0x20] - cmp r2, 0x32 - beq _081632B6 - cmp r2, 0x14 - bne _081632BE -_081632B6: - ldr r0, =0x00000351 - cmp r4, r0 - bls _081632BE - b _0816341E -_081632BE: - movs r6, 0 - ldr r5, [sp, 0x18] - adds r5, r7 - mov r8, r5 - b _081632D2 - .pool -_081632D0: - adds r6, 0x1 -_081632D2: - cmp r6, r8 - bge _081632F6 - movs r1, 0x64 - adds r0, r6, 0 - muls r0, r1 - ldr r2, =gEnemyParty - adds r0, r2 - movs r1, 0xB - movs r2, 0 - bl GetMonData - ldr r1, =gFacilityTrainerMons - ldr r2, [r1] - lsls r1, r4, 4 - adds r1, r2 - ldrh r1, [r1] - cmp r0, r1 - bne _081632D0 -_081632F6: - cmp r6, r8 - beq _081632FC - b _0816341E -_081632FC: - movs r6, 0 - cmp r6, r8 - bge _08163346 - ldr r5, =gBattleFrontierHeldItems - mov r9, r5 - movs r3, 0 -_08163308: - ldr r0, =gEnemyParty - adds r5, r3, r0 - adds r0, r5, 0 - movs r1, 0xC - movs r2, 0 - str r3, [sp, 0x38] - bl GetMonData - ldr r3, [sp, 0x38] - cmp r0, 0 - beq _0816333E - adds r0, r5, 0 - movs r1, 0xC - movs r2, 0 - bl GetMonData - ldr r1, =gFacilityTrainerMons - ldr r2, [r1] - lsls r1, r4, 4 - adds r1, r2 - ldrb r1, [r1, 0xA] - lsls r1, 1 - add r1, r9 - ldr r3, [sp, 0x38] - ldrh r1, [r1] - cmp r0, r1 - beq _08163346 -_0816333E: - adds r3, 0x64 - adds r6, 0x1 - cmp r6, r8 - blt _08163308 -_08163346: - cmp r6, r8 - bne _0816341E - movs r6, 0 - cmp r6, r7 - bge _08163368 - add r0, sp, 0xC - ldrh r0, [r0] - cmp r0, r4 - beq _08163368 - add r1, sp, 0xC -_0816335A: - adds r1, 0x2 - adds r6, 0x1 - cmp r6, r7 - bge _08163368 - ldrh r0, [r1] - cmp r0, r4 - bne _0816335A -_08163368: - cmp r6, r7 - bne _0816341E - lsls r0, r7, 1 - add r0, sp - adds r0, 0xC - strh r4, [r0] - movs r1, 0x64 - mov r0, r8 - muls r0, r1 - ldr r2, =gEnemyParty - adds r0, r2 - ldr r5, =gFacilityTrainerMons - ldr r2, [r5] - lsls r4, 4 - adds r2, r4, r2 - ldrh r1, [r2] - ldrb r3, [r2, 0xC] - ldr r6, [sp, 0x24] - str r6, [sp] - ldrb r2, [r2, 0xB] - str r2, [sp, 0x4] - ldr r2, [sp, 0x30] - str r2, [sp, 0x8] - ldr r2, [sp, 0x20] - bl CreateMonWithEVSpreadPersonalityOTID - movs r0, 0xFF - mov r6, sp - strb r0, [r6, 0x14] - movs r6, 0 - adds r0, r7, 0x1 - str r0, [sp, 0x34] - mov r9, r4 - movs r0, 0x64 - mov r3, r8 - muls r3, r0 - mov r1, r9 - str r1, [sp, 0x3C] - ldr r2, =gEnemyParty - mov r10, r2 -_081633B8: - ldr r0, [r5] - ldr r7, [sp, 0x3C] - adds r0, r7, r0 - lsls r4, r6, 1 - adds r0, 0x2 - adds r0, r4 - ldrh r1, [r0] - lsls r2, r6, 24 - lsrs r2, 24 - mov r7, r10 - adds r0, r3, r7 - str r3, [sp, 0x38] - bl SetMonMoveSlot - ldr r0, [r5] - ldr r1, [sp, 0x3C] - adds r0, r1, r0 - adds r0, 0x2 - adds r0, r4 - ldrh r0, [r0] - ldr r3, [sp, 0x38] - cmp r0, 0xDA - bne _081633EC - movs r0, 0 - mov r2, sp - strb r0, [r2, 0x14] -_081633EC: - adds r6, 0x1 - cmp r6, 0x3 - ble _081633B8 - movs r5, 0x64 - mov r4, r8 - muls r4, r5 - ldr r6, =gEnemyParty - adds r4, r6 - adds r0, r4, 0 - movs r1, 0x20 - add r2, sp, 0x14 - bl SetMonData - ldr r0, =gFacilityTrainerMons - ldr r0, [r0] - add r0, r9 - ldrb r2, [r0, 0xA] - lsls r2, 1 - ldr r0, =gBattleFrontierHeldItems - adds r2, r0 - adds r0, r4, 0 - movs r1, 0xC - bl SetMonData - ldr r7, [sp, 0x34] -_0816341E: - ldr r0, [sp, 0x1C] - cmp r7, r0 - beq _08163426 - b _08163296 -_08163426: - add sp, 0x40 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81630C4 - - thumb_func_start sub_8163444 -sub_8163444: @ 8163444 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x8] - movs r1, 0xFF - add r0, sp, 0x4 - strb r1, [r0] - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - movs r0, 0xDC - adds r0, r2 - mov r10, r0 - ldrb r0, [r0, 0x1] - movs r1, 0x9 - str r1, [sp, 0x10] - cmp r0, 0x4 - bhi _08163474 - movs r0, 0x6 - str r0, [sp, 0x10] -_08163474: - ldr r1, =0x00000ca9 - adds r0, r2, r1 - ldrb r1, [r0] - movs r0, 0x3 - ands r0, r1 - movs r1, 0x32 - str r1, [sp, 0xC] - cmp r0, 0 - beq _0816348A - movs r0, 0x64 - str r0, [sp, 0xC] -_0816348A: - movs r7, 0 - adds r2, 0xE2 - str r2, [sp, 0x14] - add r1, sp, 0x4 - mov r9, r1 -_08163494: - ldr r2, [sp, 0x8] - adds r6, r2, r7 - movs r0, 0x64 - muls r0, r6 - ldr r1, =gEnemyParty - adds r0, r1 - lsls r5, r7, 1 - adds r4, r5, r7 - lsls r4, 2 - mov r2, r10 - adds r1, r2, r4 - ldrh r1, [r1, 0x4] - movs r2, 0x8 - str r2, [sp] - ldr r2, [sp, 0xC] - ldr r3, [sp, 0x10] - bl CreateMonWithEVSpread - movs r0, 0xFF - mov r1, r9 - strb r0, [r1] - adds r2, r7, 0x1 - mov r8, r2 - movs r1, 0x3 -_081634C4: - ldr r2, [sp, 0x14] - adds r0, r2, r4 - ldrh r0, [r0] - cmp r0, 0xDA - bne _081634D4 - movs r2, 0 - mov r0, r9 - strb r2, [r0] -_081634D4: - adds r4, 0x2 - subs r1, 0x1 - cmp r1, 0 - bge _081634C4 - movs r0, 0x64 - adds r4, r6, 0 - muls r4, r0 - ldr r0, =gEnemyParty - adds r4, r0 - adds r0, r4, 0 - movs r1, 0x20 - add r2, sp, 0x4 - bl SetMonData - adds r2, r5, r7 - lsls r2, 2 - add r2, r10 - adds r2, 0xE - adds r0, r4, 0 - movs r1, 0xC - bl SetMonData - mov r7, r8 - cmp r7, 0x3 - bne _08163494 - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8163444 - - thumb_func_start RandomizeFacilityTrainerMonId -RandomizeFacilityTrainerMonId: @ 8163524 - push {r4-r6,lr} - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - bl GetFacilityEnemyMonLevel - lsls r0, 24 - lsrs r6, r0, 24 - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r4 - adds r0, r1 - ldr r5, [r0, 0x30] - movs r4, 0 - ldrh r1, [r5] - b _08163558 - .pool -_0816354C: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r0, r4, 1 - adds r0, r5 - ldrh r1, [r0] -_08163558: - ldr r0, =0x0000ffff - cmp r1, r0 - bne _0816354C -_0816355E: - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r4, 0 - bl __modsi3 - lsls r0, 1 - adds r0, r5 - ldrh r1, [r0] - cmp r6, 0x32 - beq _0816357A - cmp r6, 0x14 - bne _08163580 -_0816357A: - ldr r0, =0x00000351 - cmp r1, r0 - bhi _0816355E -_08163580: - adds r0, r1, 0 - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end RandomizeFacilityTrainerMonId - - thumb_func_start sub_8163590 -sub_8163590: @ 8163590 - push {lr} - bl ZeroEnemyPartyMons - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - beq _081635C0 - ldr r0, =gTrainerBattleOpponent_A - ldrh r0, [r0] - movs r1, 0 - bl sub_81635D4 - b _081635CA - .pool -_081635C0: - ldr r0, =gTrainerBattleOpponent_A - ldrh r0, [r0] - movs r1, 0 - bl sub_816379C -_081635CA: - pop {r0} - bx r0 - .pool - thumb_func_end sub_8163590 - - thumb_func_start sub_81635D4 -sub_81635D4: @ 81635D4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - lsls r0, 16 - lsrs r2, r0, 16 - adds r3, r2, 0 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x10] - ldr r0, =0x0000012b - cmp r2, r0 - bhi _0816364A - ldr r4, =gSaveBlock2Ptr - ldr r0, =0x000040ce - bl VarGet - lsls r0, 24 - ldr r4, [r4] - lsrs r0, 22 - movs r2, 0xCE - lsls r2, 4 - adds r1, r4, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 24 - lsrs r1, r0, 24 - ldr r3, =0x00000cb2 - adds r4, r3 - ldrh r0, [r4] - cmp r0, 0x5 - bhi _0816363C - adds r0, r1, 0 - movs r1, 0 - bl sub_81A6CA8 - lsls r0, 24 - lsrs r0, 24 - b _081636A6 - .pool -_0816363C: - adds r0, r1, 0 - movs r1, 0x1 - bl sub_81A6CA8 - lsls r0, 24 - lsrs r0, 24 - b _081636A6 -_0816364A: - movs r0, 0xFA - lsls r0, 1 - cmp r2, r0 - bne _08163694 - ldr r7, [sp, 0x10] - adds r0, r7, 0x3 - cmp r7, r0 - blt _0816365C - b _08163776 -_0816365C: - ldr r4, =gSaveBlock2Ptr -_0816365E: - movs r0, 0x64 - muls r0, r7 - ldr r1, =gEnemyParty - adds r0, r1 - ldr r1, [sp, 0x10] - subs r2, r7, r1 - movs r1, 0x2C - muls r2, r1 - movs r3, 0xC2 - lsls r3, 4 - adds r2, r3 - ldr r1, [r4] - adds r1, r2 - bl sub_806819C - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 - ldr r0, [sp, 0x10] - adds r0, 0x3 - cmp r7, r0 - blt _0816365E - b _08163776 - .pool -_08163694: - ldr r0, =0x000003fe - cmp r3, r0 - bne _081636A4 - bl sub_81A6CD0 - b _08163776 - .pool -_081636A4: - movs r0, 0x1F -_081636A6: - str r0, [sp, 0x18] - bl GetFacilityEnemyMonLevel - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x14] - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldrb r2, [r1, 0xA] - ldrb r0, [r1, 0xB] - lsls r0, 8 - orrs r2, r0 - ldrb r0, [r1, 0xC] - lsls r0, 16 - orrs r2, r0 - ldrb r0, [r1, 0xD] - lsls r0, 24 - orrs r2, r0 - mov r8, r2 - movs r7, 0 -_081636CE: - ldr r1, =gUnknown_03006298 - lsls r0, r7, 1 - adds r0, r1 - ldrh r0, [r0] - mov r9, r0 - ldr r3, [sp, 0x10] - adds r5, r3, r7 - movs r0, 0x64 - adds r6, r5, 0 - muls r6, r0 - ldr r1, =gEnemyParty - adds r0, r6, r1 - ldr r3, =gFacilityTrainerMons - ldr r2, [r3] - mov r1, r9 - lsls r4, r1, 4 - adds r2, r4, r2 - ldrh r1, [r2] - ldrb r3, [r2, 0xC] - mov r10, r3 - ldr r3, [sp, 0x18] - str r3, [sp] - ldrb r2, [r2, 0xB] - str r2, [sp, 0x4] - mov r2, r8 - str r2, [sp, 0x8] - ldr r2, [sp, 0x14] - mov r3, r10 - bl CreateMonWithEVSpreadPersonalityOTID - movs r1, 0 - add r0, sp, 0xC - strb r1, [r0] - movs r3, 0 - adds r7, 0x1 - mov r10, r7 - adds r7, r4, 0 -_08163718: - ldr r0, =gFacilityTrainerMons - ldr r1, [r0] - mov r2, r9 - lsls r0, r2, 4 - adds r0, r1 - lsls r1, r3, 1 - adds r0, 0x2 - adds r0, r1 - ldrh r1, [r0] - ldr r2, =gEnemyParty - adds r0, r6, r2 - adds r2, r3, 0 - str r3, [sp, 0x1C] - bl SetMonMoveAvoidReturn - ldr r3, [sp, 0x1C] - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0x3 - bls _08163718 - movs r3, 0x64 - adds r4, r5, 0 - muls r4, r3 - ldr r0, =gEnemyParty - adds r4, r0 - adds r0, r4, 0 - movs r1, 0x20 - add r2, sp, 0xC - bl SetMonData - ldr r1, =gFacilityTrainerMons - ldr r0, [r1] - adds r0, r7, r0 - ldrb r2, [r0, 0xA] - lsls r2, 1 - ldr r0, =gBattleFrontierHeldItems - adds r2, r0 - adds r0, r4, 0 - movs r1, 0xC - bl SetMonData - mov r2, r10 - lsls r0, r2, 24 - lsrs r7, r0, 24 - cmp r7, 0x2 - bls _081636CE -_08163776: - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81635D4 - - thumb_func_start sub_816379C -sub_816379C: @ 816379C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x10] - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldrb r0, [r1, 0xA] - mov r9, r0 - ldrb r0, [r1, 0xB] - lsls r0, 8 - mov r2, r9 - orrs r2, r0 - ldrb r0, [r1, 0xC] - lsls r0, 16 - orrs r2, r0 - ldrb r0, [r1, 0xD] - lsls r0, 24 - orrs r2, r0 - mov r9, r2 - movs r7, 0 - mov r8, r7 -_081637D0: - ldr r1, =gUnknown_03006298 - mov r2, r8 - lsls r0, r2, 1 - adds r0, r1 - ldrh r4, [r0] - ldr r5, [sp, 0x10] - add r5, r8 - movs r7, 0x64 - adds r6, r5, 0 - muls r6, r7 - ldr r1, =gEnemyParty - adds r0, r6, r1 - ldr r7, =gFacilityTrainerMons - ldr r2, [r7] - lsls r4, 4 - adds r2, r4, r2 - ldrh r1, [r2] - ldrb r3, [r2, 0xC] - movs r7, 0 - str r7, [sp] - ldrb r2, [r2, 0xB] - str r2, [sp, 0x4] - mov r2, r9 - str r2, [sp, 0x8] - movs r2, 0x1E - bl CreateMonWithEVSpreadPersonalityOTID - movs r1, 0 - add r0, sp, 0xC - strb r1, [r0] - mov r10, r5 - mov r0, r8 - adds r0, 0x1 - str r0, [sp, 0x14] - mov r8, r4 - mov r5, r8 -_08163818: - ldr r1, =gFacilityTrainerMons - ldr r0, [r1] - adds r0, r5, r0 - lsls r4, r7, 1 - adds r0, 0x2 - adds r0, r4 - ldrh r1, [r0] - ldr r2, =gEnemyParty - adds r0, r6, r2 - adds r2, r7, 0 - bl SetMonMoveAvoidReturn - ldr r1, =gFacilityTrainerMons - ldr r0, [r1] - adds r0, r5, r0 - adds r0, 0x2 - adds r0, r4 - ldrh r0, [r0] - cmp r0, 0xDA - bne _08163846 - movs r1, 0 - add r0, sp, 0xC - strb r1, [r0] -_08163846: - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 - cmp r7, 0x3 - bls _08163818 - movs r2, 0x64 - mov r4, r10 - muls r4, r2 - ldr r7, =gEnemyParty - adds r4, r7 - adds r0, r4, 0 - movs r1, 0x20 - add r2, sp, 0xC - bl SetMonData - ldr r1, =gFacilityTrainerMons - ldr r0, [r1] - add r0, r8 - ldrb r2, [r0, 0xA] - lsls r2, 1 - ldr r0, =gBattleFrontierHeldItems - adds r2, r0 - adds r0, r4, 0 - movs r1, 0xC - bl SetMonData - ldr r2, [sp, 0x14] - lsls r0, r2, 24 - lsrs r0, 24 - mov r8, r0 - cmp r0, 0x2 - bls _081637D0 - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_816379C - - thumb_func_start ConvertBattleFrontierTrainerSpeechToString -ConvertBattleFrontierTrainerSpeechToString: @ 81638AC - push {r4,r5,lr} - adds r5, r0, 0 - ldr r4, =gStringVar4 - adds r0, r4, 0 - adds r1, r5, 0 - movs r2, 0x3 - movs r3, 0x2 - bl ConvertEasyChatWordsToString - movs r2, 0x1 - negs r2, r2 - movs r0, 0x1 - adds r1, r4, 0 - bl GetStringWidth - cmp r0, 0xCC - bls _0816390A - adds r0, r4, 0 - adds r1, r5, 0 - movs r2, 0x2 - movs r3, 0x3 - bl ConvertEasyChatWordsToString - ldrb r0, [r4] - movs r1, 0x1 - cmp r0, 0xFE - beq _081638EE - adds r2, r4, 0 -_081638E4: - adds r0, r1, r2 - ldrb r0, [r0] - adds r1, 0x1 - cmp r0, 0xFE - bne _081638E4 -_081638EE: - ldr r2, =gStringVar4 - adds r0, r1, r2 - ldrb r0, [r0] - adds r3, r2, 0 - cmp r0, 0xFE - beq _08163904 -_081638FA: - adds r1, 0x1 - adds r0, r1, r2 - ldrb r0, [r0] - cmp r0, 0xFE - bne _081638FA -_08163904: - adds r1, r3 - movs r0, 0xFA - strb r0, [r1] -_0816390A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end ConvertBattleFrontierTrainerSpeechToString thumb_func_start sub_8163914 sub_8163914: @ 8163914 @@ -3118,7 +618,7 @@ sub_8163EE4: @ 8163EE4 ldrb r0, [r2, 0x8] cmp r0, 0 beq _08163F40 - ldr r4, =gUnknown_085DCEFA + ldr r4, =gTowerFemaleFacilityClasses ldrb r0, [r2, 0xA] ldrb r1, [r2, 0xB] adds r0, r1 @@ -3130,7 +630,7 @@ sub_8163EE4: @ 8163EE4 b _08163F52 .pool _08163F40: - ldr r4, =gUnknown_085DCEDC + ldr r4, =gTowerMaleFacilityClasses ldrb r0, [r2, 0xA] ldrb r1, [r2, 0xB] adds r0, r1 @@ -3650,7 +1150,7 @@ _0816438C: adds r0, r1 ldrh r0, [r0] mov r8, r0 - bl sub_81627A4 + bl GetBattleFacilityTrainerGfxId ldr r4, [sp, 0x40] strb r0, [r4, 0x19] movs r7, 0 @@ -3841,7 +1341,7 @@ _081644E0: adds r4, r5 strh r0, [r4] ldrh r0, [r4] - bl sub_81627A4 + bl GetBattleFacilityTrainerGfxId ldr r1, [sp, 0x24] adds r1, 0xA8 strb r0, [r1, 0x1] @@ -4003,7 +1503,7 @@ _08164660: adds r4, r5 strh r0, [r4] ldrh r0, [r4] - bl sub_81627A4 + bl GetBattleFacilityTrainerGfxId ldr r1, [sp, 0x24] adds r1, 0xC0 strb r0, [r1, 0x1] @@ -4223,7 +1723,7 @@ _08164884: cmp r1, 0x31 bhi _0816489A lsrs r0, r6, 16 - bl sub_8162D34 + bl GetFrontierTrainerFacilityClass lsls r0, 24 lsrs r0, 24 ldr r1, [r4] @@ -4739,10 +2239,10 @@ _08164D14: strh r0, [r4] ldrh r0, [r2] movs r1, 0 - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId ldrh r0, [r4] movs r1, 0x1 - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId ldr r0, =gReceivedRemoteLinkPlayers ldrb r0, [r0] cmp r0, 0 @@ -4805,7 +2305,7 @@ sub_8164DE4: @ 8164DE4 adds r0, r1 ldrh r0, [r0] movs r1, 0xF - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId pop {r0} bx r0 .pool @@ -5234,7 +2734,7 @@ sub_816515C: @ 816515C adds r5, r1, 0 cmp r0, 0 beq _08165194 - ldr r4, =gUnknown_085DCEFA + ldr r4, =gTowerFemaleFacilityClasses ldrb r0, [r2, 0xA] ldrb r1, [r2, 0xB] adds r0, r1 @@ -5246,7 +2746,7 @@ sub_816515C: @ 816515C b _081651A6 .pool _08165194: - ldr r4, =gUnknown_085DCEDC + ldr r4, =gTowerMaleFacilityClasses ldrb r0, [r2, 0xA] ldrb r1, [r2, 0xB] adds r0, r1 @@ -5716,7 +3216,7 @@ _0816556C: lsrs r0, 24 str r0, [sp, 0x50] adds r0, r7, 0 - bl sub_8165D08 + bl GetFrontierTrainerFixedIvs lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x4C] @@ -5866,7 +3366,7 @@ _0816567E: add r2, sp, 0x10 bl SetMonData adds r0, r7, 0 - bl sub_8162F68 + bl IsFrontierTrainerFemale lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x44] @@ -5981,7 +3481,7 @@ _0816579C: adds r0, r7, r2 lsls r0, 16 lsrs r0, 16 - bl sub_8162F68 + bl IsFrontierTrainerFemale lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x44] @@ -6037,7 +3537,7 @@ _08165812: adds r0, r7, r3 lsls r0, 16 lsrs r0, 16 - bl sub_8162F68 + bl IsFrontierTrainerFemale lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x44] @@ -6666,8 +4166,8 @@ _08165CF4: .pool thumb_func_end sub_8165CB4 - thumb_func_start sub_8165D08 -sub_8165D08: @ 8165D08 + thumb_func_start GetFrontierTrainerFixedIvs +GetFrontierTrainerFixedIvs: @ 8165D08 push {lr} lsls r0, 16 lsrs r0, 16 @@ -6697,7 +4197,7 @@ _08165D3A: adds r0, r1, 0 pop {r1} bx r1 - thumb_func_end sub_8165D08 + thumb_func_end GetFrontierTrainerFixedIvs thumb_func_start sub_8165D40 sub_8165D40: @ 8165D40 @@ -6831,7 +4331,7 @@ _08165E58: strh r4, [r5] ldrh r0, [r5] movs r1, 0 - bl sub_8162614 + bl SetBattleFacilityTrainerGfxId ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r2, =0x00000cb2 @@ -7121,7 +4621,7 @@ sub_81660B8: @ 81660B8 lsls r0, 24 lsrs r2, r0, 24 movs r1, 0 - ldr r3, =gUnknown_085DCEDC + ldr r3, =gTowerMaleFacilityClasses ldrb r0, [r3] cmp r0, r2 beq _081660DA @@ -7138,12 +4638,12 @@ _081660C8: _081660DA: cmp r1, 0x1E beq _081660EC - ldr r0, =gUnknown_085DCF0E + ldr r0, =gTowerMaleTrainerGfxIds b _08166116 .pool _081660EC: movs r1, 0 - ldr r3, =gUnknown_085DCEFA + ldr r3, =gTowerFemaleFacilityClasses ldrb r0, [r3] cmp r0, r2 beq _08166108 @@ -7164,7 +4664,7 @@ _08166108: b _0816611A .pool _08166114: - ldr r0, =gUnknown_085DCF2C + ldr r0, =gTowerFemaleTrainerGfxIds _08166116: adds r0, r1, r0 ldrb r0, [r0] diff --git a/data/battle_tower.s b/data/battle_tower.s index 2cc0aa639..ec5ee924e 100644 --- a/data/battle_tower.s +++ b/data/battle_tower.s @@ -21,16 +21,16 @@ @ 85D97BC .include "data/battle_frontier/battle_frontier_mons.inc" -gUnknown_085DCEDC:: @ 85DCEDC +gTowerMaleFacilityClasses:: @ 85DCEDC .byte 0x0e, 0x11, 0x03, 0x15, 0x17, 0x07, 0x0a, 0x19, 0x1a, 0x1b, 0x1d, 0x1e, 0x20, 0x26, 0x29, 0x09, 0x2b, 0x2d, 0x2e, 0x30, 0x32, 0x34, 0x04, 0x35, 0x3a, 0x05, 0x42, 0x44, 0x43, 0x00 -gUnknown_085DCEFA:: @ 85DCEFA +gTowerFemaleFacilityClasses:: @ 85DCEFA .byte 0x0d, 0x10, 0x12, 0x0c, 0x13, 0x14, 0x1f, 0x27, 0x2a, 0x16, 0x2f, 0x31, 0x33, 0x36, 0x37, 0x38, 0x1c, 0x02, 0x45, 0x47 -gUnknown_085DCF0E:: @ 85DCF0E +gTowerMaleTrainerGfxIds:: @ 85DCF0E .byte 0x37, 0x36, 0x21, 0x0f, 0x27, 0x33, 0x2c, 0x42, 0x42, 0x1f, 0x27, 0x25, 0x30, 0x26, 0x19, 0x15, 0x23, 0x32, 0x38, 0x33, 0x33, 0x21, 0x42, 0x05, 0x31, 0x27, 0x41, 0x1f, 0x24, 0x37 -gUnknown_085DCF2C:: @ 85DCF2C +gTowerFemaleTrainerGfxIds:: @ 85DCF2C .byte 0x14, 0x35, 0x22, 0x28, 0x14, 0x2d, 0x2f, 0x0e, 0x12, 0x16, 0x39, 0x34, 0x34, 0x0e, 0x22, 0x34, 0x20, 0x14, 0x20, 0x2f gUnknown_085DCF40:: @ 85DCF40 @@ -683,7 +683,7 @@ gUnknown_085DF96C:: @ 85DF96C .4byte sub_8161F94 .4byte sub_8162054 .4byte sub_81620F4 - .4byte sub_81623F0 + .4byte ChooseNextBattleTowerTrainer .4byte sub_81621C0 .4byte sub_816502C .4byte sub_8164040 diff --git a/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc b/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc index b29ef99a5..6eea58f9f 100644 --- a/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc +++ b/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc @@ -4,7 +4,7 @@ SootopolisCity_MysteryEventsHouse_B1F_MapScripts:: @ 8227E4F .byte 0 SootopolisCity_MysteryEventsHouse_B1F_MapScript1_227E5A: @ 8227E5A - special sub_8162794 + special SetEReaderTrainerGfxId end SootopolisCity_MysteryEventsHouse_B1F_MapScript2_227E5E: @ 8227E5E diff --git a/data/specials.inc b/data/specials.inc index cec36932a..3c5318309 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -332,7 +332,7 @@ gSpecials:: @ 81DBA64 def_special sp13F_fall_to_last_warp def_special sub_80F8D28 def_special sub_80F8EB8 - def_special sub_8162794 + def_special SetEReaderTrainerGfxId def_special BattleSetup_StartLatiBattle def_special SetRoute119Weather def_special SetRoute123Weather diff --git a/include/battle_frontier_2.h b/include/battle_frontier_2.h index 573053f10..3bd605829 100644 --- a/include/battle_frontier_2.h +++ b/include/battle_frontier_2.h @@ -14,5 +14,6 @@ bool8 InBattlePike(void); void sub_81AA078(u16*, u8); void sub_81A4C30(void); bool8 sub_81A6BF4(void); +u8 sub_81A6CA8(u8, u8); #endif // GUARD_BATTLE_FRONTIER_2_H diff --git a/include/battle_tower.h b/include/battle_tower.h index 6af87210b..f79fbb8c4 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -1,9 +1,9 @@ #ifndef GUARD_BATTLE_TOWER_H #define GUARD_BATTLE_TOWER_H -#define BATTLE_TOWER_EREADER_TRAINER_ID 200 #define BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID 300 #define BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID 400 +#define BATTLE_TOWER_EREADER_TRAINER_ID 500 struct RSBattleTowerRecord { @@ -12,9 +12,7 @@ struct RSBattleTowerRecord /*0x02*/ u16 winStreak; /*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1]; /*0x0C*/ u8 trainerId[4]; - /*0x10*/ struct { - u16 easyChat[6]; - } greeting; + /*0x10*/ u16 greeting[6]; /*0x1C*/ struct UnknownPokemonStruct party[3]; /*0xA0*/ u32 checksum; /*0xA4*/ u16 unk_11c8; @@ -26,16 +24,15 @@ union BattleTowerRecord struct EmeraldBattleTowerRecord emerald; }; -#define FRONTIER_TRAINER_NAME_LENGTH 7 - struct BattleFrontierTrainer { - u32 facilityClass; - u8 trainerName[FRONTIER_TRAINER_NAME_LENGTH + 1]; + u8 facilityClass; + u8 filler1[3]; + u8 trainerName[PLAYER_NAME_LENGTH + 1]; u16 speechBefore[6]; u16 speechWin[6]; u16 speechLose[6]; - const u16 *btMonPool; + const u16 *bfMonPool; }; struct FacilityMon @@ -47,6 +44,11 @@ struct FacilityMon u8 nature; }; +extern const u8 gTowerMaleFacilityClasses[30]; +extern const u8 gTowerMaleTrainerGfxIds[30]; +extern const u8 gTowerFemaleFacilityClasses[20]; +extern const u8 gTowerFemaleTrainerGfxIds[20]; + extern const struct BattleFrontierTrainer *gFacilityTrainers; extern const struct FacilityMon *gFacilityTrainerMons; @@ -54,8 +56,8 @@ u16 GetCurrentBattleTowerWinStreak(u8, u8); void sub_81659DC(struct RSBattleTowerRecord *a0, struct RSBattleTowerRecord *a1); bool32 sub_816587C(union BattleTowerRecord *, union BattleTowerRecord *); void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *); -void sub_81628A0(union BattleTowerRecord *); -void sub_8162614(u16 trainerId, u8); +void PutNewBattleTowerRecord(union BattleTowerRecord *); +void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId); void ConvertBattleFrontierTrainerSpeechToString(const u16 *words); void GetFrontierTrainerName(u8 *dest, u16 trainerIdx); void GetEreaderTrainerName(u8 *dest); diff --git a/include/global.h b/include/global.h index 35e34e722..ef5a944d0 100644 --- a/include/global.h +++ b/include/global.h @@ -326,19 +326,31 @@ struct UnknownPokemonStruct struct EmeraldBattleTowerRecord { /*0x00*/ u8 lvlMode; // 0 = level 50, 1 = level 100 - /*0x01*/ u8 trainerClass; + /*0x01*/ u8 facilityClass; /*0x02*/ u16 winStreak; /*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1]; /*0x0C*/ u8 trainerId[4]; - /*0x10*/ struct { - u16 easyChat[6]; - } greeting; + /*0x10*/ u16 greeting[6]; /*0x1C*/ u8 filler_1c[0x18]; /*0x34*/ struct UnknownPokemonStruct party[4]; /*0xE4*/ u8 language; /*0xE8*/ u32 checksum; }; +struct BattleTowerEReaderTrainer +{ + /*0x00*/ u8 unk0; + /*0x01*/ u8 facilityClass; + /*0x02*/ u16 winStreak; + /*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1]; + /*0x0C*/ u8 trainerId[4]; + /*0x10*/ u16 greeting[6]; + /*0x1C*/ u16 farewellPlayerLost[6]; + /*0x28*/ u16 farewellPlayerWon[6]; + /*0x34*/ struct UnknownPokemonStruct party[3]; + /*0xB8*/ u32 checksum; +}; + struct FrontierMonData { u16 moves[4]; @@ -367,17 +379,13 @@ struct BattleDomeTrainer struct BattleFrontier { /*0x64C*/ struct EmeraldBattleTowerRecord battleTower; - /*0x738*/ struct EmeraldBattleTowerRecord records[5]; // No idea here, it's probably wrong, no clue. + /*0x738*/ struct EmeraldBattleTowerRecord records[5]; // From record mixing. /*0xBD4*/ u16 field_BD4; /*0xBD6*/ u16 field_BD6; /*0xBD8*/ u8 field_BD8[11]; /*0xBE3*/ u8 field_BE3[8]; /*0xBEB*/ u8 field_BEB; - /*0xBEC*/ u8 filler_BEC[16]; - /*0xBFC*/ u16 ecwords_BFC[6]; - /*0xC08*/ u16 ecwords_C08[6]; - /*0xC14*/ u16 ecwords_C14[6]; - /*0xC20*/ u8 filler_C20[0x88]; + /*0xBEC*/ struct BattleTowerEReaderTrainer ereaderTrainer; /*0xCA8*/ u8 field_CA8; /*0xCA9*/ u8 lvlMode:2; // 0x1, 0x2 -> 0x3 /*0xCA9*/ u8 field_CA9_a:1; // 0x4 @@ -388,8 +396,8 @@ struct BattleFrontier /*0xCA9*/ u8 field_CA9_f:1; // 0x80 /*0xCAA*/ u16 field_CAA[3]; /*0xCB0*/ u16 field_CB0; - /*0xCB2*/ u16 field_CB2; - /*0xCB4*/ u16 field_CB4[20]; + /*0xCB2*/ u16 curChallengeBattleNum; // In case of battle pyramid, the floor. + /*0xCB4*/ u16 battledTrainerIds[20]; /*0xCDC*/ u32 field_CDC; /*0xCE0*/ u16 field_CE0[4][2]; /*0xCF0*/ u16 field_CF0[2]; diff --git a/src/apprentice.c b/src/apprentice.c index f2a8aa9c0..2a79652ff 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -346,11 +346,6 @@ extern void (*gUnknown_030062F4)(void); extern void sub_8165AE8(struct Apprentice *); -extern const u8 gUnknown_085DCEDC[]; -extern const u8 gUnknown_085DCF0E[]; -extern const u8 gUnknown_085DCEFA[]; -extern const u8 gUnknown_085DCF2C[]; - // This file's functions. static u16 sub_819FF98(u8 arg0); static bool8 sub_81A0194(u8 arg0, u16 moveId); @@ -382,7 +377,7 @@ static void sub_81A1218(void); static void sub_81A1224(void); static void sub_81A1438(void); static void sub_81A150C(void); -static void sub_81A15A4(void); +static void Script_SetPlayerApprenticeTrainerGfxId(void); static void sub_81A1644(void); static void sub_81A1370(void); @@ -1030,7 +1025,7 @@ static void (* const sApprenticeFunctions[])(void) = sub_81A1224, sub_81A1438, sub_81A150C, - sub_81A15A4, + Script_SetPlayerApprenticeTrainerGfxId, sub_81A1644, sub_81A1370, }; @@ -2270,51 +2265,46 @@ static void sub_81A150C(void) u8 mapObjectGfxId; u8 class = gApprentices[gSaveBlock2Ptr->apprentices[0].id].facilityClass; - for (i = 0; i < 30 && gUnknown_085DCEDC[i] != class; i++) + // Search male classes. + for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses) && gTowerMaleFacilityClasses[i] != class; i++) ; - - if (i != 30) + if (i != ARRAY_COUNT(gTowerMaleFacilityClasses)) { - mapObjectGfxId = gUnknown_085DCF0E[i]; + mapObjectGfxId = gTowerMaleTrainerGfxIds[i]; VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId); + return; } - else - { - for (i = 0; i < 20 && gUnknown_085DCEFA[i] != class; i++) - ; - if (i != 20) - { - mapObjectGfxId = gUnknown_085DCF2C[i]; - VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId); - } + for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses) && gTowerFemaleFacilityClasses[i] != class; i++) + ; + if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses)) + { + mapObjectGfxId = gTowerFemaleTrainerGfxIds[i]; + VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId); } } -static void sub_81A15A4(void) +static void Script_SetPlayerApprenticeTrainerGfxId(void) { u8 i; u8 mapObjectGfxId; u8 class = gApprentices[PLAYER_APPRENTICE.id].facilityClass; - for (i = 0; i < 30 && gUnknown_085DCEDC[i] != class; i++) + for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses) && gTowerMaleFacilityClasses[i] != class; i++) ; - - if (i != 30) + if (i != ARRAY_COUNT(gTowerMaleFacilityClasses)) { - mapObjectGfxId = gUnknown_085DCF0E[i]; + mapObjectGfxId = gTowerMaleTrainerGfxIds[i]; VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId); + return; } - else - { - for (i = 0; i < 20 && gUnknown_085DCEFA[i] != class; i++) - ; - if (i != 20) - { - mapObjectGfxId = gUnknown_085DCF2C[i]; - VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId); - } + for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses) && gTowerFemaleFacilityClasses[i] != class; i++) + ; + if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses)) + { + mapObjectGfxId = gTowerFemaleTrainerGfxIds[i]; + VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId); } } diff --git a/src/battle_dome.c b/src/battle_dome.c index 8de1c058c..6401530d7 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -62,7 +62,7 @@ extern u8 GetFacilityEnemyMonLevel(void); extern u16 sub_81A5060(u8 monId, u8 moveSlotId); extern u8 sub_81A50F0(u8, u8); extern u8 sub_81A50B0(u8); -extern void sub_8162614(u16, u8); +extern void SetBattleFacilityTrainerGfxId(u16, u8); extern void sub_81A4C30(void); extern bool8 sub_81A3610(void); extern u16 sub_81A4FF0(u8); @@ -2424,7 +2424,7 @@ static void sub_818E9CC(void) u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); gSaveBlock2Ptr->frontier.field_CA8 = 0; - gSaveBlock2Ptr->frontier.field_CB2 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = 0; gSaveBlock2Ptr->frontier.field_CA9_b = 0; if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_0860D0EC[battleMode][lvlMode])) @@ -2824,12 +2824,12 @@ static void SwapDomeTrainers(s32 id1, s32 id2, u16 *statsArray) static void sub_818F9B0(void) { - StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.field_CB2]); + StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.curChallengeBattleNum]); } static void sub_818F9E0(void) { - StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.field_CB2]); + StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.curChallengeBattleNum]); CopyDomeTrainerName(gStringVar2, gTrainerBattleOpponent_A); } @@ -3480,12 +3480,12 @@ static void sub_8190298(void) static u16 TrainerIdOfPlayerOpponent(void) { - return gSaveBlock2Ptr->frontier.domeTrainers[TournamentIdOfOpponent(gSaveBlock2Ptr->frontier.field_CB2, TRAINER_PLAYER)].trainerId; + return gSaveBlock2Ptr->frontier.domeTrainers[TournamentIdOfOpponent(gSaveBlock2Ptr->frontier.curChallengeBattleNum, TRAINER_PLAYER)].trainerId; } static void sub_81902E4(void) { - sub_8162614(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); } static void sub_81902F8(void) @@ -3819,7 +3819,7 @@ static void sub_8190B40(struct Sprite *sprite) s32 taskId1 = sprite->data[0]; s32 arrId = gTasks[gTasks[taskId1].data[4]].data[1]; s32 tournmanetTrainerId = gUnknown_0860D080[arrId]; - s32 r12 = gSaveBlock2Ptr->frontier.field_CB2; + s32 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; if (gTasks[taskId1].data[3] == 1) { @@ -3831,7 +3831,7 @@ static void sub_8190B40(struct Sprite *sprite) sprite->invisible = FALSE; } else if (!gSaveBlock2Ptr->frontier.domeTrainers[tournmanetTrainerId].isEliminated - && sBattleDomeStruct->unk_10 - 1 < r12) + && sBattleDomeStruct->unk_10 - 1 < roundId) { sprite->invisible = FALSE; } @@ -4635,7 +4635,7 @@ static u8 sub_819221C(u8 taskId) s32 taskId2 = gTasks[taskId].data[4]; s32 r5 = gTasks[taskId2].data[1]; u8 r10 = gUnknown_0860D080[r5]; - u16 roundId = gSaveBlock2Ptr->frontier.field_CB2; + u16 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; if (gMain.newKeys & (A_BUTTON | B_BUTTON)) retVal = 9; @@ -5387,7 +5387,7 @@ static void sub_81938E0(void) sub_8194D48(); gSaveBlock2Ptr->frontier.lvlMode = gSaveBlock2Ptr->frontier.field_D0A - 1; - gSaveBlock2Ptr->frontier.field_CB2 = 3; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 3; taskId = CreateTask(sub_8194220, 0); gTasks[taskId].data[0] = 0; gTasks[taskId].data[1] = 0; @@ -5489,7 +5489,7 @@ static u8 sub_8193BDC(u8 taskId) u8 retVal = 1; s32 arrId = 4; s32 spriteId = gTasks[taskId].data[1]; - s32 roundId = gSaveBlock2Ptr->frontier.field_CB2; + s32 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; if (gMain.newKeys == B_BUTTON || (gMain.newKeys & A_BUTTON && spriteId == 31)) { @@ -5550,19 +5550,19 @@ static void sub_8193D7C(void) if (gSpecialVar_0x8005 == 1) { gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].isEliminated = 1; - gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].eliminatedAt = gSaveBlock2Ptr->frontier.field_CB2; + gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].eliminatedAt = gSaveBlock2Ptr->frontier.curChallengeBattleNum; gSaveBlock2Ptr->frontier.field_EC0[TrainerIdToTournamentId(gTrainerBattleOpponent_A)] = gBattleResults.lastUsedMovePlayer; - if (gSaveBlock2Ptr->frontier.field_CB2 < DOME_FINAL) - DecideRoundWinners(gSaveBlock2Ptr->frontier.field_CB2); + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < DOME_FINAL) + DecideRoundWinners(gSaveBlock2Ptr->frontier.curChallengeBattleNum); } else { gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].isEliminated = 1; - gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].eliminatedAt = gSaveBlock2Ptr->frontier.field_CB2; + gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].eliminatedAt = gSaveBlock2Ptr->frontier.curChallengeBattleNum; gSaveBlock2Ptr->frontier.field_EC0[TrainerIdToTournamentId(TRAINER_PLAYER)] = gBattleResults.lastUsedMoveOpponent; if (gBattleOutcome == B_OUTCOME_FORFEITED || gSpecialVar_0x8005 == 9) gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].unk3 = 1; - for (i = gSaveBlock2Ptr->frontier.field_CB2; i < DOME_ROUNDS_COUNT; i++) + for (i = gSaveBlock2Ptr->frontier.curChallengeBattleNum; i < DOME_ROUNDS_COUNT; i++) DecideRoundWinners(i); } } @@ -5775,7 +5775,7 @@ static void sub_8194220(u8 taskId) AddTextPrinter(&textPrinter, 0, NULL); for (i = 0; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++) { - s32 var, var2; + s32 roundId, var2; CopyDomeTrainerName(gDisplayedStringBattle, gSaveBlock2Ptr->frontier.domeTrainers[i].trainerId); if (r10 == 1) @@ -5788,9 +5788,9 @@ static void sub_8194220(u8 taskId) sub_81948EC(i, var2); } } - else if (gSaveBlock2Ptr->frontier.field_CB2 != DOME_ROUND2) + else if (gSaveBlock2Ptr->frontier.curChallengeBattleNum != DOME_ROUND2) { - sub_81948EC(i, gSaveBlock2Ptr->frontier.field_CB2 - 2); + sub_81948EC(i, gSaveBlock2Ptr->frontier.curChallengeBattleNum - 2); } } else if (r10 == 0) @@ -5803,23 +5803,23 @@ static void sub_8194220(u8 taskId) sub_81948EC(i, var2); } } - else if (gSaveBlock2Ptr->frontier.field_CB2 != DOME_ROUND1) + else if (gSaveBlock2Ptr->frontier.curChallengeBattleNum != DOME_ROUND1) { if (gTasks[taskId].data[4]) - var2 = gSaveBlock2Ptr->frontier.field_CB2; + var2 = gSaveBlock2Ptr->frontier.curChallengeBattleNum; else - var2 = gSaveBlock2Ptr->frontier.field_CB2 - 1; + var2 = gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1; sub_81948EC(i, var2); } } if (gTasks[taskId].data[4]) - var = gSaveBlock2Ptr->frontier.field_CB2; + roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; else - var = gSaveBlock2Ptr->frontier.field_CB2 - 1; + roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1; - if ( ((r10 == 1 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt < gSaveBlock2Ptr->frontier.field_CB2 - 1) - || (r10 == 0 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt <= var)) + if ( ((r10 == 1 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt < gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1) + || (r10 == 0 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt <= roundId)) && gSaveBlock2Ptr->frontier.domeTrainers[i].isEliminated) { if (gSaveBlock2Ptr->frontier.domeTrainers[i].trainerId == TRAINER_PLAYER) @@ -5944,7 +5944,7 @@ static void sub_8194950(u8 taskId) for (i = 0; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++) { CopyDomeTrainerName(gDisplayedStringBattle, gSaveBlock2Ptr->frontier.domeTrainers[i].trainerId); - if (gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt == gSaveBlock2Ptr->frontier.field_CB2 - 1 + if (gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt == gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1 && gSaveBlock2Ptr->frontier.domeTrainers[i].isEliminated) { if (gUnknown_0860D3F1[i][0] == 0) @@ -5959,8 +5959,8 @@ static void sub_8194950(u8 taskId) } if (!gSaveBlock2Ptr->frontier.domeTrainers[i].isEliminated) { - s32 var = gSaveBlock2Ptr->frontier.field_CB2 - 1; - sub_81948EC(i, var); + s32 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1; + sub_81948EC(i, roundId); } } } @@ -6454,7 +6454,7 @@ static void CopyDomeTrainerName(u8 *dst, u16 trainerId) } else if (trainerId < 300) { - for (i = 0; i < FRONTIER_TRAINER_NAME_LENGTH; i++) + for (i = 0; i < PLAYER_NAME_LENGTH; i++) dst[i] = gFacilityTrainers[trainerId].trainerName[i]; } dst[i] = EOS; @@ -6475,7 +6475,7 @@ static void CopyDomeBrainTrainerName(u8 *dst) { s32 i; - for (i = 0; i < FRONTIER_TRAINER_NAME_LENGTH; i++) + for (i = 0; i < PLAYER_NAME_LENGTH; i++) dst[i] = gTrainers[TRAINER_TUCKER].trainerName[i]; dst[i] = EOS; } diff --git a/src/battle_frontier_1.c b/src/battle_frontier_1.c index ee8a42954..7c93f4cdc 100644 --- a/src/battle_frontier_1.c +++ b/src/battle_frontier_1.c @@ -5,7 +5,7 @@ #include "random.h" #include "battle_tower.h" -extern void sub_8162614(u16, u8); +extern void SetBattleFacilityTrainerGfxId(u16, u8); extern void (* const gUnknown_0860DE50[])(void); extern const u32 gUnknown_0860DE98[][2]; @@ -23,7 +23,7 @@ void sub_8195980(void) u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); gSaveBlock2Ptr->frontier.field_CA8 = 0; - gSaveBlock2Ptr->frontier.field_CB2 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = 0; gSaveBlock2Ptr->frontier.field_CA9_b = 0; if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_0860DE98[battleMode][lvlMode])) @@ -90,7 +90,7 @@ void sub_8195BB0(void) void sub_8195C20(void) { gTrainerBattleOpponent_A = 5 *(Random() % 255) / 64u; - sub_8162614(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); } void sub_8195C50(void) diff --git a/src/battle_setup.c b/src/battle_setup.c index db173a38e..b5ae0d6ea 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -885,8 +885,8 @@ u8 sub_80B100C(s32 arg0) return sUnknown_0854FE98[Random() % ARRAY_COUNT(sUnknown_0854FE98)]; } - var = gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.field_CB2 * 2 + 0] - + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.field_CB2 * 2 + 1]; + var = gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 0] + + gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 1]; return sUnknown_0854FE98[var % ARRAY_COUNT(sUnknown_0854FE98)]; } diff --git a/src/battle_tent.c b/src/battle_tent.c index e30cac386..4edb0b619 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -102,7 +102,7 @@ void sub_81B99B4(void) static void sub_81B99D4(void) { gSaveBlock2Ptr->frontier.field_CA8 = 0; - gSaveBlock2Ptr->frontier.field_CB2 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } @@ -120,7 +120,7 @@ static void sub_81B9A44(void) static void sub_81B9A60(void) { gTrainerBattleOpponent_A = (u32)((Random() % 255) * 5) / 64; - sub_8162614(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); } static void sub_81B9A90(void) @@ -164,7 +164,7 @@ void sub_81B9B80(void) static void sub_81B9BA0(void) { gSaveBlock2Ptr->frontier.field_CA8 = 0; - gSaveBlock2Ptr->frontier.field_CB2 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } @@ -219,7 +219,7 @@ void sub_81B9D08(void) static void sub_81B9D28(void) { gSaveBlock2Ptr->frontier.field_CA8 = 0; - gSaveBlock2Ptr->frontier.field_CB2 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } @@ -551,25 +551,25 @@ static void sub_81BA040(void) do { trainerId = Random() % 30; - for (i = 0; i < gSaveBlock2Ptr->frontier.field_CB2; i++) + for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) { - if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + if (gSaveBlock2Ptr->frontier.battledTrainerIds[i] == trainerId) break; } - } while (i != gSaveBlock2Ptr->frontier.field_CB2); + } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); gTrainerBattleOpponent_A = trainerId; - while (gFacilityTrainers[gTrainerBattleOpponent_A].btMonPool[monPoolCount] != 0xFFFF) + while (gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool[monPoolCount] != 0xFFFF) monPoolCount++; if (monPoolCount > 8) break; monPoolCount = 0; } - if (gSaveBlock2Ptr->frontier.field_CB2 < 2) - gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.field_CB2] = gTrainerBattleOpponent_A; + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 2) + gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; - monSetsPool = gFacilityTrainers[gTrainerBattleOpponent_A].btMonPool; + monSetsPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool; i = 0; while (i != 3) { diff --git a/src/battle_tower.c b/src/battle_tower.c index a6983897f..b9451aecd 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1,27 +1,55 @@ #include "global.h" +#include "battle_tower.h" +#include "apprentice.h" #include "event_data.h" #include "battle_setup.h" #include "overworld.h" #include "random.h" -#include "battle_tower.h" +#include "text.h" +#include "international_string_util.h" +#include "battle.h" #include "battle_frontier_1.h" +#include "battle_frontier_2.h" +#include "recorded_battle.h" +#include "easy_chat.h" #include "constants/battle_frontier.h" +#include "constants/trainers.h" +#include "constants/event_objects.h" +#include "constants/moves.h" extern void sub_81A3ACC(void); +extern void CreateFrontierBrainPokemon(void); +extern void sub_81A6CD0(void); extern u8 GetFrontierEnemyMonLevel(u8); +extern u8 GetFacilityEnemyMonLevel(void); +extern u16 sub_81A39C4(void); +extern void SetFrontierBrainTrainerGfxId(void); +extern u8 GetFrontierBrainTrainerPicIndex(void); +extern u8 GetFrontierBrainTrainerClass(void); +extern u8 IsFrontierBrainFemale(void); +extern void CopyFrontierBrainTrainerName(u8 *dst); +extern void SetMonMoveAvoidReturn(struct Pokemon *mon, u16 move, u8 moveSlot); extern const u32 gUnknown_085DF9AC[][2]; extern const u32 gUnknown_085DF9CC[][2]; extern void (* const gUnknown_085DF96C[])(void); extern const u8 gUnknown_085DF9F6[]; extern const u8 gUnknown_085DF9EC[]; +extern const u16 gBattleFrontierHeldItems[]; // This file's functions. void sub_8164ED8(void); void sub_8163E90(void); void sub_8165B20(void); +void sub_8165E18(void); u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode); void sub_816534C(void *); +u16 sub_8162548(u8, u8); +void sub_81630C4(u16 trainerId, u8 firstMonId, u8 monCount); +void sub_8165EA4(u16 trainerId, u8 firstMonId, u8 monCount); +void sub_81635D4(u16 trainerId, u8 firstMonId); +void sub_816379C(u16 trainerId, u8 firstMonId); +u8 GetFrontierTrainerFixedIvs(u16 trainerId); // code void sub_8161F74(void) @@ -35,7 +63,7 @@ void sub_8161F94(void) u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); gSaveBlock2Ptr->frontier.field_CA8 = 1; - gSaveBlock2Ptr->frontier.field_CB2 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = 0; gSaveBlock2Ptr->frontier.field_CA9_b = 0; sub_81A3ACC(); @@ -94,15 +122,15 @@ void sub_81620F4(void) void sub_81621C0(void) { - if (gTrainerBattleOpponent_A == 500) - sub_816534C(&gSaveBlock2Ptr->frontier.filler_BEC); + if (gTrainerBattleOpponent_A == BATTLE_TOWER_EREADER_TRAINER_ID) + sub_816534C(&gSaveBlock2Ptr->frontier.ereaderTrainer); if (gSaveBlock2Ptr->frontier.field_D04 < 9999) gSaveBlock2Ptr->frontier.field_D04++; - gSaveBlock2Ptr->frontier.field_CB2++; + gSaveBlock2Ptr->frontier.curChallengeBattleNum++; sub_8163E90(); - gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CB2; + gSpecialVar_Result = gSaveBlock2Ptr->frontier.curChallengeBattleNum; } bool8 ChooseSpecialBattleTowerTrainer(void) @@ -172,3 +200,940 @@ bool8 ChooseSpecialBattleTowerTrainer(void) return FALSE; } } + +void ChooseNextBattleTowerTrainer(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + if (lvlMode == FRONTIER_LVL_TENT) + { + sub_8165E18(); + } + else + { + u16 id; + u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + u32 r5 = sub_81A39C4() / 7; + GetFacilityEnemyMonLevel(); // Pointless function call. + + if (battleMode == FRONTIER_MODE_MULTIS || battleMode == FRONTIER_MODE_LINK_MULTIS) + { + id = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.battledTrainerIds[id * 2]; + gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.battledTrainerIds[id * 2 + 1]; + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); + } + else if (ChooseSpecialBattleTowerTrainer()) + { + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + } + else + { + s32 i; + while (1) + { + id = sub_8162548(r5, gSaveBlock2Ptr->frontier.curChallengeBattleNum); + + // Ensure trainer wasn't previously fought in this challenge. + for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) + { + if (gSaveBlock2Ptr->frontier.battledTrainerIds[i] == id) + break; + } + if (i == gSaveBlock2Ptr->frontier.curChallengeBattleNum) + break; + } + + gTrainerBattleOpponent_A = id; + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 7) + gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + } + } +} + +extern const u16 gUnknown_085DFA1A[][2]; +extern const u16 gUnknown_085DF9FA[][2]; + +u16 sub_8162548(u8 challengeNum, u8 battleNum) +{ + u16 trainerId; + + if (challengeNum <= 7) + { + if (battleNum == 6) + { + trainerId = (gUnknown_085DFA1A[challengeNum][1] - gUnknown_085DFA1A[challengeNum][0]) + 1; + trainerId = gUnknown_085DFA1A[challengeNum][0] + (Random() % trainerId); + } + else + { + trainerId = (gUnknown_085DF9FA[challengeNum][1] - gUnknown_085DF9FA[challengeNum][0]) + 1; + trainerId = gUnknown_085DF9FA[challengeNum][0] + (Random() % trainerId); + } + } + else + { + trainerId = (gUnknown_085DF9FA[7][1] - gUnknown_085DF9FA[7][0]) + 1; + trainerId = gUnknown_085DF9FA[7][0] + (Random() % trainerId); + } + + return trainerId; +} + +#ifdef NONMATCHING +u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) // Unused +{ + register u16 trainerId, count; + + if (challengeNum <= 7) + { + if (battleNum == 6) + { + count = (gUnknown_085DFA1A[challengeNum][1] - gUnknown_085DFA1A[challengeNum][0]) + 1; + trainerId = gUnknown_085DFA1A[challengeNum][0]; + } + else + { + count = (gUnknown_085DF9FA[challengeNum][1] - gUnknown_085DF9FA[challengeNum][0]) + 1; + trainerId = gUnknown_085DF9FA[challengeNum][0]; + } + } + else + { + count = (gUnknown_085DF9FA[7][1] - gUnknown_085DF9FA[7][0]) + 1; + trainerId = gUnknown_085DF9FA[7][0]; + } + + *trainerIdPtr = trainerId; + *arg3 = count; +} +#else +NAKED +u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) +{ + asm_unified(" push {r4,lr}\n\ + adds r4, r2, 0\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + adds r2, r0, 0\n\ + lsls r1, 24\n\ + lsrs r1, 24\n\ + cmp r0, 0x7\n\ + bhi _081625F4\n\ + cmp r1, 0x6\n\ + bne _081625D4\n\ + ldr r1, =gUnknown_085DFA1A\n\ + lsls r2, r0, 2\n\ + b _081625D8\n\ + .pool\n\ +_081625D4:\n\ + ldr r1, =gUnknown_085DF9FA\n\ + lsls r2, 2\n\ +_081625D8:\n\ + adds r0, r1, 0x2\n\ + adds r0, r2, r0\n\ + adds r2, r1\n\ + ldrh r0, [r0]\n\ + ldrh r1, [r2]\n\ + subs r0, r1\n\ + adds r0, 0x1\n\ + lsls r0, 16\n\ + lsrs r1, r0, 16\n\ + ldrh r0, [r2]\n\ + b _08162604\n\ + .pool\n\ +_081625F4:\n\ + ldr r0, =gUnknown_085DF9FA\n\ + ldrh r1, [r0, 0x1E]\n\ + ldrh r2, [r0, 0x1C]\n\ + subs r1, r2\n\ + adds r1, 0x1\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + ldrh r0, [r0, 0x1C]\n\ +_08162604:\n\ + strh r0, [r4]\n\ + strb r1, [r3]\n\ + pop {r4}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif + +void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId) +{ + u32 i; + u8 facilityClass; + u8 trainerObjectGfxId; + + GetFacilityEnemyMonLevel(); // Pointless function call. + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + SetFrontierBrainTrainerGfxId(); + return; + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + facilityClass = gFacilityTrainers[trainerId].facilityClass; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + } + else + { + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + } + + // Search male classes. + for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses); i++) + { + if (gTowerMaleFacilityClasses[i] == facilityClass) + break; + } + if (i != ARRAY_COUNT(gTowerMaleFacilityClasses)) + { + trainerObjectGfxId = gTowerMaleTrainerGfxIds[i]; + switch (tempVarId) + { + case 0: + default: + VarSet(VAR_OBJ_GFX_ID_0, trainerObjectGfxId); + return; + case 1: + VarSet(VAR_OBJ_GFX_ID_1, trainerObjectGfxId); + return; + case 15: + VarSet(VAR_OBJ_GFX_ID_E, trainerObjectGfxId); + return; + } + } + + // Search female classes. + for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++) + { + if (gTowerFemaleFacilityClasses[i] == facilityClass) + break; + } + if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses)) + { + trainerObjectGfxId = gTowerFemaleTrainerGfxIds[i]; + switch (tempVarId) + { + case 0: + default: + VarSet(VAR_OBJ_GFX_ID_0, trainerObjectGfxId); + return; + case 1: + VarSet(VAR_OBJ_GFX_ID_1, trainerObjectGfxId); + return; + case 15: + VarSet(VAR_OBJ_GFX_ID_E, trainerObjectGfxId); + return; + } + } + + switch (tempVarId) + { + case 0: + default: + VarSet(VAR_OBJ_GFX_ID_0, EVENT_OBJ_GFX_BOY_1); + return; + case 1: + VarSet(VAR_OBJ_GFX_ID_1, EVENT_OBJ_GFX_BOY_1); + return; + case 15: + VarSet(VAR_OBJ_GFX_ID_E, EVENT_OBJ_GFX_BOY_1); + return; + } +} + +void SetEReaderTrainerGfxId(void) +{ + SetBattleFacilityTrainerGfxId(BATTLE_TOWER_EREADER_TRAINER_ID, 0); +} + +u8 GetBattleFacilityTrainerGfxId(u16 trainerId) +{ + u32 i; + u8 facilityClass; + u8 trainerObjectGfxId; + + GetFacilityEnemyMonLevel(); // Pointless function call. + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + facilityClass = gFacilityTrainers[trainerId].facilityClass; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + } + else + { + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + } + + // Search male classes. + for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses); i++) + { + if (gTowerMaleFacilityClasses[i] == facilityClass) + break; + } + if (i != ARRAY_COUNT(gTowerMaleFacilityClasses)) + { + trainerObjectGfxId = gTowerMaleTrainerGfxIds[i]; + return trainerObjectGfxId; + } + + // Search female classes. + for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++) + { + if (gTowerFemaleFacilityClasses[i] == facilityClass) + break; + } + if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses)) + { + trainerObjectGfxId = gTowerFemaleTrainerGfxIds[i]; + return trainerObjectGfxId; + } + else + { + return EVENT_OBJ_GFX_BOY_1; + } +} + +void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) +{ + u16 slotValues[6]; + u16 slotIds[6]; + s32 i, j, k; + s32 slotsCount = 0; + struct EmeraldBattleTowerRecord *newRecordEm = &newRecord->emerald; + + // Find a record slot of the same player and replace it. + for (i = 0; i < 5; i++) + { + k = 0; + for (j = 0; j < 4; j++) + { + if (gSaveBlock2Ptr->frontier.records[i].trainerId[j] != newRecordEm->trainerId[j]) + break; + } + if (j == 4) + { + for (k = 0; k < PLAYER_NAME_LENGTH; k++) + { + // BUG: Wrong variable used, 'j' instead of 'k'. + if (gSaveBlock2Ptr->frontier.records[i].name[j] != newRecordEm->name[j]) + break; + if (newRecordEm->name[j] == EOS) + { + k = PLAYER_NAME_LENGTH; + break; + } + } + } + + if (k == PLAYER_NAME_LENGTH) + break; + } + if (i < 5) + { + gSaveBlock2Ptr->frontier.records[i] = *newRecordEm; + return; + } + + // Find an empty record slot. + for (i = 0; i < 5; i++) + { + if (gSaveBlock2Ptr->frontier.records[i].winStreak == 0) + break; + } + if (i < 5) + { + gSaveBlock2Ptr->frontier.records[i] = *newRecordEm; + return; + } + + // Find possible slots to replace the record. + slotValues[0] = gSaveBlock2Ptr->frontier.records[0].winStreak; + slotIds[0] = 0; + slotsCount++; + + for (i = 1; i < 5; i++) + { + for (j = 0; j < slotsCount; j++) + { + if (gSaveBlock2Ptr->frontier.records[i].winStreak < slotValues[j]) + { + j = 0; + slotsCount = 1; + slotValues[0] = gSaveBlock2Ptr->frontier.records[i].winStreak; + slotIds[0] = i; + break; + } + else if (gSaveBlock2Ptr->frontier.records[i].winStreak > slotValues[j]) + { + break; + } + } + + if (j == slotsCount) + { + slotValues[slotsCount] = gSaveBlock2Ptr->frontier.records[i].winStreak; + slotIds[slotsCount] = i; + slotsCount++; + } + } + + i = Random() % slotsCount; + gSaveBlock2Ptr->frontier.records[slotIds[i]] = *newRecordEm; +} + +u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) +{ + GetFacilityEnemyMonLevel(); // Pointless function call + + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass]; + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + return GetFrontierBrainTrainerPicIndex(); + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + return gFacilityClassToPicIndex[gFacilityTrainers[trainerId].facilityClass]; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + return gFacilityClassToPicIndex[sub_818649C()]; + else + return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; + } + else + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + return gFacilityClassToPicIndex[gApprentices[sub_81864A8()].facilityClass]; + else + return gFacilityClassToPicIndex[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass]; + } +} + +u8 GetFrontierOpponentClass(u16 trainerId) +{ + u8 trainerClass = 0; + GetFacilityEnemyMonLevel(); // Pointless function call. + + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass]; + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + trainerClass = GetFrontierBrainTrainerClass(); + } + else if (trainerId == TRAINER_STEVEN_PARTNER) + { + trainerClass = gTrainers[TRAINER_STEVEN].trainerClass; + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + trainerClass = gFacilityClassToTrainerClass[gFacilityTrainers[trainerId].facilityClass]; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + { + trainerClass = gFacilityClassToTrainerClass[sub_818649C()]; + } + else + { + trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; + asm(""); + } + } + else + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + { + trainerClass = gFacilityClassToTrainerClass[gApprentices[sub_81864A8()].facilityClass]; + } + else + { + trainerClass = gFacilityClassToTrainerClass[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass]; + asm(""); + } + } + + return trainerClass; +} + +u8 GetFrontierTrainerFacilityClass(u16 trainerId) +{ + u8 facilityClass; + GetFacilityEnemyMonLevel(); // Pointless function call. + + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + facilityClass = gFacilityTrainers[trainerId].facilityClass; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + facilityClass = sub_818649C(); + else + facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + } + else + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + facilityClass = gApprentices[sub_81864A8()].facilityClass; + else + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + } + + return facilityClass; +} + +void GetFrontierTrainerName(u8 *dst, u16 trainerId) +{ + s32 i = 0; + GetFacilityEnemyMonLevel(); // Pointless function call. + + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + for (i = 0; i < PLAYER_NAME_LENGTH; i++) + dst[i] = gSaveBlock2Ptr->frontier.ereaderTrainer.name[i]; + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + CopyFrontierBrainTrainerName(dst); + return; + } + else if (trainerId == TRAINER_STEVEN_PARTNER) + { + for (i = 0; i < PLAYER_NAME_LENGTH; i++) + dst[i] = gTrainers[TRAINER_STEVEN].trainerName[i]; + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + for (i = 0; i < PLAYER_NAME_LENGTH; i++) + dst[i] = gFacilityTrainers[trainerId].trainerName[i]; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + { + sub_8186468(dst); + return; + } + else + { + struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID]; + TVShowConvertInternationalString(dst, record->name, record->language); + return; + } + } + else + { + u8 id, language; + + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + { + id = sub_81864A8(); + language = sub_81864C0(); + } + else + { + struct Apprentice *apprentice = &gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID]; + id = apprentice->id; + language = apprentice->language; + } + TVShowConvertInternationalString(dst, GetApprenticeNameInLanguage(id, language), language); + return; + } + + dst[i] = EOS; +} + +bool8 IsFrontierTrainerFemale(u16 trainerId) +{ + u32 i; + u8 facilityClass; + + GetFacilityEnemyMonLevel(); // Pointless function call. + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + return IsFrontierBrainFemale(); + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + facilityClass = gFacilityTrainers[trainerId].facilityClass; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + } + else + { + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + } + + // Search female classes. + for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++) + { + if (gTowerFemaleFacilityClasses[i] == facilityClass) + break; + } + if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses)) + return TRUE; + else + return FALSE; +} + +void sub_8163048(u8 monsCount) +{ + ZeroEnemyPartyMons(); + sub_81630C4(gTrainerBattleOpponent_A, 0, monsCount); +} + +void sub_816306C(u8 monsCount) +{ + ZeroEnemyPartyMons(); + sub_81630C4(gTrainerBattleOpponent_A, 0, monsCount); + sub_81630C4(gTrainerBattleOpponent_B, 3, monsCount); +} + +void sub_81630A0(u8 monsCount) +{ + ZeroEnemyPartyMons(); + sub_8165EA4(gTrainerBattleOpponent_A, 0, monsCount); +} + +void sub_81630C4(u16 trainerId, u8 firstMonId, u8 monCount) +{ + s32 i, j; + u16 chosenMonIndices[4]; + u8 friendship = 0xFF; + u8 level = GetFacilityEnemyMonLevel(); + u8 fixedIV = 0; + u8 bfMonCount; + const u16 *bfMonPool = NULL; + u32 otID = 0; + + if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + // Normal battle frontier trainer. + fixedIV = GetFrontierTrainerFixedIvs(trainerId); + bfMonPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool; + } + else if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + for (i = firstMonId; i < firstMonId + 3; i++) + sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]); + return; + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + CreateFrontierBrainPokemon(); + return; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + // Record mixed player. + for (j = 0, i = firstMonId; i < firstMonId + monCount; j++, i++) + { + if (gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].species != 0 + && gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].level <= level) + { + sub_8068338(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j], FALSE); + } + } + return; + } + else + { + // Apprentice. + for (i = firstMonId; i < firstMonId + 3; i++) + CreateApprenticeMon(&gEnemyParty[i], &gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID], i - firstMonId); + return; + } + + // Regular battle frontier trainer. + // Attempt to fill the trainer's party with random Pokemon until 3 have been + // successfully chosen. The trainer's party may not have duplicate pokemon species + // or duplicate held items. + for (bfMonCount = 0; bfMonPool[bfMonCount] != 0xFFFF; bfMonCount++) + ; + i = 0; + otID = Random32(); + while (i != monCount) + { + u16 monPoolId = bfMonPool[Random() % bfMonCount]; + if ((level == 50 || level == 20) && monPoolId > 849) + continue; + + // Ensure this pokemon species isn't a duplicate. + for (j = 0; j < i + firstMonId; j++) + { + if (GetMonData(&gEnemyParty[j], MON_DATA_SPECIES, NULL) == gFacilityTrainerMons[monPoolId].species) + break; + } + if (j != i + firstMonId) + continue; + + // Ensure this Pokemon's held item isn't a duplicate. + for (j = 0; j < i + firstMonId; j++) + { + if (GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) != 0 + && GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) == gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]) + break; + } + if (j != i + firstMonId) + continue; + + // Ensure this exact pokemon index isn't a duplicate. This check doesn't seem necessary + // because the species and held items were already checked directly above. + for (j = 0; j < i; j++) + { + if (chosenMonIndices[j] == monPoolId) + break; + } + if (j != i) + continue; + + chosenMonIndices[i] = monPoolId; + + // Place the chosen pokemon into the trainer's party. + CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[i + firstMonId], + gFacilityTrainerMons[monPoolId].species, + level, + gFacilityTrainerMons[monPoolId].nature, + fixedIV, + gFacilityTrainerMons[monPoolId].evSpread, + otID); + + friendship = 255; + // Give the chosen pokemon its specified moves. + for (j = 0; j < 4; j++) + { + SetMonMoveSlot(&gEnemyParty[i + firstMonId], gFacilityTrainerMons[monPoolId].moves[j], j); + if (gFacilityTrainerMons[monPoolId].moves[j] == MOVE_FRUSTRATION) + friendship = 0; // Frustration is more powerful the lower the pokemon's friendship is. + } + + SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_FRIENDSHIP, &friendship); + SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]); + + // The pokemon was successfully added to the trainer's party, so it's safe to move on to + // the next party slot. + i++; + } +} + +// Probably an early draft before the 'CreateApprenticeMon' was written. +void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) +{ + s32 i, j; + u8 friendship = 0xFF; + u8 level = 0; + u8 fixedIV = 0; + struct Apprentice *apprentice = &gSaveBlock2Ptr->apprentices[0]; + + if (apprentice->field_1 < 5) + fixedIV = 6; + else + fixedIV = 9; + + if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50) + level = 100; + else + level = 50; + + for (i = 0; i != 3; i++) + { + CreateMonWithEVSpread(&gEnemyParty[firstMonId + i], apprentice->monData[i].species, level, fixedIV, 8); + friendship = 0xFF; + for (j = 0; j < 4; j++) + { + if (apprentice->monData[i].moves[j] == MOVE_FRUSTRATION) + friendship = 0; + } + SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship); + SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &apprentice->monData[i].item); + } +} + +u16 RandomizeFacilityTrainerMonId(u16 trainerId) +{ + u32 monPoolId; + u8 level = GetFacilityEnemyMonLevel(); + const u16 *bfMonPool = gFacilityTrainers[trainerId].bfMonPool; + u8 bfMonCount = 0; + + /* + I had to use ugly C tricks to get this part to match. + A cleaner version would look like this + + for (bfMonCount = 0; bfMonPool[bfMonCount] != 0xFFFF; bfMonCount++) + ; + + */ + + monPoolId = bfMonPool[bfMonCount]; + goto COMPARE; + while (1) + { + bfMonCount++; + monPoolId = bfMonPool[bfMonCount]; + COMPARE: + if (monPoolId == 0xFFFF) + break; + } + + do + { + monPoolId = bfMonPool[Random() % bfMonCount]; + } while((level == 50 || level == 20) && monPoolId > 849); + + return monPoolId; +} + +void sub_8163590(void) +{ + ZeroEnemyPartyMons(); + if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) + sub_81635D4(gTrainerBattleOpponent_A, 0); + else + sub_816379C(gTrainerBattleOpponent_A, 0); +} + +extern u16 gUnknown_03006298[]; + +void sub_81635D4(u16 trainerId, u8 firstMonId) +{ + u8 i, j; + u8 friendship; + u8 level; + u8 fixedIV; + u32 otID; + + if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; // Unused variable. + u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + u8 r1 = gSaveBlock2Ptr->frontier.field_CE0[battleMode][0] / 7; + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6) + fixedIV = sub_81A6CA8(r1, 0); + else + fixedIV = sub_81A6CA8(r1, 1); + } + else if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + for (i = firstMonId; i < firstMonId + 3; i++) + sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]); + return; + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + sub_81A6CD0(); + return; + } + else + { + fixedIV = 31; + } + + + level = GetFacilityEnemyMonLevel(); + otID = T1_READ_32(gSaveBlock2Ptr->playerTrainerId); + for (i = 0; i < 3; i++) + { + u16 poolId = gUnknown_03006298[i]; + CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[firstMonId + i], + gFacilityTrainerMons[poolId].species, + level, + gFacilityTrainerMons[poolId].nature, + fixedIV, + gFacilityTrainerMons[poolId].evSpread, + otID); + + friendship = 0; + for (j = 0; j < 4; j++) + SetMonMoveAvoidReturn(&gEnemyParty[firstMonId + i], gFacilityTrainerMons[poolId].moves[j], j); + + SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship); + SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[poolId].itemTableId]); + } +} + +void sub_816379C(u16 trainerId, u8 firstMonId) +{ + u8 i, j; + u8 friendship; + u8 level = 30; + u8 fixedIV = 0; + u32 otID = T1_READ_32(gSaveBlock2Ptr->playerTrainerId); + + for (i = 0; i < 3; i++) + { + u16 poolId = gUnknown_03006298[i]; + CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[firstMonId + i], + gFacilityTrainerMons[poolId].species, + level, + gFacilityTrainerMons[poolId].nature, + fixedIV, + gFacilityTrainerMons[poolId].evSpread, + otID); + + friendship = 0; + for (j = 0; j < 4; j++) + { + SetMonMoveAvoidReturn(&gEnemyParty[firstMonId + i], gFacilityTrainerMons[poolId].moves[j], j); + if (gFacilityTrainerMons[poolId].moves[j] == MOVE_FRUSTRATION) + friendship = 0; + } + + SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship); + SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[poolId].itemTableId]); + } +} + +void ConvertBattleFrontierTrainerSpeechToString(const u16 *words) +{ + ConvertEasyChatWordsToString(gStringVar4, words, 3, 2); + if (GetStringWidth(1, gStringVar4, -1) > 204) + { + s32 i = 0; + + ConvertEasyChatWordsToString(gStringVar4, words, 2, 3); + while (gStringVar4[i++] != CHAR_NEWLINE) + ; + while (gStringVar4[i] != CHAR_NEWLINE) + i++; + + gStringVar4[i] = CHAR_PROMPT_SCROLL; + } +} diff --git a/src/map_name_popup.c b/src/map_name_popup.c index 3feffd70d..94628f9c4 100644 --- a/src/map_name_popup.c +++ b/src/map_name_popup.c @@ -314,7 +314,7 @@ static void ShowMapNamePopUpWindow(void) else { withoutPrefixPtr = &(mapDisplayHeader[3]); - mapDisplayHeaderSource = gBattlePyramid_MapHeaderStrings[gSaveBlock2Ptr->frontier.field_CB2]; + mapDisplayHeaderSource = gBattlePyramid_MapHeaderStrings[gSaveBlock2Ptr->frontier.curChallengeBattleNum]; } StringCopy(withoutPrefixPtr, mapDisplayHeaderSource); } diff --git a/src/record_mixing.c b/src/record_mixing.c index 4c3c3d03c..4fb4a256e 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -686,7 +686,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u } CalcEmeraldBattleTowerChecksum(dest); } - sub_81628A0((void *)battleTowerRecord + recordSize * which); + PutNewBattleTowerRecord((void *)battleTowerRecord + recordSize * which); } static void ReceiveLilycoveLadyData(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) diff --git a/src/start_menu.c b/src/start_menu.c index dcb2c4154..aaa9fec2c 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -383,14 +383,14 @@ static void ShowSafariBallsWindow(void) static void ShowPyramidFloorWindow(void) { - if (gSaveBlock2Ptr->frontier.field_CB2 == 7) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum == 7) sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_1); else sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_2); PutWindowTilemap(sBattlePyramidFloorWindowId); NewMenuHelpers_DrawStdWindowFrame(sBattlePyramidFloorWindowId, FALSE); - StringCopy(gStringVar1, sPyramindFloorNames[gSaveBlock2Ptr->frontier.field_CB2]); + StringCopy(gStringVar1, sPyramindFloorNames[gSaveBlock2Ptr->frontier.curChallengeBattleNum]); StringExpandPlaceholders(gStringVar4, gText_BattlePyramidFloor); AddTextPrinterParameterized(sBattlePyramidFloorWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL); CopyWindowToVram(sBattlePyramidFloorWindowId, 2); diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 9a22323ff..ec69ad2b5 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -5102,7 +5102,7 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi } if (gMapHeader.mapLayoutId == 0x169) { - headerId = gSaveBlock2Ptr->frontier.field_CB2; + headerId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) return FALSE; else if (DoWildEncounterRateTest(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) @@ -5240,7 +5240,7 @@ bool8 SweetScentWildEncounter(void) } if (gMapHeader.mapLayoutId == 0x169) { - headerId = gSaveBlock2Ptr->frontier.field_CB2; + headerId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; if (TryGenerateWildMon(gBattlePyramidWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, 0) != TRUE) return FALSE; From 0ab27e44b14a0dc4523b5bac7fef18312ab4fdde Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 21 Oct 2018 20:13:12 +0200 Subject: [PATCH 3/8] more tower, fail --- asm/battle_frontier_2.s | 24 +- asm/battle_tower.s | 1526 +---------------- asm/pokenav.s | 8 +- data/battle_tower.s | 2 +- data/event_scripts.s | 5 +- .../scripts.inc | 6 +- .../scripts.inc | 6 +- .../scripts.inc | 10 +- .../scripts.inc | 6 +- .../scripts.inc | 26 +- .../scripts.inc | 4 +- .../scripts.inc | 6 +- .../scripts.inc | 4 +- .../scripts.inc | 2 +- .../MossdeepCity_SpaceCenter_2F/scripts.inc | 4 +- .../scripts.inc | 6 +- .../scripts.inc | 6 +- .../scripts.inc | 2 +- data/specials.inc | 2 +- include/battle.h | 1 + include/battle_tower.h | 2 +- include/constants/battle_frontier.h | 13 + include/constants/battle_script_commands.h | 7 +- include/global.h | 17 +- src/apprentice.c | 2 +- src/battle_frontier_1.c | 2 +- src/battle_tent.c | 2 +- src/battle_tower.c | 558 +++++- src/record_mixing.c | 4 +- src/secret_base.c | 3 +- 30 files changed, 628 insertions(+), 1638 deletions(-) diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 48673d4fa..108f1996c 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -3600,7 +3600,7 @@ _081A370C: ldr r0, [r2] adds r0, r1 adds r0, 0xC - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081A38F8 .pool _081A3738: @@ -3652,7 +3652,7 @@ _081A3794: ldr r0, [r2] adds r0, r1 adds r0, 0x18 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081A38F8 .pool _081A37B8: @@ -3720,7 +3720,7 @@ _081A3844: ldr r0, [r2] adds r0, r1 adds r0, 0x24 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081A38F8 .pool _081A3868: @@ -3736,7 +3736,7 @@ _081A3868: beq _081A3890 _081A387C: bl sub_81864E0 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081A38F8 .pool _081A3890: @@ -3764,7 +3764,7 @@ _081A38A8: ldr r1, =gApprentices+0x4A _081A38C4: adds r0, r1 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081A38F8 .pool _081A38D4: @@ -3784,7 +3784,7 @@ _081A38D4: muls r0, r3 ldr r1, =gApprentices+0x4A adds r0, r1 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString _081A38F8: pop {r0} bx r0 @@ -10896,7 +10896,7 @@ _081A7560: lsls r0, 2 ldr r1, =gUnknown_086123E4 adds r0, r1 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString pop {r0} bx r0 .pool @@ -12875,7 +12875,7 @@ sub_81A84EC: @ 81A84EC ldr r0, [r2] adds r0, r1 adds r0, 0xC - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081A8542 .pool _081A8524: @@ -12892,7 +12892,7 @@ _081A8524: ldr r0, [r2] adds r0, r1 adds r0, 0xC - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString _081A8542: pop {r0} bx r0 @@ -16003,7 +16003,7 @@ sub_81A9EDC: @ 81A9EDC ldr r0, [r2] adds r0, r1 adds r0, 0xC - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString pop {r0} bx r0 .pool @@ -16020,7 +16020,7 @@ sub_81A9EFC: @ 81A9EFC ldr r0, [r2] adds r0, r1 adds r0, 0x18 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString pop {r0} bx r0 .pool @@ -16037,7 +16037,7 @@ sub_81A9F1C: @ 81A9F1C ldr r0, [r2] adds r0, r1 adds r0, 0x24 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString pop {r0} bx r0 .pool diff --git a/asm/battle_tower.s b/asm/battle_tower.s index fd011c555..b8f138e7b 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -5,1526 +5,6 @@ .text - - - - - thumb_func_start sub_8163914 -sub_8163914: @ 8163914 - push {lr} - bl GetFacilityEnemyMonLevel - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0 - beq _08163930 - ldr r0, =gTrainerBattleOpponent_B - b _08163932 - .pool -_08163930: - ldr r0, =gTrainerBattleOpponent_A -_08163932: - ldrh r3, [r0] - movs r0, 0xFA - lsls r0, 1 - cmp r3, r0 - bne _08163950 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bfc - b _08163986 - .pool -_08163950: - ldr r0, =0x0000012b - cmp r3, r0 - bhi _08163974 - ldr r2, =gFacilityTrainers - movs r0, 0x34 - adds r1, r3, 0 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0xC - bl ConvertBattleFrontierTrainerSpeechToString - b _081639A8 - .pool -_08163974: - ldr r0, =0x0000018f - cmp r3, r0 - bhi _0816399C - ldr r1, =gSaveBlock2Ptr - movs r0, 0xEC - muls r0, r3 - ldr r1, [r1] - adds r0, r1 - ldr r1, =0xfffef2b8 -_08163986: - adds r0, r1 - bl ConvertBattleFrontierTrainerSpeechToString - b _081639A8 - .pool -_0816399C: - adds r0, r3, 0 - adds r0, 0x70 - lsls r0, 24 - lsrs r0, 24 - bl CopyFriendsApprenticeChallengeText -_081639A8: - pop {r0} - bx r0 - thumb_func_end sub_8163914 - - thumb_func_start sub_81639AC -sub_81639AC: @ 81639AC - push {r4-r6,lr} - sub sp, 0x4 - bl sub_81864CC - ldr r0, =gBattleScripting - adds r0, 0x26 - ldrb r0, [r0] - cmp r0, 0xA - bhi _08163A78 - lsls r0, 2 - ldr r1, =_081639D0 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081639D0: - .4byte _081639FC - .4byte _08163A38 - .4byte _08163A74 - .4byte _081639FC - .4byte _081639FC - .4byte _081639FC - .4byte _081639FC - .4byte _081639FC - .4byte _08163A78 - .4byte _081639FC - .4byte _081639FC -_081639FC: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000ebc - adds r1, r0, r2 - ldr r2, [r1] - ldr r0, =0x00fffffe - cmp r2, r0 - bhi _08163A2C - adds r0, r2, 0x1 - str r0, [r1] - movs r1, 0x14 - bl __umodsi3 - cmp r0, 0 - bne _08163A78 - bl UpdateGymLeaderRematch - b _08163A78 - .pool -_08163A2C: - ldr r0, =0x00ffffff - str r0, [r1] - b _08163A78 - .pool -_08163A38: - movs r5, 0 - ldr r6, =gSaveBlock1Ptr -_08163A3C: - movs r0, 0x64 - adds r4, r5, 0 - muls r4, r0 - movs r0, 0x8E - lsls r0, 2 - adds r1, r4, r0 - ldr r0, [r6] - adds r0, r1 - movs r1, 0xC - bl GetMonData - mov r1, sp - strh r0, [r1] - ldr r0, =gPlayerParty - adds r4, r0 - adds r0, r4, 0 - movs r1, 0xC - mov r2, sp - bl SetMonData - adds r5, 0x1 - cmp r5, 0x5 - ble _08163A3C - b _08163A78 - .pool -_08163A74: - bl sub_816537C -_08163A78: - ldr r0, =CB2_ReturnToFieldContinueScriptPlayMapMusic - bl SetMainCallback2 - add sp, 0x4 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81639AC - - thumb_func_start sub_8163A8C -sub_8163A8C: @ 8163A8C - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - bl IsBattleTransitionDone - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _08163AB0 - ldr r0, =gMain - ldr r1, =sub_81639AC - str r1, [r0, 0x8] - ldr r0, =CB2_InitBattle - bl SetMainCallback2 - adds r0, r4, 0 - bl DestroyTask -_08163AB0: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8163A8C - - thumb_func_start sub_8163AC4 -sub_8163AC4: @ 8163AC4 - push {r4-r6,lr} - sub sp, 0x4 - ldr r0, =gBattleScripting - ldr r2, =gSpecialVar_0x8004 - ldrh r1, [r2] - adds r0, 0x26 - strb r1, [r0] - ldrh r0, [r2] - cmp r0, 0xA - bls _08163ADA - b _08163E68 -_08163ADA: - lsls r0, 2 - ldr r1, =_08163AF0 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08163AF0: - .4byte _08163B1C - .4byte _08163BC0 - .4byte _08163C10 - .4byte _08163C70 - .4byte _08163CC4 - .4byte _08163D28 - .4byte _08163D74 - .4byte _08163DB4 - .4byte _08163E2C - .4byte _08163DF4 - .4byte _08163DC8 -_08163B1C: - ldr r5, =gBattleTypeFlags - movs r0, 0x84 - lsls r0, 1 - str r0, [r5] - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x1 - beq _08163B56 - cmp r4, 0x1 - bgt _08163B44 - cmp r4, 0 - beq _08163B4E - b _08163BA6 - .pool -_08163B44: - cmp r4, 0x2 - beq _08163B64 - cmp r4, 0x3 - beq _08163B98 - b _08163BA6 -_08163B4E: - movs r0, 0x3 - bl sub_8163048 - b _08163BA6 -_08163B56: - movs r0, 0x4 - bl sub_8163048 - ldr r0, [r5] - orrs r0, r4 - str r0, [r5] - b _08163BA6 -_08163B64: - movs r0, 0x2 - bl sub_816306C - ldr r1, =gPartnerTrainerId - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000cd6 - adds r0, r2 - ldrh r0, [r0] - strh r0, [r1] - ldrh r0, [r1] - bl sub_8165404 - ldr r0, [r5] - ldr r1, =0x00408041 - orrs r0, r1 - str r0, [r5] - b _08163BA6 - .pool -_08163B98: - ldr r0, [r5] - ldr r1, =0x00800043 - orrs r0, r1 - str r0, [r5] - movs r0, 0x2 - bl sub_816306C -_08163BA6: - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0 - b _08163E10 - .pool -_08163BC0: - movs r5, 0 - ldr r6, =gSaveBlock1Ptr -_08163BC4: - movs r0, 0x64 - adds r4, r5, 0 - muls r4, r0 - ldr r0, =gPlayerParty - adds r0, r4, r0 - movs r1, 0xC - bl GetMonData - mov r1, sp - strh r0, [r1] - movs r0, 0x8E - lsls r0, 2 - adds r4, r0 - ldr r0, [r6] - adds r0, r4 - movs r1, 0xC - mov r2, sp - bl SetMonData - adds r5, 0x1 - cmp r5, 0x5 - ble _08163BC4 - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0xC - b _08163E10 - .pool -_08163C10: - bl ZeroEnemyPartyMons - movs r5, 0 - ldr r4, =gSaveBlock2Ptr -_08163C18: - movs r0, 0x64 - muls r0, r5 - ldr r1, =gEnemyParty - adds r0, r1 - movs r1, 0x2C - adds r2, r5, 0 - muls r2, r1 - movs r1, 0xC2 - lsls r1, 4 - adds r2, r1 - ldr r1, [r4] - adds r1, r2 - bl sub_806819C - adds r5, 0x1 - cmp r5, 0x2 - ble _08163C18 - ldr r1, =gBattleTypeFlags - ldr r0, =0x00000808 - str r0, [r1] - ldr r1, =gTrainerBattleOpponent_A - movs r0, 0 - strh r0, [r1] - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0xD - b _08163E10 - .pool -_08163C70: - ldr r4, =gBattleTypeFlags - ldr r0, =0x00010008 - str r0, [r4] - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0x1 - bne _08163C8A - ldr r0, [r4] - orrs r0, r1 - str r0, [r4] -_08163C8A: - ldr r0, =gTrainerBattleOpponent_A - ldrh r1, [r0] - ldr r0, =0x000003fe - cmp r1, r0 - bne _08163C9A - movs r0, 0x2 - bl sub_8163048 -_08163C9A: - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl sub_806E694 - movs r0, 0x3 - b _08163E10 - .pool -_08163CC4: - ldr r4, =gBattleTypeFlags - ldr r0, =0x00020008 - str r0, [r4] - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0x1 - bne _08163CDE - ldr r0, [r4] - orrs r0, r1 - str r0, [r4] -_08163CDE: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - beq _08163D0C - movs r0, 0x3 - bl sub_8163048 - b _08163D12 - .pool -_08163D0C: - movs r0, 0x3 - bl sub_81630A0 -_08163D12: - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0x4 - b _08163E10 - .pool -_08163D28: - ldr r1, =gBattleTypeFlags - ldr r0, =0x00040008 - str r0, [r1] - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - beq _08163D58 - movs r0, 0x3 - bl sub_8163048 - b _08163D5E - .pool -_08163D58: - movs r0, 0x3 - bl sub_81630A0 -_08163D5E: - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0x5 - b _08163E10 - .pool -_08163D74: - ldr r4, =gBattleTypeFlags - ldr r0, =0x00080008 - str r0, [r4] - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0x1 - bne _08163D8E - ldr r0, [r4] - orrs r0, r1 - str r0, [r4] -_08163D8E: - bl sub_8163590 - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0x6 - b _08163E10 - .pool -_08163DB4: - ldr r1, =gBattleTypeFlags - movs r0, 0x84 - lsls r0, 1 - str r0, [r1] - movs r0, 0x3 - bl sub_8163048 - b _08163E00 - .pool -_08163DC8: - ldr r1, =gBattleTypeFlags - ldr r0, =0x00200008 - str r0, [r1] - movs r0, 0x3 - bl sub_8163048 - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0xA - b _08163E10 - .pool -_08163DF4: - ldr r1, =gBattleTypeFlags - ldr r0, =0x00008109 - str r0, [r1] - movs r0, 0x1 - bl sub_816306C -_08163E00: - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0x7 -_08163E10: - bl sub_80B100C - lsls r0, 24 - lsrs r0, 24 - bl BattleTransition_StartOnField - b _08163E68 - .pool -_08163E2C: - ldr r1, =gBattleTypeFlags - ldr r0, =0x00408049 - str r0, [r1] - ldr r5, =0x00000c03 - adds r0, r5, 0 - bl sub_8165404 - ldr r4, =gApproachingTrainerId - movs r0, 0 - strb r0, [r4] - ldr r0, =MossdeepCity_SpaceCenter_2F_EventScript_224157 + 1 - bl BattleSetup_ConfigureTrainerBattle - movs r0, 0x1 - strb r0, [r4] - ldr r0, =MossdeepCity_SpaceCenter_2F_EventScript_224166 + 1 - bl BattleSetup_ConfigureTrainerBattle - ldr r0, =gPartnerTrainerId - strh r5, [r0] - ldr r0, =sub_8163A8C - movs r1, 0x1 - bl CreateTask - movs r0, 0 - bl PlayMapChosenOrBattleBGM - movs r0, 0x12 - bl BattleTransition_StartOnField -_08163E68: - add sp, 0x4 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8163AC4 - - thumb_func_start sub_8163E90 -sub_8163E90: @ 8163E90 - push {r4-r6,lr} - ldr r6, =gSaveBlock2Ptr - ldr r0, [r6] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r5, [r0] - lsls r5, 30 - lsrs r5, 30 - ldr r0, =0x000040ce - bl VarGet - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetCurrentBattleTowerWinStreak - lsls r0, 16 - lsrs r2, r0, 16 - ldr r0, [r6] - lsls r5, 1 - lsls r4, 2 - adds r5, r4 - movs r1, 0xCE - lsls r1, 4 - adds r0, r1 - adds r1, r0, r5 - ldrh r0, [r1] - cmp r0, r2 - bcs _08163ED0 - strh r2, [r1] -_08163ED0: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8163E90 - - thumb_func_start sub_8163EE4 -sub_8163EE4: @ 8163EE4 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r1, =0x0000064c - adds r5, r0, r1 - adds r0, r5, 0 - bl sub_8164FB8 - ldr r0, [r4] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r6, r0, 30 - ldr r0, =0x000040ce - bl VarGet - lsls r0, 24 - lsrs r7, r0, 24 - ldr r2, [r4] - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _08163F40 - ldr r4, =gTowerFemaleFacilityClasses - ldrb r0, [r2, 0xA] - ldrb r1, [r2, 0xB] - adds r0, r1 - ldrb r1, [r2, 0xC] - adds r0, r1 - ldrb r1, [r2, 0xD] - adds r0, r1 - movs r1, 0x14 - b _08163F52 - .pool -_08163F40: - ldr r4, =gTowerMaleFacilityClasses - ldrb r0, [r2, 0xA] - ldrb r1, [r2, 0xB] - adds r0, r1 - ldrb r1, [r2, 0xC] - adds r0, r1 - ldrb r1, [r2, 0xD] - adds r0, r1 - movs r1, 0x1E -_08163F52: - bl __umodsi3 - adds r0, r4 - ldrb r0, [r0] - strb r6, [r5] - strb r0, [r5, 0x1] - adds r0, r5, 0 - adds r0, 0xC - ldr r4, =gSaveBlock2Ptr - ldr r1, [r4] - adds r1, 0xA - bl CopyUnalignedWord - adds r0, r5, 0x4 - ldr r1, [r4] - bl StringCopy7 - adds r0, r6, 0 - adds r1, r7, 0 - bl GetCurrentBattleTowerWinStreak - strh r0, [r5, 0x2] - movs r4, 0 - movs r2, 0x10 - adds r2, r5 - mov r12, r2 - movs r7, 0x1C - adds r7, r5 - mov r9, r7 - adds r6, r5, 0 - adds r6, 0x28 - movs r0, 0xE4 - adds r0, r5 - mov r8, r0 -_08163F96: - lsls r2, r4, 1 - mov r1, r12 - adds r3, r1, r2 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r7, =0x00002bbc - adds r0, r1, r7 - adds r0, r2 - ldrh r0, [r0] - strh r0, [r3] - mov r0, r9 - adds r3, r0, r2 - adds r7, 0xC - adds r0, r1, r7 - adds r0, r2 - ldrh r0, [r0] - strh r0, [r3] - adds r3, r6, r2 - ldr r0, =0x00002bd4 - adds r1, r0 - adds r1, r2 - ldrh r0, [r1] - strh r0, [r3] - adds r4, 0x1 - cmp r4, 0x5 - ble _08163F96 - movs r4, 0 -_08163FCC: - ldr r6, =gSaveBlock2Ptr - ldr r0, [r6] - lsls r1, r4, 1 - ldr r2, =0x00000caa - adds r0, r2 - adds r1, r0, r1 - ldrh r0, [r1] - cmp r0, 0 - beq _08163FF4 - adds r1, r0, 0 - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - 100 - adds r0, r1 - movs r1, 0x2C - muls r1, r4 - adds r1, 0x34 - adds r1, r5, r1 - bl sub_80686FC -_08163FF4: - adds r4, 0x1 - cmp r4, 0x3 - ble _08163FCC - ldr r0, =gGameLanguage - ldrb r0, [r0] - mov r7, r8 - strb r0, [r7] - ldr r0, [r6] - ldr r1, =0x0000064c - adds r0, r1 - bl CalcEmeraldBattleTowerChecksum - bl sub_8163E90 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8163EE4 - - thumb_func_start sub_8164040 -sub_8164040: @ 8164040 - push {r4,r5,lr} - ldr r5, =gSaveBlock2Ptr - ldr r0, [r5] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r4, [r0] - lsls r4, 30 - lsrs r4, 30 - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - ldr r5, [r5] - lsls r4, 1 - lsrs r0, 14 - adds r4, r0 - movs r2, 0xCE - lsls r2, 4 - adds r0, r5, r2 - adds r0, r4 - ldrh r0, [r0] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r1, r0, 16 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0 - bne _0816408E - cmp r1, 0x1 - bgt _0816408A - ldr r1, =0x00000cb2 - adds r0, r5, r1 - ldrh r0, [r0] - cmp r0, 0 - beq _0816408E -_0816408A: - bl sub_8163EE4 -_0816408E: - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r1, =gSpecialVar_0x8005 - ldrh r1, [r1] - ldr r2, =0x00000ca8 - adds r0, r2 - strb r1, [r0] - movs r0, 0x80 - lsls r0, 7 - movs r1, 0 - bl VarSet - ldr r1, [r4] - ldr r0, =0x00000ca9 - adds r1, r0 - ldrb r0, [r1] - movs r2, 0x4 - orrs r0, r2 - strb r0, [r1] - bl sub_81A4C30 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164040 - - thumb_func_start nullsub_61 -nullsub_61: @ 81640D8 - bx lr - thumb_func_end nullsub_61 - - thumb_func_start nullsub_116 -nullsub_116: @ 81640DC - bx lr - thumb_func_end nullsub_116 - - thumb_func_start sub_81640E0 -sub_81640E0: @ 81640E0 - push {r4-r7,lr} - sub sp, 0xC - adds r5, r0, 0 - lsls r5, 16 - lsrs r5, 16 - ldr r4, =gPlayerParty - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - lsls r0, 16 - lsrs r7, r0, 16 - adds r4, 0x64 - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - lsls r0, 16 - lsrs r4, r0, 16 - movs r6, 0 - movs r2, 0 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r5, r0 - lsls r0, r5, 4 - adds r0, r5 - lsls r0, 2 - adds r1, 0xE0 - adds r0, r1 - mov r3, sp -_08164122: - ldrh r1, [r0] - cmp r1, r7 - beq _08164130 - cmp r1, r4 - beq _08164130 - stm r3!, {r2} - adds r6, 0x1 -_08164130: - adds r0, 0xC - adds r2, 0x1 - cmp r2, 0x2 - ble _08164122 - bl Random - ldr r4, =gUnknown_03006298 - lsls r0, 16 - lsrs r0, 16 - adds r1, r6, 0 - bl __modsi3 - lsls r0, 2 - add r0, sp - ldr r0, [r0] - strh r0, [r4] -_08164150: - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r6, 0 - bl __modsi3 - lsls r0, 2 - add r0, sp - ldr r0, [r0] - strh r0, [r4, 0x2] - ldrh r1, [r4] - lsls r0, 16 - lsrs r0, 16 - cmp r1, r0 - beq _08164150 - add sp, 0xC - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81640E0 - - thumb_func_start sub_8164188 -sub_8164188: @ 8164188 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x1C - adds r5, r0, 0 - lsls r5, 16 - lsrs r5, 16 - ldr r6, =gSaveBlock2Ptr - ldr r0, [r6] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - str r0, [sp, 0xC] - ldr r4, =gPlayerParty - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x10] - adds r4, 0x64 - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x14] - movs r3, 0 - mov r8, r3 - movs r7, 0 - adds r2, r6, 0 - ldr r0, =0xfffffed4 - adds r5, r0 - ldr r6, =0x0000076c - mov r10, sp - movs r0, 0xEC - adds r1, r5, 0 - muls r1, r0 - mov r9, r1 -_081641E6: - ldr r1, [r2] - movs r0, 0x2C - muls r0, r7 - mov r3, r9 - adds r5, r0, r3 - adds r1, r5 - adds r0, r1, r6 - ldrh r0, [r0] - ldr r3, [sp, 0x10] - cmp r0, r3 - beq _0816423A - ldr r3, [sp, 0x14] - cmp r0, r3 - beq _0816423A - movs r0, 0xEF - lsls r0, 3 - adds r4, r1, r0 - ldr r1, [sp, 0xC] - lsls r0, r1, 24 - lsrs r0, 24 - str r2, [sp, 0x18] - bl GetFrontierEnemyMonLevel - ldrb r1, [r4] - lsls r0, 24 - lsrs r0, 24 - ldr r2, [sp, 0x18] - cmp r1, r0 - bhi _0816423A - ldr r0, [r2] - adds r0, r5 - adds r0, r6 - ldrh r0, [r0] - cmp r0, 0 - beq _0816423A - mov r3, r10 - adds r3, 0x4 - mov r10, r3 - subs r3, 0x4 - stm r3!, {r7} - movs r0, 0x1 - add r8, r0 -_0816423A: - adds r7, 0x1 - cmp r7, 0x3 - ble _081641E6 - bl Random - ldr r4, =gUnknown_03006298 - lsls r0, 16 - lsrs r0, 16 - mov r1, r8 - bl __modsi3 - lsls r0, 2 - add r0, sp - ldr r0, [r0] - strh r0, [r4, 0x4] -_08164258: - bl Random - lsls r0, 16 - lsrs r0, 16 - mov r1, r8 - bl __modsi3 - lsls r0, 2 - add r0, sp - ldr r0, [r0] - strh r0, [r4, 0x6] - ldrh r1, [r4, 0x4] - lsls r0, 16 - lsrs r0, 16 - cmp r1, r0 - beq _08164258 - add sp, 0x1C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164188 - - thumb_func_start sub_81642A0 -sub_81642A0: @ 81642A0 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4C - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r1, r0, r1 - str r1, [sp, 0x24] - ldr r5, =gSaveBlock2Ptr - ldr r0, [r5] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - str r0, [sp, 0x14] - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - ldr r1, [r5] - ldr r3, [sp, 0x14] - lsls r2, r3, 1 - lsrs r0, 14 - adds r2, r0 - movs r4, 0xCE - lsls r4, 4 - adds r1, r4 - adds r1, r2 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x18] - ldr r4, =gPlayerParty - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - str r0, [sp, 0x1C] - adds r4, 0x64 - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - str r0, [sp, 0x20] - bl GetFacilityEnemyMonLevel - movs r7, 0 - ldr r0, [sp, 0x18] - lsls r0, 24 - mov r10, r0 -_08164318: - lsls r6, r7, 1 -_0816431A: - mov r1, r10 - lsrs r0, r1, 24 - movs r1, 0 - bl sub_8162548 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - movs r2, 0 - mov r9, r2 - cmp r9, r7 - bge _08164368 - ldr r0, [r5] - ldr r3, =0x00000cb4 - adds r1, r0, r3 - ldrh r0, [r1] - cmp r0, r8 - beq _08164368 - ldr r0, =gFacilityTrainers - ldr r2, [r0] - movs r4, 0x34 - mov r0, r8 - muls r0, r4 - adds r0, r2 - ldrb r3, [r0] -_0816434C: - ldrh r0, [r1] - muls r0, r4 - adds r0, r2 - ldrb r0, [r0] - cmp r0, r3 - beq _08164368 - adds r1, 0x2 - movs r0, 0x1 - add r9, r0 - cmp r9, r7 - bge _08164368 - ldrh r0, [r1] - cmp r0, r8 - bne _0816434C -_08164368: - cmp r9, r7 - bne _0816431A - ldr r0, [r5] - ldr r1, =0x00000cb4 - adds r0, r1 - adds r0, r6 - mov r2, r8 - strh r2, [r0] - mov r7, r9 - adds r7, 0x1 - cmp r7, 0x5 - ble _08164318 - movs r3, 0x8 - mov r10, r3 - movs r4, 0 - mov r9, r4 - ldr r0, [sp, 0x24] - str r0, [sp, 0x40] -_0816438C: - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - mov r2, r9 - lsls r1, r2, 1 - ldr r3, =0x00000cb4 - adds r0, r3 - adds r0, r1 - ldrh r0, [r0] - mov r8, r0 - bl GetBattleFacilityTrainerGfxId - ldr r4, [sp, 0x40] - strb r0, [r4, 0x19] - movs r7, 0 -_081643A8: - adds r0, r7, 0x1 - str r0, [sp, 0x30] - mov r1, r10 - lsls r1, 1 - str r1, [sp, 0x38] - mov r2, r10 - adds r2, 0x1 - str r2, [sp, 0x34] - mov r0, r10 - subs r0, 0x1 - lsls r0, 1 - str r0, [sp, 0x28] -_081643C0: - mov r0, r8 - bl RandomizeFacilityTrainerMonId - lsls r0, 16 - lsrs r6, r0, 16 - movs r0, 0x1 - ands r0, r7 - cmp r0, 0 - beq _081643F4 - ldr r3, =gSaveBlock2Ptr - ldr r0, [r3] - ldr r4, =0x00000cb4 - adds r0, r4 - ldr r1, [sp, 0x28] - adds r0, r1 - ldrh r2, [r0] - ldr r0, =gFacilityTrainerMons - ldr r0, [r0] - lsls r2, 4 - adds r2, r0 - lsls r1, r6, 4 - adds r1, r0 - ldrb r0, [r2, 0xA] - ldrb r1, [r1, 0xA] - cmp r0, r1 - beq _081643C0 -_081643F4: - movs r5, 0x8 - cmp r5, r10 - bge _08164430 - ldr r2, =gSaveBlock2Ptr - ldr r0, [r2] - ldr r1, =gFacilityTrainerMons - ldr r3, [r1] - lsls r1, r6, 4 - adds r1, r3 - ldr r4, =0x00000cc4 - adds r2, r0, r4 - ldrh r0, [r1] - mov r12, r0 -_0816440E: - ldrh r0, [r2] - lsls r0, 4 - adds r0, r3 - ldrh r0, [r0] - cmp r0, r12 - beq _08164430 - ldrh r0, [r1] - ldr r4, [sp, 0x1C] - cmp r4, r0 - beq _08164430 - ldr r4, [sp, 0x20] - cmp r4, r0 - beq _08164430 - adds r2, 0x2 - adds r5, 0x1 - cmp r5, r10 - blt _0816440E -_08164430: - cmp r5, r10 - bne _081643C0 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r2, =0x00000cb4 - adds r0, r2 - ldr r3, [sp, 0x38] - adds r0, r3 - strh r6, [r0] - ldr r4, [sp, 0x34] - mov r10, r4 - ldr r7, [sp, 0x30] - cmp r7, 0x1 - ble _081643A8 - ldr r0, [sp, 0x40] - adds r0, 0x18 - str r0, [sp, 0x40] - movs r1, 0x1 - add r9, r1 - mov r2, r9 - cmp r2, 0x5 - ble _0816438C - movs r3, 0 - mov r10, r3 - bl sub_8165B20 - movs r4, 0 - mov r9, r4 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r2, 0 - adds r6, r0, 0 - adds r6, 0xDC - mov r8, sp -_08164474: - ldrb r0, [r6] - lsls r4, r0, 25 - lsrs r0, r4, 30 - cmp r0, 0 - beq _081644E0 - ldr r1, =gUnknown_085DF9EC - ldrb r0, [r6, 0x1] - adds r0, r1 - ldrb r0, [r0] - movs r1, 0x7 - str r2, [sp, 0x44] - bl __udivsi3 - lsls r0, 24 - lsrs r0, 24 - ldr r2, [sp, 0x44] - ldr r1, [sp, 0x18] - cmp r0, r1 - bgt _081644E0 - lsrs r0, r4, 30 - subs r0, 0x1 - ldr r3, [sp, 0x14] - cmp r0, r3 - bne _081644E0 - movs r5, 0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - adds r0, 0xE0 - adds r1, r2, r0 - movs r7, 0x2 -_081644B0: - ldrh r0, [r1] - ldr r4, [sp, 0x1C] - cmp r4, r0 - beq _081644C0 - ldr r3, [sp, 0x20] - cmp r3, r0 - beq _081644C0 - adds r5, 0x1 -_081644C0: - adds r1, 0xC - subs r7, 0x1 - cmp r7, 0 - bge _081644B0 - cmp r5, 0x2 - ble _081644E0 - movs r0, 0xC8 - lsls r0, 1 - add r0, r9 - mov r4, r8 - adds r4, 0x4 - mov r8, r4 - subs r4, 0x4 - stm r4!, {r0} - movs r0, 0x1 - add r10, r0 -_081644E0: - adds r2, 0x44 - adds r6, 0x44 - movs r1, 0x1 - add r9, r1 - mov r3, r9 - cmp r3, 0x3 - ble _08164474 - mov r4, r10 - cmp r4, 0 - beq _08164532 - bl Random - ldr r6, =gSaveBlock2Ptr - ldr r4, [r6] - lsls r0, 16 - lsrs r0, 16 - mov r1, r10 - bl __modsi3 - lsls r0, 2 - add r0, sp - ldr r0, [r0] - movs r5, 0xCC - lsls r5, 4 - adds r4, r5 - strh r0, [r4] - ldrh r0, [r4] - bl GetBattleFacilityTrainerGfxId - ldr r1, [sp, 0x24] - adds r1, 0xA8 - strb r0, [r1, 0x1] - movs r0, 0xD8 - lsls r0, 2 - bl FlagClear - ldr r0, [r6] - adds r0, r5 - ldrh r0, [r0] - bl sub_81640E0 -_08164532: - movs r0, 0 - mov r10, r0 - mov r9, r0 - mov r1, sp - str r1, [sp, 0x3C] -_0816453C: - ldr r0, =gSaveBlock2Ptr - movs r2, 0xEC - mov r1, r9 - muls r1, r2 - movs r3, 0xE7 - lsls r3, 3 - adds r1, r3 - ldr r0, [r0] - movs r2, 0 - movs r3, 0 - movs r7, 0 - mov r4, r9 - adds r4, 0x1 - str r4, [sp, 0x2C] - adds r1, r0, r1 -_0816455A: - ldm r1!, {r0} - orrs r2, r0 - adds r3, r0 - adds r7, 0x1 - cmp r7, 0x39 - bls _0816455A - ldr r0, =gSaveBlock2Ptr - ldr r5, [r0] - movs r1, 0xEC - mov r6, r9 - muls r6, r1 - adds r4, r5, r6 - ldr r1, =0x0000073a - adds r0, r4, r1 - ldrh r0, [r0] - movs r1, 0x7 - str r2, [sp, 0x44] - str r3, [sp, 0x48] - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - ldr r2, [sp, 0x44] - ldr r3, [sp, 0x48] - ldr r1, [sp, 0x18] - cmp r0, r1 - bgt _08164656 - movs r1, 0xE7 - lsls r1, 3 - adds r0, r4, r1 - ldrb r0, [r0] - ldr r4, [sp, 0x14] - cmp r0, r4 - bne _08164656 - cmp r2, 0 - beq _08164656 - adds r1, 0xE8 - adds r0, r5, r1 - adds r0, r6 - ldr r0, [r0] - cmp r0, r3 - bne _08164656 - movs r5, 0 - movs r7, 0 - ldr r2, =gSaveBlock2Ptr - mov r8, r2 - ldr r3, =0x0000076c -_081645B8: - mov r4, r8 - ldr r2, [r4] - movs r0, 0x2C - adds r1, r7, 0 - muls r1, r0 - movs r4, 0xEC - mov r0, r9 - muls r0, r4 - adds r6, r1, r0 - adds r2, r6 - adds r0, r2, r3 - ldrh r0, [r0] - ldr r1, [sp, 0x1C] - cmp r1, r0 - beq _0816463C - ldr r4, [sp, 0x20] - cmp r4, r0 - beq _0816463C - movs r0, 0xEF - lsls r0, 3 - adds r4, r2, r0 - ldr r1, [sp, 0x14] - lsls r0, r1, 24 - lsrs r0, 24 - str r3, [sp, 0x48] - bl GetFrontierEnemyMonLevel - ldrb r1, [r4] - lsls r0, 24 - lsrs r0, 24 - ldr r3, [sp, 0x48] - cmp r1, r0 - bhi _0816463C - mov r2, r8 - ldr r0, [r2] - adds r0, r6 - adds r0, r3 - ldrh r0, [r0] - cmp r0, 0 - b _08164638 - .pool -_08164638: - beq _0816463C - adds r5, 0x1 -_0816463C: - adds r7, 0x1 - cmp r7, 0x3 - ble _081645B8 - cmp r5, 0x1 - ble _08164656 - movs r0, 0x96 - lsls r0, 1 - add r0, r9 - ldr r3, [sp, 0x3C] - stm r3!, {r0} - str r3, [sp, 0x3C] - movs r4, 0x1 - add r10, r4 -_08164656: - ldr r0, [sp, 0x2C] - mov r9, r0 - cmp r0, 0x4 - bgt _08164660 - b _0816453C -_08164660: - mov r1, r10 - cmp r1, 0 - beq _081646A0 - bl Random - ldr r6, =gSaveBlock2Ptr - ldr r4, [r6] - lsls r0, 16 - lsrs r0, 16 - mov r1, r10 - bl __modsi3 - lsls r0, 2 - add r0, sp - ldr r0, [r0] - ldr r5, =0x00000cc2 - adds r4, r5 - strh r0, [r4] - ldrh r0, [r4] - bl GetBattleFacilityTrainerGfxId - ldr r1, [sp, 0x24] - adds r1, 0xC0 - strb r0, [r1, 0x1] - ldr r0, =0x00000361 - bl FlagClear - ldr r0, [r6] - adds r0, r5 - ldrh r0, [r0] - bl sub_8164188 -_081646A0: - add sp, 0x4C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81642A0 - thumb_func_start sub_81646BC sub_81646BC: @ 81646BC push {r4-r7,lr} @@ -2979,7 +1459,7 @@ sub_8165360: @ 8165360 ldr r0, [r0] ldr r1, =0x00000bfc adds r0, r1 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString pop {r0} bx r0 .pool @@ -3004,7 +1484,7 @@ _08165398: ldr r0, [r0] ldr r1, =0x00000c14 adds r0, r1 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081653C0 .pool _081653B4: @@ -3012,7 +1492,7 @@ _081653B4: ldr r0, [r0] ldr r1, =0x00000c08 adds r0, r1 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString _081653C0: pop {r0} bx r0 diff --git a/asm/pokenav.s b/asm/pokenav.s index a8d3c838f..b3a174bdc 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -28371,7 +28371,7 @@ _081D5764: adds r1, 0x4 adds r0, r1 adds r0, 0x10 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081D580E .pool _081D5790: @@ -28392,7 +28392,7 @@ _081D5790: adds r1, 0x4 adds r0, r1 adds r0, 0x1C - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081D580E .pool _081D57BC: @@ -28413,7 +28413,7 @@ _081D57BC: adds r1, 0x4 adds r0, r1 adds r0, 0x28 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString b _081D580E .pool _081D57E8: @@ -28434,7 +28434,7 @@ _081D57E8: adds r1, 0x4 adds r0, r1 adds r0, 0x34 - bl ConvertBattleFrontierTrainerSpeechToString + bl FrontierSpeechToString _081D580E: bl sub_81D5710 pop {r4-r6} diff --git a/data/battle_tower.s b/data/battle_tower.s index ec5ee924e..296db3577 100644 --- a/data/battle_tower.s +++ b/data/battle_tower.s @@ -686,7 +686,7 @@ gUnknown_085DF96C:: @ 85DF96C .4byte ChooseNextBattleTowerTrainer .4byte sub_81621C0 .4byte sub_816502C - .4byte sub_8164040 + .4byte SaveBattleTowerProgress .4byte sub_8163914 .4byte nullsub_61 .4byte nullsub_116 diff --git a/data/event_scripts.s b/data/event_scripts.s index 46ba34db5..4534ccf13 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -7,6 +7,7 @@ #include "constants/vars.h" #include "constants/heal_locations.h" #include "constants/trainers.h" +#include "constants/battle_frontier.h" .include "asm/macros.inc" .include "asm/macros/event.inc" .include "constants/constants.inc" @@ -5126,9 +5127,9 @@ SecretBase_RedCave1_EventScript_27627C:: @ 827627C SecretBase_RedCave1_EventScript_276286:: @ 8276286 special sub_80EA2E4 - setvar VAR_0x8004, 1 + setvar VAR_0x8004, SPECIAL_BATTLE_SECRET_BASE setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate compare VAR_RESULT, 3 call_if 1, SecretBase_RedCave1_EventScript_2762BD diff --git a/data/maps/BattleFrontier_BattleArenaBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleArenaBattleRoom/scripts.inc index 076eeab6e..888ca9878 100644 --- a/data/maps/BattleFrontier_BattleArenaBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleArenaBattleRoom/scripts.inc @@ -89,7 +89,7 @@ BattleFrontier_BattleArenaBattleRoom_EventScript_25752E:: @ 825752E waitmovement 0 setvar VAR_0x8004, 5 special sub_8195960 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage call BattleFrontier_BattleArenaBattleRoom_EventScript_257B6C switch VAR_RESULT @@ -431,9 +431,9 @@ FallarborTown_BattleTentBattleRoom_EventScript_257B6C:: @ 8257B6C setvar VAR_0x8006, 0 special sub_81A1780 special HealPlayerParty - setvar VAR_0x8004, 5 + setvar VAR_0x8004, SPECIAL_BATTLE_ARENA setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate setvar VAR_0x8004, 18 special sub_81A1780 diff --git a/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc index 3d5704dba..0a4052f23 100644 --- a/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc @@ -81,7 +81,7 @@ BattleFrontier_BattleDomeBattleRoom_EventScript_24BD82:: @ 824BD82 setvar VAR_0x8004, 7 setvar VAR_0x8005, 0 special sub_8161F74 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 closemessage setvar VAR_0x8004, 5 special CallBattleDomeFunction @@ -529,10 +529,10 @@ BattleFrontier_BattleDomeBattleRoom_EventScript_24C440:: @ 824C440 setvar VAR_0x8006, 0 special sub_81A1780 special HealPlayerParty - setvar VAR_0x8004, 3 + setvar VAR_0x8004, SPECIAL_BATTLE_DOME setvar VAR_0x8005, 0 setvar VAR_TEMP_9, 1 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate setvar VAR_TEMP_9, 0 setvar VAR_0x8004, 17 diff --git a/data/maps/BattleFrontier_BattleFactoryBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleFactoryBattleRoom/scripts.inc index 2968e2c0f..ef26ad3a7 100644 --- a/data/maps/BattleFrontier_BattleFactoryBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleFactoryBattleRoom/scripts.inc @@ -82,7 +82,7 @@ BattleFrontier_BattleFactoryBattleRoom_EventScript_25AEA7:: @ 825AEA7 setvar VAR_0x8004, 5 special sub_8195960 lockall - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage closemessage setvar VAR_0x8004, 2 @@ -90,9 +90,9 @@ BattleFrontier_BattleFactoryBattleRoom_EventScript_25AEA7:: @ 825AEA7 setvar VAR_0x8006, 0 special sub_81A1780 special HealPlayerParty - setvar VAR_0x8004, 6 + setvar VAR_0x8004, SPECIAL_BATTLE_FACTORY setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate switch VAR_RESULT case 1, BattleFrontier_BattleFactoryBattleRoom_EventScript_25AF0F @@ -226,9 +226,9 @@ BattleFrontier_BattleFactoryBattleRoom_EventScript_25B0E0:: @ 825B0E0 setvar VAR_0x8006, 0 special sub_81A1780 special HealPlayerParty - setvar VAR_0x8004, 6 + setvar VAR_0x8004, SPECIAL_BATTLE_FACTORY setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate return diff --git a/data/maps/BattleFrontier_BattlePalaceBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattlePalaceBattleRoom/scripts.inc index 372b5da76..e97297a16 100644 --- a/data/maps/BattleFrontier_BattlePalaceBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattlePalaceBattleRoom/scripts.inc @@ -61,7 +61,7 @@ BattleFrontier_BattlePalaceBattleRoom_EventScript_24F8BF:: @ 824F8BF waitmovement 0 setvar VAR_0x8004, 5 special sub_8195960 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage call BattleFrontier_BattlePalaceBattleRoom_EventScript_24FDF7 switch VAR_RESULT @@ -338,9 +338,9 @@ VerdanturfTown_BattleTentBattleRoom_EventScript_24FDF7:: @ 824FDF7 setvar VAR_0x8006, 0 special sub_81A1780 special HealPlayerParty - setvar VAR_0x8004, 4 + setvar VAR_0x8004, SPECIAL_BATTLE_PALACE setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate setvar VAR_0x8004, 18 special sub_81A1780 diff --git a/data/maps/BattleFrontier_BattlePikeRandomRoom1/scripts.inc b/data/maps/BattleFrontier_BattlePikeRandomRoom1/scripts.inc index 509806531..d1dc7d13e 100644 --- a/data/maps/BattleFrontier_BattlePikeRandomRoom1/scripts.inc +++ b/data/maps/BattleFrontier_BattlePikeRandomRoom1/scripts.inc @@ -30,13 +30,13 @@ BattleFrontier_BattlePikeRandomRoom1_EventScript_25D1C6:: @ 825D1C6 setvar VAR_0x8004, 21 setvar VAR_0x8005, 0 special sub_81A703C - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage closemessage releaseall - setvar VAR_0x8004, 7 + setvar VAR_0x8004, SPECIAL_BATTLE_PIKE_SINGLE setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate switch VAR_RESULT case 1, BattleFrontier_BattlePikeRandomRoom1_EventScript_25D226 @@ -66,13 +66,13 @@ BattleFrontier_BattlePikeRandomRoom1_EventScript_25D231:: @ 825D231 setvar VAR_0x8004, 21 setvar VAR_0x8005, 0 special sub_81A703C - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage closemessage releaseall - setvar VAR_0x8004, 7 + setvar VAR_0x8004, SPECIAL_BATTLE_PIKE_SINGLE setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate switch VAR_RESULT case 1, BattleFrontier_BattlePikeRandomRoom1_EventScript_25D285 @@ -282,7 +282,7 @@ BattleFrontier_BattlePikeRandomRoom1_EventScript_25D53E:: @ 825D53E setvar VAR_0x8004, 21 setvar VAR_0x8005, 0 special sub_81A703C - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 closemessage delay 16 applymovement 255, BattleFrontier_BattlePikeRandomRoom1_Movement_25D7BD @@ -290,11 +290,11 @@ BattleFrontier_BattlePikeRandomRoom1_EventScript_25D53E:: @ 825D53E setvar VAR_0x8004, 21 setvar VAR_0x8005, 1 special sub_81A703C - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 closemessage - setvar VAR_0x8004, 9 + setvar VAR_0x8004, SPECIAL_BATTLE_PIKE_DOUBLE setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate switch VAR_RESULT case 1, BattleFrontier_BattlePikeRandomRoom1_EventScript_25D5DC @@ -433,9 +433,9 @@ BattleFrontier_BattlePikeRandomRoom1_EventScript_25D77B:: @ 825D77B closemessage applymovement 255, BattleFrontier_BattlePikeRandomRoom1_Movement_25D7DC waitmovement 0 - setvar VAR_0x8004, 7 + setvar VAR_0x8004, SPECIAL_BATTLE_PIKE_SINGLE setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate return @@ -590,7 +590,7 @@ BattleFrontier_BattlePikeRandomRoom1_EventScript_25D81B:: @ 825D81B faceplayer setvar VAR_0x8004, 14 special sub_81A703C - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage closemessage release diff --git a/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc b/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc index 886b3fe01..5169a6971 100644 --- a/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc @@ -228,9 +228,9 @@ BattleFrontier_BattlePyramidTop_EventScript_2553B3:: @ 82553B3 BattleFrontier_BattlePyramidTop_EventScript_2553ED:: @ 82553ED closemessage - setvar VAR_0x8004, 10 + setvar VAR_0x8004, SPECIAL_BATTLE_PYRAMID setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate return diff --git a/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc index d687f83dd..69a78215d 100644 --- a/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc @@ -45,7 +45,7 @@ BattleFrontier_BattleTowerBattleRoom_EventScript_241BC3:: @ 8241BC3 setvar VAR_0x8004, 7 setvar VAR_0x8005, 0 special sub_8161F74 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage call BattleFrontier_BattleTowerBattleRoom_EventScript_24210E switch VAR_RESULT @@ -362,9 +362,9 @@ BattleFrontier_BattleTowerBattleRoom_EventScript_24210E:: @ 824210E setvar VAR_0x8006, 0 special sub_81A1780 special HealPlayerParty - setvar VAR_0x8004, 0 + setvar VAR_0x8004, SPECIAL_BATTLE_TOWER setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate copyvar VAR_0x8004, VAR_FRONTIER_BATTLE_MODE compare VAR_0x8004, 3 diff --git a/data/maps/BattleFrontier_BattleTowerBattleRoom2/scripts.inc b/data/maps/BattleFrontier_BattleTowerBattleRoom2/scripts.inc index 2db7e5cdf..9c4cd6bc9 100644 --- a/data/maps/BattleFrontier_BattleTowerBattleRoom2/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerBattleRoom2/scripts.inc @@ -78,14 +78,14 @@ BattleFrontier_BattleTowerBattleRoom2_EventScript_248FB4:: @ 8248FB4 delay 15 applymovement 1, BattleFrontier_BattleTowerBattleRoom2_Movement_249545 waitmovement 0 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage setvar VAR_0x8004, 7 setvar VAR_0x8005, 1 special sub_8161F74 applymovement 4, BattleFrontier_BattleTowerBattleRoom2_Movement_249545 waitmovement 0 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage goto BattleFrontier_BattleTowerBattleRoom2_EventScript_249069 diff --git a/data/maps/FallarborTown_BattleTentBattleRoom/scripts.inc b/data/maps/FallarborTown_BattleTentBattleRoom/scripts.inc index e373ff5ad..6103a1aaa 100644 --- a/data/maps/FallarborTown_BattleTentBattleRoom/scripts.inc +++ b/data/maps/FallarborTown_BattleTentBattleRoom/scripts.inc @@ -54,7 +54,7 @@ FallarborTown_BattleTentBattleRoom_EventScript_20090F:: @ 820090F msgbox FallarborTown_BattleTentBattleRoom_Text_257C93, 4 setvar VAR_0x8004, 4 special sub_81B99B4 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage call FallarborTown_BattleTentBattleRoom_EventScript_257B6C switch VAR_RESULT diff --git a/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc b/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc index b09babbdd..e89406f31 100644 --- a/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc +++ b/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc @@ -264,9 +264,9 @@ MossdeepCity_SpaceCenter_2F_EventScript_224032:: @ 8224032 setvar VAR_0x8004, 2 setvar VAR_0x8005, 4 special sub_81A1780 - setvar VAR_0x8004, 8 + setvar VAR_0x8004, SPECIAL_BATTLE_STEVEN setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate setvar VAR_0x8004, 6 special sub_81A1780 diff --git a/data/maps/SlateportCity_BattleTentBattleRoom/scripts.inc b/data/maps/SlateportCity_BattleTentBattleRoom/scripts.inc index 150cc425b..7321f7662 100644 --- a/data/maps/SlateportCity_BattleTentBattleRoom/scripts.inc +++ b/data/maps/SlateportCity_BattleTentBattleRoom/scripts.inc @@ -51,13 +51,13 @@ SlateportCity_BattleTentBattleRoom_EventScript_2099BE:: @ 82099BE setvar VAR_0x8004, 4 special sub_81B99B4 lockall - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage closemessage special HealPlayerParty - setvar VAR_0x8004, 6 + setvar VAR_0x8004, SPECIAL_BATTLE_FACTORY setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate switch VAR_RESULT case 1, SlateportCity_BattleTentBattleRoom_EventScript_209A39 diff --git a/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc b/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc index 6eea58f9f..1ecf08399 100644 --- a/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc +++ b/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc @@ -16,11 +16,11 @@ SootopolisCity_MysteryEventsHouse_B1F_EventScript_227E68:: @ 8227E68 applymovement 255, SootopolisCity_MysteryEventsHouse_B1F_Movement_227EF3 waitmovement 0 special sub_8165360 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 closemessage - setvar VAR_0x8004, 2 + setvar VAR_0x8004, SPECIAL_BATTLE_EREADER setvar VAR_0x8005, 0 - special sub_8163AC4 + special DoSpecialTrainerBattle waitstate compare VAR_RESULT, 3 call_if 1, SootopolisCity_MysteryEventsHouse_B1F_EventScript_227ECF diff --git a/data/maps/VerdanturfTown_BattleTentBattleRoom/scripts.inc b/data/maps/VerdanturfTown_BattleTentBattleRoom/scripts.inc index b7f687cdf..7d30cf2c0 100644 --- a/data/maps/VerdanturfTown_BattleTentBattleRoom/scripts.inc +++ b/data/maps/VerdanturfTown_BattleTentBattleRoom/scripts.inc @@ -48,7 +48,7 @@ VerdanturfTown_BattleTentBattleRoom_EventScript_20236F:: @ 820236F waitmovement 0 setvar VAR_0x8004, 4 special sub_81B99B4 - msgbox 0x2021fc4, 4 + msgbox gStringVar4, 4 waitmessage call VerdanturfTown_BattleTentBattleRoom_EventScript_24FDF7 switch VAR_RESULT diff --git a/data/specials.inc b/data/specials.inc index 3c5318309..09f74cb51 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -247,7 +247,7 @@ gSpecials:: @ 81DBA64 def_special CallBattleDomeFunction def_special sub_8195960 def_special sub_8165360 - def_special sub_8163AC4 + def_special DoSpecialTrainerBattle def_special sub_81A5238 def_special sub_81A5E74 def_special sub_81A703C diff --git a/include/battle.h b/include/battle.h index 87aa2a45b..f34364ea6 100644 --- a/include/battle.h +++ b/include/battle.h @@ -561,6 +561,7 @@ struct BattleScripting u8 field_23; u8 windowsType; // 0 - normal, 1 - battle arena u8 multiplayerId; + u8 specialTrainerBattleType; }; // rom_80A5C6C diff --git a/include/battle_tower.h b/include/battle_tower.h index f79fbb8c4..a47007122 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -58,7 +58,7 @@ bool32 sub_816587C(union BattleTowerRecord *, union BattleTowerRecord *); void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *); void PutNewBattleTowerRecord(union BattleTowerRecord *); void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId); -void ConvertBattleFrontierTrainerSpeechToString(const u16 *words); +void FrontierSpeechToString(const u16 *words); void GetFrontierTrainerName(u8 *dest, u16 trainerIdx); void GetEreaderTrainerName(u8 *dest); diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index 1cd750a3d..ca110aeb7 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -21,4 +21,17 @@ #define FRONTIER_MODE_MULTIS 2 #define FRONTIER_MODE_LINK_MULTIS 3 +// Special trainer battles. +#define SPECIAL_BATTLE_TOWER 0 +#define SPECIAL_BATTLE_SECRET_BASE 1 +#define SPECIAL_BATTLE_EREADER 2 +#define SPECIAL_BATTLE_DOME 3 +#define SPECIAL_BATTLE_PALACE 4 +#define SPECIAL_BATTLE_ARENA 5 +#define SPECIAL_BATTLE_FACTORY 6 +#define SPECIAL_BATTLE_PIKE_SINGLE 7 +#define SPECIAL_BATTLE_STEVEN 8 +#define SPECIAL_BATTLE_PIKE_DOUBLE 9 +#define SPECIAL_BATTLE_PYRAMID 10 + #endif // GUARD_CONSTANTS_BATTLE_FRONTIER_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index bd9d8e67d..dc07fda6e 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -11,9 +11,9 @@ #define sB_ANIM_ARG2 gBattleScripting + 0x11 #define sTRIPLE_KICK_POWER gBattleScripting + 0x12 #define sMOVEEND_STATE gBattleScripting + 0x14 -#define sBANK_WITH_ABILITY gBattleScripting + 0x15 +#define sBATTLER_WITH_ABILITY gBattleScripting + 0x15 #define sMULTIHIT_EFFECT gBattleScripting + 0x16 -#define sBANK gBattleScripting + 0x17 +#define sBATTLER gBattleScripting + 0x17 #define sB_ANIM_TURN gBattleScripting + 0x18 #define sB_ANIM_TARGETS_HIT gBattleScripting + 0x19 #define sSTATCHANGER gBattleScripting + 0x1A @@ -26,8 +26,9 @@ #define sRESHOW_MAIN_STATE gBattleScripting + 0x21 #define sRESHOW_HELPER_STATE gBattleScripting + 0x22 #define sFIELD_23 gBattleScripting + 0x23 -#define sFIELD_24 gBattleScripting + 0x24 +#define sWINDOWS_TYPE gBattleScripting + 0x24 #define sMULTIPLAYER_ID gBattleScripting + 0x25 +#define sSPECIAL_TRAINER_BATTLE_TYPE gBattleScripting + 0x26 #define cEFFECT_CHOOSER gBattleCommunication + 3 #define cMULTISTRING_CHOOSER gBattleCommunication + 5 diff --git a/include/global.h b/include/global.h index ef5a944d0..6840d5fe2 100644 --- a/include/global.h +++ b/include/global.h @@ -331,7 +331,8 @@ struct EmeraldBattleTowerRecord /*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1]; /*0x0C*/ u8 trainerId[4]; /*0x10*/ u16 greeting[6]; - /*0x1C*/ u8 filler_1c[0x18]; + /*0x1C*/ u16 unk1C[6]; + /*0x28*/ u16 unk28[6]; /*0x34*/ struct UnknownPokemonStruct party[4]; /*0xE4*/ u8 language; /*0xE8*/ u32 checksum; @@ -378,8 +379,8 @@ struct BattleDomeTrainer struct BattleFrontier { - /*0x64C*/ struct EmeraldBattleTowerRecord battleTower; - /*0x738*/ struct EmeraldBattleTowerRecord records[5]; // From record mixing. + /*0x64C*/ struct EmeraldBattleTowerRecord towerPlayer; + /*0x738*/ struct EmeraldBattleTowerRecord towerRecords[5]; // From record mixing. /*0xBD4*/ u16 field_BD4; /*0xBD6*/ u16 field_BD6; /*0xBD8*/ u8 field_BD8[11]; @@ -397,7 +398,10 @@ struct BattleFrontier /*0xCAA*/ u16 field_CAA[3]; /*0xCB0*/ u16 field_CB0; /*0xCB2*/ u16 curChallengeBattleNum; // In case of battle pyramid, the floor. - /*0xCB4*/ u16 battledTrainerIds[20]; + /*0xCB4*/ u16 battledTrainerIds[17]; + u16 field_CD6; + u16 field_CD8; + u16 field_CDA; /*0xCDC*/ u32 field_CDC; /*0xCE0*/ u16 field_CE0[4][2]; /*0xCF0*/ u16 field_CF0[2]; @@ -457,10 +461,7 @@ struct BattleFrontier /*0xEB8*/ u16 frontierBattlePoints; /*0xEBA*/ u8 field_EBA; /*0xEBB*/ u8 field_EBB; - /*0xEBC*/ u8 field_EBC; - /*0xEBD*/ u8 field_EBD; - /*0xEBE*/ u8 field_EBE; - /*0xEBF*/ u8 field_EBF; + /*0xEBC*/ u32 battlesCount; /*0xEC0*/ u16 field_EC0[16]; /*0xEE0*/ u8 field_EE0; /*0xEE1*/ u8 field_EE1[2][PLAYER_NAME_LENGTH + 1]; diff --git a/src/apprentice.c b/src/apprentice.c index 2a79652ff..d45cff430 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -1970,7 +1970,7 @@ static void sub_81A0FFC(void) StringCopy(stringDst, gText_OpenLevel); break; case APPRENTICE_BUFF_EASY_CHAT: - ConvertBattleFrontierTrainerSpeechToString(gSaveBlock2Ptr->apprentices[0].easyChatWords); + FrontierSpeechToString(gSaveBlock2Ptr->apprentices[0].easyChatWords); StringCopy(stringDst, gStringVar4); break; case APPRENTICE_BUFF_SPECIES4: diff --git a/src/battle_frontier_1.c b/src/battle_frontier_1.c index 7c93f4cdc..9ec9f8520 100644 --- a/src/battle_frontier_1.c +++ b/src/battle_frontier_1.c @@ -96,7 +96,7 @@ void sub_8195C20(void) void sub_8195C50(void) { if (gTrainerBattleOpponent_A < 300) - ConvertBattleFrontierTrainerSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); + FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); } /* diff --git a/src/battle_tent.c b/src/battle_tent.c index 4edb0b619..4ad045043 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -126,7 +126,7 @@ static void sub_81B9A60(void) static void sub_81B9A90(void) { if (gTrainerBattleOpponent_A < 300) - ConvertBattleFrontierTrainerSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); + FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); } static void sub_81B9ABC(void) diff --git a/src/battle_tower.c b/src/battle_tower.c index b9451aecd..75253792e 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -6,12 +6,18 @@ #include "overworld.h" #include "random.h" #include "text.h" +#include "main.h" #include "international_string_util.h" #include "battle.h" #include "battle_frontier_1.h" #include "battle_frontier_2.h" #include "recorded_battle.h" #include "easy_chat.h" +#include "gym_leader_rematch.h" +#include "battle_transition.h" +#include "trainer_see.h" +#include "new_game.h" +#include "string_util.h" #include "constants/battle_frontier.h" #include "constants/trainers.h" #include "constants/event_objects.h" @@ -39,9 +45,11 @@ extern const u16 gBattleFrontierHeldItems[]; // This file's functions. void sub_8164ED8(void); -void sub_8163E90(void); +void SaveCurrentWinStreak(void); void sub_8165B20(void); void sub_8165E18(void); +void sub_816537C(void); +void sub_8164FB8(struct EmeraldBattleTowerRecord *record); u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode); void sub_816534C(void *); u16 sub_8162548(u8, u8); @@ -50,6 +58,7 @@ void sub_8165EA4(u16 trainerId, u8 firstMonId, u8 monCount); void sub_81635D4(u16 trainerId, u8 firstMonId); void sub_816379C(u16 trainerId, u8 firstMonId); u8 GetFrontierTrainerFixedIvs(u16 trainerId); +void sub_8165404(u16 trainerId); // code void sub_8161F74(void) @@ -129,7 +138,7 @@ void sub_81621C0(void) gSaveBlock2Ptr->frontier.field_D04++; gSaveBlock2Ptr->frontier.curChallengeBattleNum++; - sub_8163E90(); + SaveCurrentWinStreak(); gSpecialVar_Result = gSaveBlock2Ptr->frontier.curChallengeBattleNum; } @@ -148,7 +157,7 @@ bool8 ChooseSpecialBattleTowerTrainer(void) winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode); for (i = 0; i < 5; i++) { - u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.records[i]); + u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]); u32 recordHasData = 0; u32 checksum = 0; for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself. @@ -159,16 +168,16 @@ bool8 ChooseSpecialBattleTowerTrainer(void) validMons = 0; for (j = 0; j < 4; j++) { - if (gSaveBlock2Ptr->frontier.records[i].party[j].species != 0 - && gSaveBlock2Ptr->frontier.records[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode)) + if (gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species != 0 + && gSaveBlock2Ptr->frontier.towerRecords[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode)) validMons++; } if (validMons >= gUnknown_085DF9F6[battleMode] - && gSaveBlock2Ptr->frontier.records[i].winStreak == winStreak - && gSaveBlock2Ptr->frontier.records[i].lvlMode == lvlMode + && gSaveBlock2Ptr->frontier.towerRecords[i].winStreak == winStreak + && gSaveBlock2Ptr->frontier.towerRecords[i].lvlMode == lvlMode && recordHasData - && gSaveBlock2Ptr->frontier.records[i].checksum == checksum) + && gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum) { trainerIds[idsCount] = i + BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID; idsCount++; @@ -385,7 +394,7 @@ void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId) } else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) { - facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; } else { @@ -477,7 +486,7 @@ u8 GetBattleFacilityTrainerGfxId(u16 trainerId) } else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) { - facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; } else { @@ -527,7 +536,7 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) k = 0; for (j = 0; j < 4; j++) { - if (gSaveBlock2Ptr->frontier.records[i].trainerId[j] != newRecordEm->trainerId[j]) + if (gSaveBlock2Ptr->frontier.towerRecords[i].trainerId[j] != newRecordEm->trainerId[j]) break; } if (j == 4) @@ -535,7 +544,7 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) for (k = 0; k < PLAYER_NAME_LENGTH; k++) { // BUG: Wrong variable used, 'j' instead of 'k'. - if (gSaveBlock2Ptr->frontier.records[i].name[j] != newRecordEm->name[j]) + if (gSaveBlock2Ptr->frontier.towerRecords[i].name[j] != newRecordEm->name[j]) break; if (newRecordEm->name[j] == EOS) { @@ -550,24 +559,24 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) } if (i < 5) { - gSaveBlock2Ptr->frontier.records[i] = *newRecordEm; + gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecordEm; return; } // Find an empty record slot. for (i = 0; i < 5; i++) { - if (gSaveBlock2Ptr->frontier.records[i].winStreak == 0) + if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak == 0) break; } if (i < 5) { - gSaveBlock2Ptr->frontier.records[i] = *newRecordEm; + gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecordEm; return; } // Find possible slots to replace the record. - slotValues[0] = gSaveBlock2Ptr->frontier.records[0].winStreak; + slotValues[0] = gSaveBlock2Ptr->frontier.towerRecords[0].winStreak; slotIds[0] = 0; slotsCount++; @@ -575,15 +584,15 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) { for (j = 0; j < slotsCount; j++) { - if (gSaveBlock2Ptr->frontier.records[i].winStreak < slotValues[j]) + if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak < slotValues[j]) { j = 0; slotsCount = 1; - slotValues[0] = gSaveBlock2Ptr->frontier.records[i].winStreak; + slotValues[0] = gSaveBlock2Ptr->frontier.towerRecords[i].winStreak; slotIds[0] = i; break; } - else if (gSaveBlock2Ptr->frontier.records[i].winStreak > slotValues[j]) + else if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak > slotValues[j]) { break; } @@ -591,14 +600,14 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) if (j == slotsCount) { - slotValues[slotsCount] = gSaveBlock2Ptr->frontier.records[i].winStreak; + slotValues[slotsCount] = gSaveBlock2Ptr->frontier.towerRecords[i].winStreak; slotIds[slotsCount] = i; slotsCount++; } } i = Random() % slotsCount; - gSaveBlock2Ptr->frontier.records[slotIds[i]] = *newRecordEm; + gSaveBlock2Ptr->frontier.towerRecords[slotIds[i]] = *newRecordEm; } u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) @@ -622,7 +631,7 @@ u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) return gFacilityClassToPicIndex[sub_818649C()]; else - return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; + return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; } else { @@ -662,7 +671,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) } else { - trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; + trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; asm(""); } } @@ -700,7 +709,7 @@ u8 GetFrontierTrainerFacilityClass(u16 trainerId) if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) facilityClass = sub_818649C(); else - facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; } else { @@ -747,7 +756,7 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) } else { - struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID]; + struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID]; TVShowConvertInternationalString(dst, record->name, record->language); return; } @@ -794,7 +803,7 @@ bool8 IsFrontierTrainerFemale(u16 trainerId) } else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) { - facilityClass = gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; } else { @@ -865,10 +874,10 @@ void sub_81630C4(u16 trainerId, u8 firstMonId, u8 monCount) // Record mixed player. for (j = 0, i = firstMonId; i < firstMonId + monCount; j++, i++) { - if (gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].species != 0 - && gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].level <= level) + if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].species != 0 + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].level <= level) { - sub_8068338(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.records[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j], FALSE); + sub_8068338(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j], FALSE); } } return; @@ -1044,11 +1053,11 @@ void sub_81635D4(u16 trainerId, u8 firstMonId) { u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; // Unused variable. u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); - u8 r1 = gSaveBlock2Ptr->frontier.field_CE0[battleMode][0] / 7; + u8 challengeNum = gSaveBlock2Ptr->frontier.field_CE0[battleMode][0] / 7; if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6) - fixedIV = sub_81A6CA8(r1, 0); + fixedIV = sub_81A6CA8(challengeNum, 0); else - fixedIV = sub_81A6CA8(r1, 1); + fixedIV = sub_81A6CA8(challengeNum, 1); } else if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { @@ -1121,7 +1130,7 @@ void sub_816379C(u16 trainerId, u8 firstMonId) } } -void ConvertBattleFrontierTrainerSpeechToString(const u16 *words) +void FrontierSpeechToString(const u16 *words) { ConvertEasyChatWordsToString(gStringVar4, words, 3, 2); if (GetStringWidth(1, gStringVar4, -1) > 204) @@ -1137,3 +1146,486 @@ void ConvertBattleFrontierTrainerSpeechToString(const u16 *words) gStringVar4[i] = CHAR_PROMPT_SCROLL; } } + +void sub_8163914(void) +{ + u16 trainerId; + GetFacilityEnemyMonLevel(); // Pointless function call. + + if (gSpecialVar_0x8005) + trainerId = gTrainerBattleOpponent_B; + else + trainerId = gTrainerBattleOpponent_A; + + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.greeting); + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore); + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + FrontierSpeechToString(gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].greeting); + else + CopyFriendsApprenticeChallengeText(trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID); +} + +static void HandleSpecialTrainerBattleEnd(void) +{ + s32 i; + + sub_81864CC(); + switch (gBattleScripting.specialTrainerBattleType) + { + case SPECIAL_BATTLE_TOWER: + case SPECIAL_BATTLE_DOME: + case SPECIAL_BATTLE_PALACE: + case SPECIAL_BATTLE_ARENA: + case SPECIAL_BATTLE_FACTORY: + case SPECIAL_BATTLE_PIKE_SINGLE: + case SPECIAL_BATTLE_PIKE_DOUBLE: + case SPECIAL_BATTLE_PYRAMID: + if (gSaveBlock2Ptr->frontier.battlesCount < 0xFFFFFF) + { + gSaveBlock2Ptr->frontier.battlesCount++; + if (gSaveBlock2Ptr->frontier.battlesCount % 20 == 0) + UpdateGymLeaderRematch(); + } + else + { + gSaveBlock2Ptr->frontier.battlesCount = 0xFFFFFF; + } + break; + case SPECIAL_BATTLE_SECRET_BASE: + for (i = 0; i < PARTY_SIZE; i++) + { + u16 itemBefore = GetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_HELD_ITEM); + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &itemBefore); + } + break; + case SPECIAL_BATTLE_EREADER: + sub_816537C(); + break; + } + + SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); +} + +static void Task_StartBattleAfterTransition(u8 taskId) +{ + if (IsBattleTransitionDone() == TRUE) + { + gMain.savedCallback = HandleSpecialTrainerBattleEnd; + SetMainCallback2(CB2_InitBattle); + DestroyTask(taskId); + } +} + +extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224157[]; +extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224166[]; + +void DoSpecialTrainerBattle(void) +{ + s32 i; + + gBattleScripting.specialTrainerBattleType = gSpecialVar_0x8004; + switch (gSpecialVar_0x8004) + { + case SPECIAL_BATTLE_TOWER: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER; + switch (VarGet(VAR_FRONTIER_BATTLE_MODE)) + { + case FRONTIER_MODE_SINGLES: + sub_8163048(3); + break; + case FRONTIER_MODE_DOUBLES: + sub_8163048(4); + gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; + break; + case FRONTIER_MODE_MULTIS: + sub_816306C(2); + gPartnerTrainerId = gSaveBlock2Ptr->frontier.field_CD6; + sub_8165404(gPartnerTrainerId); + gBattleTypeFlags |= BATTLE_TYPE_DOUBLE | BATTLE_TYPE_INGAME_PARTNER | BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS; + break; + case FRONTIER_MODE_LINK_MULTIS: + gBattleTypeFlags |= BATTLE_TYPE_DOUBLE | BATTLE_TYPE_LINK | BATTLE_TYPE_MULTI | BATTLE_TYPE_x800000; + sub_816306C(2); + break; + } + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(0)); + break; + case SPECIAL_BATTLE_SECRET_BASE: + for (i = 0; i < PARTY_SIZE; i++) + { + u16 itemBefore = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + SetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_HELD_ITEM, &itemBefore); + } + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(12)); + break; + case SPECIAL_BATTLE_EREADER: + ZeroEnemyPartyMons(); + for (i = 0; i < 3; i++) + sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i]); + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_EREADER_TRAINER; + gTrainerBattleOpponent_A = 0; + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(13)); + break; + case SPECIAL_BATTLE_DOME: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOME; + if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES) + gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; + if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + sub_8163048(2); + CreateTask(Task_StartBattleAfterTransition, 1); + sub_806E694(0); + BattleTransition_StartOnField(sub_80B100C(3)); + break; + case SPECIAL_BATTLE_PALACE: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_PALACE; + if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES) + gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; + if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) + sub_8163048(3); + else + sub_81630A0(3); + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(4)); + break; + case SPECIAL_BATTLE_ARENA: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_ARENA; + if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) + sub_8163048(3); + else + sub_81630A0(3); + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(5)); + break; + case SPECIAL_BATTLE_FACTORY: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_FACTORY; + if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES) + gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; + sub_8163590(); + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(6)); + break; + case SPECIAL_BATTLE_PIKE_SINGLE: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER; + sub_8163048(3); + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(7)); + break; + case SPECIAL_BATTLE_PYRAMID: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_PYRAMID; + sub_8163048(3); + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(10)); + break; + case SPECIAL_BATTLE_PIKE_DOUBLE: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS; + sub_816306C(1); + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(sub_80B100C(7)); + break; + case SPECIAL_BATTLE_STEVEN: + gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER; + sub_8165404(TRAINER_STEVEN_PARTNER); + gApproachingTrainerId = 0; + BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_224157 + 1); + gApproachingTrainerId = 1; + BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_224166 + 1); + gPartnerTrainerId = TRAINER_STEVEN_PARTNER; + CreateTask(Task_StartBattleAfterTransition, 1); + PlayMapChosenOrBattleBGM(0); + BattleTransition_StartOnField(B_TRANSITION_MAGMA); + break; + } +} + +void SaveCurrentWinStreak(void) +{ + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + u16 winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode); + + if (gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] < winStreak) + gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] = winStreak; +} + +void sub_8163EE4(void) +{ + s32 i; + u8 lvlMode, battleMode, class; + struct EmeraldBattleTowerRecord *playerRecord = &gSaveBlock2Ptr->frontier.towerPlayer; + + sub_8164FB8(playerRecord); + lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + if (gSaveBlock2Ptr->playerGender != MALE) + { + class = gTowerFemaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] + + gSaveBlock2Ptr->playerTrainerId[1] + + gSaveBlock2Ptr->playerTrainerId[2] + + gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerFemaleFacilityClasses)]; + } + else + { + class = gTowerMaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] + + gSaveBlock2Ptr->playerTrainerId[1] + + gSaveBlock2Ptr->playerTrainerId[2] + + gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerMaleFacilityClasses)]; + } + playerRecord->lvlMode = lvlMode; + playerRecord->facilityClass = class; + CopyUnalignedWord(playerRecord->trainerId, gSaveBlock2Ptr->playerTrainerId); + StringCopy7(playerRecord->name, gSaveBlock2Ptr->playerName); + playerRecord->winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode); + + for (i = 0; i < 6; i++) + { + playerRecord->greeting[i] = gSaveBlock1Ptr->unk2BBC[i]; + playerRecord->unk1C[i] = gSaveBlock1Ptr->unk2BC8[i]; + playerRecord->unk28[i] = gSaveBlock1Ptr->unk2BD4[i]; + } + + for (i = 0; i < 4; i++) + { + if (gSaveBlock2Ptr->frontier.field_CAA[i] != 0) + sub_80686FC(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], &playerRecord->party[i]); + } + + playerRecord->language = gGameLanguage; + CalcEmeraldBattleTowerChecksum(&gSaveBlock2Ptr->frontier.towerPlayer); + SaveCurrentWinStreak(); +} + +void SaveBattleTowerProgress(void) +{ + u16 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] / 7); + + if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0)) + sub_8163EE4(); + + gSaveBlock2Ptr->frontier.field_CA8 =gSpecialVar_0x8005; + VarSet(VAR_TEMP_0, 0); + gSaveBlock2Ptr->frontier.field_CA9_a = 1; + sub_81A4C30(); +} + +void nullsub_61(void) +{ + +} + +void nullsub_116(void) +{ + +} + +void sub_81640E0(u16 trainerId) +{ + s32 i, count; + u32 validSpecies[3]; + u16 species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); + u16 species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); + + count = 0; + for (i = 0; i < 3; i++) + { + u16 apprenticeSpecies = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].monData[i].species; + if (apprenticeSpecies != species1 && apprenticeSpecies != species2) + { + validSpecies[count] = i; + count++; + } + } + + gUnknown_03006298[0] = validSpecies[Random() % count]; + do + { + gUnknown_03006298[1] = validSpecies[Random() % count]; + } while (gUnknown_03006298[0] == gUnknown_03006298[1]); +} + +void sub_8164188(u16 trainerId) +{ + s32 i, count; + u32 validSpecies[3]; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u16 species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); + u16 species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); + + count = 0; + for (i = 0; i < 4; i++) + { + if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].species != species1 + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].species != species2 + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].level <= GetFrontierEnemyMonLevel(lvlMode) + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].species != 0) + { + validSpecies[count] = i; + count++; + } + } + + gUnknown_03006298[2] = validSpecies[Random() % count]; + do + { + gUnknown_03006298[3] = validSpecies[Random() % count]; + } while (gUnknown_03006298[2] == gUnknown_03006298[3]); +} + +void sub_81642A0(void) +{ + s32 i, j, k; + u32 spArray[5]; + s32 r10; + u16 trainerId; + u16 monPoolId; + u32 lvlMode, battleMode; + s32 challengeNum; + u32 species1, species2; + u32 level; + struct EventObjectTemplate *eventObjTemplates; + + eventObjTemplates = gSaveBlock1Ptr->eventObjectTemplates; + lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + challengeNum = gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] / 7; + species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); + species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); + level = GetFacilityEnemyMonLevel(); + + for (j = 0; j < 6; j++) + { + do + { + trainerId = sub_8162548(challengeNum, 0); + for (i = 0; i < j; i++) + { + if (gSaveBlock2Ptr->frontier.battledTrainerIds[i] == trainerId) + break; + if (gFacilityTrainers[gSaveBlock2Ptr->frontier.battledTrainerIds[i]].facilityClass == gFacilityTrainers[trainerId].facilityClass) + break; + } + } while (i != j); + gSaveBlock2Ptr->frontier.battledTrainerIds[j] = trainerId; + } + + r10 = 8; + for (i = 0; i < 6; i++) + { + trainerId = gSaveBlock2Ptr->frontier.battledTrainerIds[i]; + eventObjTemplates[i + 1].graphicsId = GetBattleFacilityTrainerGfxId(trainerId); + for (j = 0; j < 2; j++) + { + while (1) + { + monPoolId = RandomizeFacilityTrainerMonId(trainerId); + if (j % 2 != 0 && gFacilityTrainerMons[gSaveBlock2Ptr->frontier.battledTrainerIds[r10 - 1]].itemTableId == gFacilityTrainerMons[monPoolId].itemTableId) + continue; + + for (k = 8; k < r10; k++) + { + if (gFacilityTrainerMons[gSaveBlock2Ptr->frontier.battledTrainerIds[k]].species == gFacilityTrainerMons[monPoolId].species) + break; + if (species1 == gFacilityTrainerMons[monPoolId].species) + break; + if (species2 == gFacilityTrainerMons[monPoolId].species) + break; + } + if (k == r10) + break; + } + + gSaveBlock2Ptr->frontier.battledTrainerIds[r10] = monPoolId; + r10++; + } + } + + r10 = 0; + sub_8165B20(); + for (i = 0; i < 4; i++) + { + if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0 + && gUnknown_085DF9EC[gSaveBlock2Ptr->apprentices[i].field_1] / 7 <= challengeNum + && gSaveBlock2Ptr->apprentices[i].lvlMode - 1 == lvlMode) + { + k = 0; + for (j = 0; j < 3; j++) + { + if (species1 != gSaveBlock2Ptr->apprentices[i].monData[j].species + && species2 != gSaveBlock2Ptr->apprentices[i].monData[j].species) + { + k++; + } + } + if (k > 2) + { + spArray[r10] = i + BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID; + r10++; + } + } + } + if (r10 != 0) + { + gSaveBlock2Ptr->frontier.battledTrainerIds[6] = spArray[Random() % r10]; + eventObjTemplates[7].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.battledTrainerIds[6]); + FlagClear(FLAG_HIDE_BATTLE_TOWER_MULTI_BATTLE_PARTNER_ALT_1); + sub_81640E0(gSaveBlock2Ptr->frontier.battledTrainerIds[6]); + } + + r10 = 0; + for (i = 0; i < 5; i++) + { + u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]); + u32 recordHasData = 0; + u32 checksum = 0; + for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself. + { + recordHasData |= record[j]; + checksum += record[j]; + } + + if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak / 7 <= challengeNum + && gSaveBlock2Ptr->frontier.towerRecords[i].lvlMode == lvlMode + && recordHasData + && gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum) + { + k = 0; + for (j = 0; j < 4; j++) + { + if (species1 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species + && species2 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species + && gSaveBlock2Ptr->frontier.towerRecords[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode) + && gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species != 0) + { + k++; + } + } + if (k > 1) + { + spArray[r10] = i + BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID; + r10++; + } + } + } + if (r10 != 0) + { + gSaveBlock2Ptr->frontier.battledTrainerIds[7] = spArray[Random() % r10]; + eventObjTemplates[8].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.battledTrainerIds[7]); + FlagClear(FLAG_HIDE_BATTLE_TOWER_MULTI_BATTLE_PARTNER_ALT_2); + sub_8164188(gSaveBlock2Ptr->frontier.battledTrainerIds[7]); + } +} diff --git a/src/record_mixing.c b/src/record_mixing.c index 4fb4a256e..c9fe3fd47 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -197,10 +197,10 @@ static void SetSrcLookupPointers(void) sOldManSave = &gSaveBlock1Ptr->oldMan; sEasyChatPairsSave = gSaveBlock1Ptr->easyChatPairs; gUnknown_03001148 = &gUnknown_02039F9C; - sBattleTowerSave = &gSaveBlock2Ptr->frontier.battleTower; + sBattleTowerSave = &gSaveBlock2Ptr->frontier.towerPlayer; sLilycoveLadySave = &gSaveBlock1Ptr->lilycoveLady; gUnknown_03001154 = gSaveBlock2Ptr->apprentices; - sBattleTowerSave_Duplicate = &gSaveBlock2Ptr->frontier.battleTower; + sBattleTowerSave_Duplicate = &gSaveBlock2Ptr->frontier.towerPlayer; } static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest) diff --git a/src/secret_base.c b/src/secret_base.c index a684f3982..87d44fb17 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -40,6 +40,7 @@ #include "tv.h" #include "secret_base.h" #include "constants/map_types.h" +#include "constants/trainers.h" extern void mapldr_default(void); @@ -1143,7 +1144,7 @@ const u8 *GetSecretBaseTrainerLoseText(void) void sub_80EA2E4(void) { sub_813BADC(TRUE); - gTrainerBattleOpponent_A = 0x400; + gTrainerBattleOpponent_A = TRAINER_SECRET_BASE; gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_SECRET_BASE; } From b330bdba51b86959e702e904c4a5d8039e6395c7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 22 Oct 2018 19:22:57 +0200 Subject: [PATCH 4/8] More and more battle tower --- asm/battle_tower.s | 2227 +---------------- asm/rom_8011DC0.s | 2 +- data/battle_tower.s | 6 +- .../scripts.inc | 2 +- data/specials.inc | 2 +- include/battle_tower.h | 11 +- include/global.h | 15 +- src/battle_setup.c | 11 +- src/battle_tower.c | 853 ++++++- src/record_mixing.c | 21 +- 10 files changed, 821 insertions(+), 2329 deletions(-) diff --git a/asm/battle_tower.s b/asm/battle_tower.s index b8f138e7b..46d10acd1 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -5,2227 +5,6 @@ .text - thumb_func_start sub_81646BC -sub_81646BC: @ 81646BC - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - lsls r0, 16 - lsrs r5, r0, 16 - lsls r1, 16 - lsrs r4, r1, 16 - movs r0, 0 - mov r9, r0 - mov r10, r0 - bl GetFacilityEnemyMonLevel - movs r0, 0xFA - lsls r0, 1 - cmp r5, r0 - beq _081647CE - subs r0, 0xC9 - cmp r5, r0 - bhi _081646FC - ldr r0, =gFacilityTrainerMons - ldr r1, [r0] - lsls r0, r4, 4 - adds r0, r1 - ldrh r1, [r0, 0x2] - mov r9, r1 - ldrh r0, [r0] - mov r10, r0 - b _081647CE - .pool -_081646FC: - ldr r0, =0x0000018f - cmp r5, r0 - bhi _08164750 - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - ldr r1, =gUnknown_03006298 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - adds r0, 0x1 - lsls r0, 1 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x2C - muls r1, r0 - ldr r0, =0xfffffed4 - adds r2, r5, r0 - movs r0, 0xEC - muls r0, r2 - adds r1, r0 - adds r3, r1 - movs r1, 0xEE - lsls r1, 3 - adds r0, r3, r1 - ldrh r0, [r0] - mov r9, r0 - ldr r2, =0x0000076c - adds r3, r2 - ldrh r3, [r3] - mov r10, r3 - b _081647CE - .pool -_08164750: - ldr r4, =gSaveBlock2Ptr - ldr r3, [r4] - ldr r1, =gUnknown_03006298 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - subs r0, 0x1 - lsls r0, 1 - adds r0, r1 - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - ldr r2, =0xfffffe70 - adds r1, r5, r2 - lsls r2, r1, 4 - adds r2, r1 - lsls r2, 2 - adds r0, r2 - adds r3, r0 - adds r0, r3, 0 - adds r0, 0xE2 - ldrh r0, [r0] - mov r9, r0 - adds r3, 0xE0 - ldrh r3, [r3] - mov r10, r3 - movs r3, 0 - ldr r7, =gStringVar3 - mov r8, r7 - adds r0, r4, 0 - mov r12, r0 - adds r4, r2, 0 - movs r6, 0x8A - lsls r6, 1 -_08164794: - mov r1, r8 - adds r2, r3, r1 - mov r1, r12 - ldr r0, [r1] - adds r1, r3, r4 - adds r0, r6 - adds r0, r1 - ldrb r0, [r0] - strb r0, [r2] - adds r3, 0x1 - cmp r3, 0x6 - ble _08164794 - adds r1, r3, r7 - movs r0, 0xFF - strb r0, [r1] - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldr r0, =0xfffffe70 - adds r1, r5, r0 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, r0 - ldr r1, =0x0000011b - adds r0, r2, r1 - ldrb r1, [r0] - adds r0, r7, 0 - bl ConvertInternationalString -_081647CE: - ldr r0, =gStringVar1 - movs r1, 0xD - mov r2, r9 - muls r2, r1 - adds r1, r2, 0 - ldr r2, =gMoveNames - adds r1, r2 - bl StringCopy - ldr r0, =gStringVar2 - movs r1, 0xB - mov r2, r10 - muls r2, r1 - adds r1, r2, 0 - ldr r2, =gSpeciesNames - adds r1, r2 - bl StringCopy - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81646BC - - thumb_func_start sub_8164828 -sub_8164828: @ 8164828 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - bl GetFacilityEnemyMonLevel - bl sub_81A39C4 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - ldr r0, =gSpecialVar_LastTalked - ldrh r0, [r0] - subs r5, r0, 0x2 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - lsls r1, r5, 1 - ldr r2, =0x00000cb4 - adds r0, r2 - adds r0, r1 - ldrh r7, [r0] - movs r3, 0 - str r3, [sp] - ldr r4, =gUnknown_085DD500 - lsls r6, r7, 16 - b _08164884 - .pool -_0816487C: - adds r4, 0x8 - ldr r0, [sp] - adds r0, 0x1 - str r0, [sp] -_08164884: - ldr r1, [sp] - cmp r1, 0x31 - bhi _0816489A - lsrs r0, r6, 16 - bl GetFrontierTrainerFacilityClass - lsls r0, 24 - lsrs r0, 24 - ldr r1, [r4] - cmp r1, r0 - bne _0816487C -_0816489A: - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0x4 - bls _081648A4 - b _08164AC2 -_081648A4: - lsls r0, 2 - ldr r1, =_081648B8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081648B8: - .4byte _081648CC - .4byte _08164984 - .4byte _0816499C - .4byte _081649BC - .4byte _08164AC2 -_081648CC: - movs r0, 0xFA - lsls r0, 1 - cmp r7, r0 - bne _081648D6 - b _08164B54 -_081648D6: - subs r0, 0xC9 - cmp r7, r0 - ble _081648E2 - ldr r0, =0x0000018f - cmp r7, r0 - bgt _081648F4 -_081648E2: - ldr r0, =gStringVar1 - adds r1, r7, 0 - bl GetFrontierTrainerName - b _08164AC2 - .pool -_081648F4: - movs r3, 0 - lsls r2, r7, 16 - mov r10, r2 - ldr r6, =gStringVar1 - mov r9, r6 - ldr r4, =gSaveBlock2Ptr - mov r8, r4 - ldr r5, =0xfffffe70 - adds r1, r7, r5 - lsls r0, r1, 4 - adds r0, r1 - lsls r4, r0, 2 - movs r5, 0x8A - lsls r5, 1 -_08164910: - mov r0, r9 - adds r2, r3, r0 - mov r1, r8 - ldr r0, [r1] - adds r1, r3, r4 - adds r0, r5 - adds r0, r1 - ldrb r0, [r0] - strb r0, [r2] - adds r3, 0x1 - cmp r3, 0x6 - ble _08164910 - adds r1, r3, r6 - movs r0, 0xFF - strb r0, [r1] - ldr r2, =gSaveBlock2Ptr - ldr r1, [r2] - ldr r3, =0xfffffe70 - adds r0, r7, r3 - lsls r4, r0, 4 - adds r4, r0 - lsls r4, 2 - adds r1, r4 - ldr r5, =0x0000011b - adds r0, r1, r5 - ldrb r1, [r0] - adds r0, r6, 0 - bl ConvertInternationalString - ldr r0, =gStringVar2 - ldr r2, =gSaveBlock2Ptr - ldr r1, [r2] - adds r1, r4 - adds r1, 0xDE - ldrb r1, [r1] - movs r2, 0 - movs r3, 0x3 - bl ConvertIntToDecimalStringN - ldr r0, =gStringVar3 - mov r3, r10 - lsrs r1, r3, 16 - bl GetFrontierTrainerName - b _08164AC2 - .pool -_08164984: - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - lsls r0, r5, 2 - adds r1, r0 - ldr r4, =0x00000cc4 - adds r1, r4 - b _081649A8 - .pool -_0816499C: - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - lsls r0, r5, 2 - adds r1, r0 - ldr r5, =0x00000cc6 - adds r1, r5 -_081649A8: - adds r0, r7, 0 - ldrh r1, [r1] - bl sub_81646BC - b _08164AC2 - .pool -_081649BC: - ldr r0, =gPartnerTrainerId - strh r7, [r0] - ldr r0, =0x0000012b - cmp r7, r0 - bgt _08164A08 - ldr r0, =gSaveBlock2Ptr - ldr r4, [r0] - lsls r1, r5, 1 - adds r0, r1, 0 - adds r0, 0x8 - lsls r0, 1 - ldr r3, =0x00000cb4 - adds r2, r4, r3 - adds r0, r2, r0 - ldrh r3, [r0] - ldr r5, =0x00000cd8 - adds r0, r4, r5 - strh r3, [r0] - adds r1, 0x9 - lsls r1, 1 - adds r2, r1 - ldrh r0, [r2] - ldr r1, =0x00000cda - adds r4, r1 - strh r0, [r4] - b _08164A46 - .pool -_08164A08: - ldr r0, =0x0000018f - cmp r7, r0 - bgt _08164A30 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r3, =gUnknown_03006298 - ldrh r2, [r3, 0x4] - ldr r4, =0x00000cd8 - adds r0, r1, r4 - strh r2, [r0] - ldrh r0, [r3, 0x6] - b _08164A40 - .pool -_08164A30: - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r3, =gUnknown_03006298 - ldrh r2, [r3] - ldr r4, =0x00000cd8 - adds r0, r1, r4 - strh r2, [r0] - ldrh r0, [r3, 0x2] -_08164A40: - ldr r5, =0x00000cda - adds r1, r5 - strh r0, [r1] -_08164A46: - movs r5, 0 - mov r0, r8 - lsls r0, 24 - str r0, [sp, 0x4] -_08164A4E: - lsls r1, r5, 1 - mov r10, r1 - adds r2, r5, 0x1 - mov r9, r2 - lsrs r0, r5, 31 - adds r0, r5, r0 - asrs r0, 1 - lsls r0, 24 - mov r8, r0 -_08164A60: - ldr r3, [sp, 0x4] - lsrs r0, r3, 24 - mov r4, r8 - lsrs r1, r4, 24 - bl sub_8162548 - lsls r0, 16 - lsrs r3, r0, 16 - ldr r0, =gPartnerTrainerId - ldrh r0, [r0] - cmp r0, r3 - beq _08164A60 - movs r2, 0 - cmp r2, r5 - bge _08164AA2 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r4, =0x00000cb4 - adds r0, r4 - ldrh r0, [r0] - cmp r0, r3 - beq _08164AA2 - adds r6, r1, 0 -_08164A8E: - adds r2, 0x1 - cmp r2, r5 - bge _08164AA2 - ldr r0, [r6] - lsls r1, r2, 1 - adds r0, r4 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r3 - bne _08164A8E -_08164AA2: - cmp r2, r5 - bne _08164A60 - ldr r5, =gSaveBlock2Ptr - ldr r0, [r5] - ldr r1, =0x00000cb4 - adds r0, r1 - add r0, r10 - strh r3, [r0] - mov r5, r9 - cmp r5, 0xD - ble _08164A4E - ldr r2, =gSaveBlock2Ptr - ldr r0, [r2] - ldr r3, =0x00000cd6 - adds r0, r3 - strh r7, [r0] -_08164AC2: - movs r0, 0xFA - lsls r0, 1 - cmp r7, r0 - beq _08164B54 - subs r0, 0xC9 - cmp r7, r0 - bgt _08164AF8 - ldr r0, =gUnknown_085DD500 - ldr r4, [sp] - lsls r1, r4, 3 - b _08164B04 - .pool -_08164AF8: - ldr r0, =0x0000018f - cmp r7, r0 - bgt _08164B28 - ldr r0, =gUnknown_085DD500 - ldr r5, [sp] - lsls r1, r5, 3 -_08164B04: - adds r0, 0x4 - adds r1, r0 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - ldr r1, [r1] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl ShowFieldMessage - b _08164B54 - .pool -_08164B28: - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0xfffffe70 - adds r2, r7, r0 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r1, r0 - adds r1, 0xDC - ldrb r0, [r1] - lsls r0, 27 - ldr r1, =gUnknown_085DD690 - lsrs r0, 25 - adds r0, r1 - ldr r1, =gSpecialVar_0x8005 - ldrh r1, [r1] - ldr r0, [r0] - lsls r1, 2 - adds r1, r0 - ldr r0, [r1] - bl ShowFieldMessage -_08164B54: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164828 - - thumb_func_start sub_8164B74 -sub_8164B74: @ 8164B74 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 30 - lsrs r7, r0, 30 - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - lsrs r5, r0, 16 - ldr r0, [r4] - ldr r2, =0x00000cb2 - adds r0, r2 - ldrh r6, [r0] - bl GetMultiplayerId - ldr r0, =gSpecialVar_Result - ldrh r0, [r0] - cmp r0, 0x6 - bls _08164BAC - b _08164DB6 -_08164BAC: - lsls r0, 2 - ldr r1, =_08164BD0 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08164BD0: - .4byte _08164BEC - .4byte _08164C3C - .4byte _08164CE0 - .4byte _08164D14 - .4byte _08164D98 - .4byte _08164DA8 - .4byte _08164DB6 -_08164BEC: - cmp r5, 0x3 - beq _08164BF2 - b _08164DB0 -_08164BF2: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - lsls r1, r7, 1 - adds r0, r1 - ldr r3, =0x00000cec - adds r0, r3 - ldrh r0, [r0] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - str r0, [sp] - bl sub_800A520 - lsls r0, 24 - cmp r0, 0 - bne _08164C18 - b _08164DB6 -_08164C18: - bl bitmask_all_link_players_but_self - lsls r0, 24 - lsrs r0, 24 - mov r1, sp - movs r2, 0x4 - bl SendBlock - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - b _08164DB4 - .pool -_08164C3C: - bl GetBlockReceivedStatus - movs r1, 0x3 - ands r1, r0 - cmp r1, 0x3 - beq _08164C4A - b _08164DB6 -_08164C4A: - bl ResetBlockReceivedFlags - ldr r1, =gBlockRecvBuffer - movs r0, 0x80 - lsls r0, 1 - adds r2, r1, r0 - ldrh r0, [r1] - ldrh r3, [r2] - cmp r0, r3 - bhi _08164C60 - ldrh r0, [r2] -_08164C60: - str r0, [sp] - movs r4, 0 - ldr r0, =gSaveBlock2Ptr - mov r9, r0 -_08164C68: - adds r1, r4, 0x1 - mov r8, r1 - lsrs r0, r4, 31 - adds r0, r4, r0 - asrs r0, 1 - lsls r7, r0, 24 -_08164C74: - ldr r0, [sp] - lsls r0, 24 - lsrs r0, 24 - lsrs r1, r7, 24 - bl sub_8162548 - lsls r0, 16 - lsrs r3, r0, 16 - movs r2, 0 - cmp r2, r4 - bge _08164CB0 - mov r1, r9 - ldr r0, [r1] - ldr r1, =0x00000cb4 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r3 - beq _08164CB0 - ldr r6, =gSaveBlock2Ptr - adds r5, r1, 0 -_08164C9C: - adds r2, 0x1 - cmp r2, r4 - bge _08164CB0 - ldr r0, [r6] - lsls r1, r2, 1 - adds r0, r5 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r3 - bne _08164C9C -_08164CB0: - cmp r4, r2 - bne _08164C74 - mov r2, r9 - ldr r0, [r2] - lsls r1, r4, 1 - ldr r2, =0x00000cb4 - adds r0, r2 - adds r0, r1 - strh r3, [r0] - mov r4, r8 - cmp r4, 0xD - ble _08164C68 - ldr r1, =gSpecialVar_Result - movs r0, 0x2 - b _08164DB4 - .pool -_08164CE0: - bl sub_800A520 - lsls r0, 24 - cmp r0, 0 - beq _08164DB6 - bl bitmask_all_link_players_but_self - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gSaveBlock2Ptr - ldr r1, [r1] - ldr r3, =0x00000cb4 - adds r1, r3 - movs r2, 0x28 - bl SendBlock - ldr r1, =gSpecialVar_Result - movs r0, 0x3 - b _08164DB4 - .pool -_08164D14: - bl GetBlockReceivedStatus - movs r1, 0x3 - ands r1, r0 - cmp r1, 0x3 - bne _08164DB6 - bl ResetBlockReceivedFlags - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r5, =0x00000cb4 - adds r0, r5 - ldr r1, =gBlockRecvBuffer - movs r2, 0x28 - bl memcpy - ldr r2, =gTrainerBattleOpponent_A - ldr r1, [r4] - lsls r0, r6, 2 - adds r1, r5 - adds r0, r1, r0 - ldrh r0, [r0] - strh r0, [r2] - ldr r4, =gTrainerBattleOpponent_B - lsls r0, r6, 1 - adds r0, 0x1 - lsls r0, 1 - adds r1, r0 - ldrh r0, [r1] - strh r0, [r4] - ldrh r0, [r2] - movs r1, 0 - bl SetBattleFacilityTrainerGfxId - ldrh r0, [r4] - movs r1, 0x1 - bl SetBattleFacilityTrainerGfxId - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0 - beq _08164DB0 - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - bne _08164DB0 - ldr r1, =gSpecialVar_Result - movs r0, 0x4 - b _08164DB4 - .pool -_08164D98: - bl sub_800AC34 - ldr r1, =gSpecialVar_Result - movs r0, 0x5 - b _08164DB4 - .pool -_08164DA8: - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0 - bne _08164DB6 -_08164DB0: - ldr r1, =gSpecialVar_Result - movs r0, 0x6 -_08164DB4: - strh r0, [r1] -_08164DB6: - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164B74 - - thumb_func_start sub_8164DCC -sub_8164DCC: @ 8164DCC - push {lr} - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - beq _08164DDA - bl sub_800AC34 -_08164DDA: - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164DCC - - thumb_func_start sub_8164DE4 -sub_8164DE4: @ 8164DE4 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cd6 - adds r0, r1 - ldrh r0, [r0] - movs r1, 0xF - bl SetBattleFacilityTrainerGfxId - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164DE4 - - thumb_func_start sub_8164E04 -sub_8164E04: @ 8164E04 - push {r4-r6,lr} - sub sp, 0x20 - ldr r0, =0x000040ce - bl VarGet - lsls r0, 16 - cmp r0, 0 - bne _08164E9A - ldr r5, =gTrainerBattleOpponent_A - ldrh r1, [r5] - mov r0, sp - bl GetFrontierTrainerName - mov r0, sp - bl StripExtCtrlCodes - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r1, =0x00000bd8 - adds r0, r1 - mov r1, sp - bl StringCopy - ldr r0, [r4] - ldr r2, =0x00000beb - adds r0, r2 - ldrh r1, [r5] - bl sub_8165B88 - ldr r6, =gBattlerPartyIndexes - ldrh r0, [r6, 0x2] - movs r5, 0x64 - muls r0, r5 - ldr r1, =gEnemyParty - adds r0, r1 - movs r1, 0xB - movs r2, 0 - bl GetMonData - ldr r1, [r4] - ldr r2, =0x00000bd6 - adds r1, r2 - strh r0, [r1] - ldrh r0, [r6] - muls r0, r5 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0xB - movs r2, 0 - bl GetMonData - ldr r1, [r4] - ldr r2, =0x00000bd4 - adds r1, r2 - strh r0, [r1] - movs r2, 0 - movs r5, 0xBE - lsls r5, 4 - ldr r3, =gBattleMons + 0x30 - adds r6, r4, 0 -_08164E7C: - ldr r0, [r4] - adds r0, r5 - adds r0, r2 - adds r1, r2, r3 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0xA - ble _08164E7C - ldr r0, [r6] - ldr r1, =gBattleOutcome - ldrb r1, [r1] - ldr r2, =0x00000d06 - adds r0, r2 - strb r1, [r0] -_08164E9A: - add sp, 0x20 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164E04 - - thumb_func_start sub_8164ED8 -sub_8164ED8: @ 8164ED8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r3, 0 - movs r2, 0 - ldr r4, =0x0000064c - adds r1, r0, r4 -_08164EEA: - ldm r1!, {r0} - adds r3, r0 - adds r2, 0x1 - cmp r2, 0x39 - bls _08164EEA - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - ldr r2, =0x00000734 - adds r0, r1, r2 - ldr r0, [r0] - cmp r0, r3 - beq _08164F0A - ldr r3, =0x0000064c - adds r0, r1, r3 - bl sub_8164FB8 -_08164F0A: - movs r4, 0 - adds r7, r5, 0 - movs r6, 0xEC - mov r8, r7 -_08164F12: - adds r0, r4, 0 - muls r0, r6 - movs r1, 0xE7 - lsls r1, 3 - adds r0, r1 - ldr r1, [r7] - movs r3, 0 - movs r2, 0 - adds r5, r4, 0x1 - adds r1, r0 -_08164F26: - ldm r1!, {r0} - adds r3, r0 - adds r2, 0x1 - cmp r2, 0x39 - bls _08164F26 - mov r0, r8 - ldr r2, [r0] - adds r1, r4, 0 - muls r1, r6 - movs r4, 0x82 - lsls r4, 4 - adds r0, r2, r4 - adds r0, r1 - ldr r0, [r0] - cmp r0, r3 - beq _08164F52 - movs r3, 0xE7 - lsls r3, 3 - adds r0, r1, r3 - adds r0, r2, r0 - bl sub_8164FB8 -_08164F52: - adds r4, r5, 0 - cmp r4, 0x4 - ble _08164F12 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8164ED8 - - thumb_func_start CalcEmeraldBattleTowerChecksum -CalcEmeraldBattleTowerChecksum: @ 8164F70 - push {r4,lr} - adds r2, r0, 0 - adds r2, 0xE8 - movs r1, 0 - str r1, [r2] - movs r3, 0 - adds r4, r0, 0 -_08164F7E: - ldr r0, [r2] - ldm r4!, {r1} - adds r0, r1 - str r0, [r2] - adds r3, 0x1 - cmp r3, 0x39 - bls _08164F7E - pop {r4} - pop {r0} - bx r0 - thumb_func_end CalcEmeraldBattleTowerChecksum - - thumb_func_start sub_8164F94 -sub_8164F94: @ 8164F94 - push {r4,lr} - adds r2, r0, 0 - adds r2, 0xA0 - movs r1, 0 - str r1, [r2] - movs r3, 0 - adds r4, r0, 0 -_08164FA2: - ldr r0, [r2] - ldm r4!, {r1} - adds r0, r1 - str r0, [r2] - adds r3, 0x1 - cmp r3, 0x27 - bls _08164FA2 - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8164F94 - - thumb_func_start sub_8164FB8 -sub_8164FB8: @ 8164FB8 - push {lr} - movs r1, 0 - movs r2, 0 -_08164FBE: - stm r0!, {r2} - adds r1, 0x1 - cmp r1, 0x3A - bls _08164FBE - pop {r0} - bx r0 - thumb_func_end sub_8164FB8 - - thumb_func_start GetCurrentBattleTowerWinStreak -GetCurrentBattleTowerWinStreak: @ 8164FCC - push {lr} - lsls r0, 24 - lsls r1, 24 - ldr r2, =gSaveBlock2Ptr - ldr r2, [r2] - lsrs r0, 23 - lsrs r1, 22 - adds r0, r1 - movs r1, 0xCE - lsls r1, 4 - adds r2, r1 - adds r2, r0 - ldrh r0, [r2] - ldr r1, =0x0000270f - cmp r0, r1 - bls _08164FEE - adds r0, r1, 0 -_08164FEE: - pop {r1} - bx r1 - .pool - thumb_func_end GetCurrentBattleTowerWinStreak - - thumb_func_start sub_8164FFC -sub_8164FFC: @ 8164FFC - push {r4,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r4, r0, 24 - ldr r1, =gUnknown_085DFA42 - mov r0, sp - movs r2, 0x4 - bl memcpy - cmp r4, 0x3 - bls _0816501C - movs r0, 0x3 - b _08165022 - .pool -_0816501C: - mov r1, sp - adds r0, r1, r4 - ldrb r0, [r0] -_08165022: - add sp, 0x4 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8164FFC - - thumb_func_start sub_816502C -sub_816502C: @ 816502C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca9 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - adds r5, r0, 0 - ldr r0, =0x000040ce - bl VarGet - lsls r0, 24 - lsrs r0, 24 - adds r4, r0, 0 - bl sub_8164FFC - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - movs r2, 0x44 - mov r10, r2 - cmp r5, 0 - beq _0816506A - movs r0, 0x45 - mov r10, r0 -_0816506A: - ldr r1, =gSpecialVar_Result - mov r9, r1 - movs r0, 0 - strh r0, [r1] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetCurrentBattleTowerWinStreak - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x37 - bls _081650DC - movs r6, 0 - cmp r6, r8 - bge _081650DC - ldr r7, =gSaveBlock1Ptr - mov r5, sp -_0816508C: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - lsls r1, r6, 1 - ldr r2, =0x00000caa - adds r0, r2 - adds r0, r1 - ldrh r1, [r0] - subs r1, 0x1 - movs r0, 0 - strb r1, [r5] - strb r0, [r5, 0x1] - movs r0, 0x64 - muls r0, r1 - movs r1, 0x8E - lsls r1, 2 - adds r4, r0, r1 - ldr r0, [r7] - adds r0, r4 - mov r1, r10 - bl GetMonData - cmp r0, 0 - bne _081650D4 - movs r0, 0x1 - mov r2, r9 - strh r0, [r2] - ldr r0, [r7] - adds r0, r4 - mov r1, r10 - bl SetMonData - ldr r0, [r7] - adds r0, r4 - bl GetRibbonCount - strb r0, [r5, 0x1] -_081650D4: - adds r5, 0x4 - adds r6, 0x1 - cmp r6, r8 - blt _0816508C -_081650DC: - ldr r0, =gSpecialVar_Result - ldrh r0, [r0] - cmp r0, 0 - beq _08165132 - movs r0, 0x2A - bl IncrementGameStat - mov r0, r8 - cmp r0, 0x1 - ble _08165110 - mov r3, sp - add r2, sp, 0x4 - mov r6, r8 - subs r6, 0x1 -_081650F8: - ldrb r1, [r3, 0x1] - ldrb r0, [r2, 0x1] - cmp r0, r1 - bls _08165108 - ldr r1, [sp] - ldr r0, [r2] - str r0, [sp] - str r1, [r2] -_08165108: - adds r2, 0x4 - subs r6, 0x1 - cmp r6, 0 - bne _081650F8 -_08165110: - mov r0, sp - ldrb r0, [r0, 0x1] - cmp r0, 0x4 - bls _08165132 - ldr r2, =gSaveBlock1Ptr - mov r0, sp - ldrb r1, [r0] - movs r0, 0x64 - muls r1, r0 - movs r0, 0x8E - lsls r0, 2 - adds r1, r0 - ldr r0, [r2] - adds r0, r1 - mov r1, r10 - bl sub_80EE4DC -_08165132: - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_816502C - - thumb_func_start sub_816515C -sub_816515C: @ 816515C - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - ldr r1, =gSaveBlock2Ptr - ldr r2, [r1] - ldr r0, =0x00000bec - adds r7, r2, r0 - ldrb r0, [r2, 0x8] - adds r5, r1, 0 - cmp r0, 0 - beq _08165194 - ldr r4, =gTowerFemaleFacilityClasses - ldrb r0, [r2, 0xA] - ldrb r1, [r2, 0xB] - adds r0, r1 - ldrb r1, [r2, 0xC] - adds r0, r1 - ldrb r1, [r2, 0xD] - adds r0, r1 - movs r1, 0x14 - b _081651A6 - .pool -_08165194: - ldr r4, =gTowerMaleFacilityClasses - ldrb r0, [r2, 0xA] - ldrb r1, [r2, 0xB] - adds r0, r1 - ldrb r1, [r2, 0xC] - adds r0, r1 - ldrb r1, [r2, 0xD] - adds r0, r1 - movs r1, 0x1E -_081651A6: - bl __umodsi3 - adds r0, r4 - ldrb r0, [r0] - strb r0, [r7, 0x1] - adds r0, r7, 0 - adds r0, 0xC - ldr r1, [r5] - adds r1, 0xA - bl CopyUnalignedWord - adds r0, r7, 0x4 - ldr r1, [r5] - bl StringCopy7 - movs r0, 0x1 - strh r0, [r7, 0x2] - movs r6, 0x7 - movs r4, 0 - ldr r0, =gSaveBlock1Ptr - mov r8, r0 - adds r5, r7, 0 - adds r5, 0x10 - ldr r1, =0x00002bbc - mov r12, r1 - adds r3, r7, 0 - adds r3, 0x28 - adds r2, r7, 0 - adds r2, 0x1C -_081651E0: - lsls r0, r4, 1 - mov r9, r0 - mov r1, r8 - ldr r0, [r1] - add r0, r12 - add r0, r9 - ldrh r0, [r0] - strh r0, [r5] - strh r6, [r2] - adds r0, r6, 0x6 - strh r0, [r3] - adds r6, 0x1 - adds r5, 0x2 - adds r3, 0x2 - adds r2, 0x2 - adds r4, 0x1 - cmp r4, 0x5 - ble _081651E0 - movs r4, 0 -_08165206: - movs r0, 0x64 - muls r0, r4 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x2C - muls r1, r4 - adds r1, 0x34 - adds r1, r7, r1 - bl sub_80686FC - adds r4, 0x1 - cmp r4, 0x2 - ble _08165206 - adds r0, r7, 0 - bl sub_8165328 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_816515C - - thumb_func_start GetEreaderTrainerFrontSpriteId -GetEreaderTrainerFrontSpriteId: @ 8165244 - ldr r1, =gFacilityClassToPicIndex - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000bed - adds r0, r2 - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end GetEreaderTrainerFrontSpriteId - - thumb_func_start GetEreaderTrainerClassId -GetEreaderTrainerClassId: @ 8165264 - ldr r1, =gFacilityClassToTrainerClass - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000bed - adds r0, r2 - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end GetEreaderTrainerClassId - - thumb_func_start GetEreaderTrainerName -GetEreaderTrainerName: @ 8165284 - push {r4,lr} - adds r3, r0, 0 - movs r2, 0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r1, 0xBF - lsls r1, 4 - adds r4, r0, r1 -_08165294: - adds r0, r3, r2 - adds r1, r4, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x4 - ble _08165294 - adds r1, r3, r2 - movs r0, 0xFF - strb r0, [r1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end GetEreaderTrainerName - - thumb_func_start ValidateEReaderTrainer -ValidateEReaderTrainer: @ 81652B4 - push {r4-r6,lr} - ldr r2, =gSpecialVar_Result - movs r0, 0 - strh r0, [r2] - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r3, =0x00000bec - adds r5, r0, r3 - movs r4, 0 - movs r3, 0 - adds r6, r1, 0 - adds r1, r5, 0 -_081652CC: - ldm r1!, {r0} - orrs r4, r0 - adds r3, 0x1 - cmp r3, 0x2D - bls _081652CC - cmp r4, 0 - bne _081652EC - movs r0, 0x1 - strh r0, [r2] - b _08165316 - .pool -_081652EC: - movs r4, 0 - movs r3, 0 - adds r2, r5, 0 -_081652F2: - ldm r2!, {r0} - adds r4, r0 - adds r3, 0x1 - cmp r3, 0x2D - bls _081652F2 - ldr r1, [r6] - ldr r2, =0x00000ca4 - adds r0, r1, r2 - ldr r0, [r0] - cmp r0, r4 - beq _08165316 - ldr r3, =0x00000bec - adds r0, r1, r3 - bl sub_816534C - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - strh r0, [r1] -_08165316: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end ValidateEReaderTrainer - - thumb_func_start sub_8165328 -sub_8165328: @ 8165328 - push {r4,lr} - adds r2, r0, 0 - adds r2, 0xB8 - movs r1, 0 - str r1, [r2] - movs r3, 0 - adds r4, r0, 0 -_08165336: - ldr r0, [r2] - ldm r4!, {r1} - adds r0, r1 - str r0, [r2] - adds r3, 0x1 - cmp r3, 0x2D - bls _08165336 - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8165328 - - thumb_func_start sub_816534C -sub_816534C: @ 816534C - push {lr} - movs r1, 0 - movs r2, 0 -_08165352: - stm r0!, {r2} - adds r1, 0x1 - cmp r1, 0x2E - bls _08165352 - pop {r0} - bx r0 - thumb_func_end sub_816534C - - thumb_func_start sub_8165360 -sub_8165360: @ 8165360 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000bfc - adds r0, r1 - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_8165360 - - thumb_func_start sub_816537C -sub_816537C: @ 816537C - push {lr} - ldr r0, =gBattleOutcome - ldrb r0, [r0] - cmp r0, 0x3 - bne _08165398 - ldr r1, =gStringVar4 - movs r0, 0xFF - strb r0, [r1] - b _081653C0 - .pool -_08165398: - cmp r0, 0x1 - bne _081653B4 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000c14 - adds r0, r1 - bl FrontierSpeechToString - b _081653C0 - .pool -_081653B4: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000c08 - adds r0, r1 - bl FrontierSpeechToString -_081653C0: - pop {r0} - bx r0 - .pool - thumb_func_end sub_816537C - - thumb_func_start sub_81653CC -sub_81653CC: @ 81653CC - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca8 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0x1 - bne _081653E0 - bl sub_80F01B8 -_081653E0: - movs r0, 0x77 - bl FlagGet - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _081653F8 - bl sub_80F01B8 - movs r0, 0x77 - bl FlagClear -_081653F8: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81653CC - - thumb_func_start sub_8165404 -sub_8165404: @ 8165404 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x70 - lsls r0, 16 - lsrs r7, r0, 16 - bl GetFacilityEnemyMonLevel - ldr r0, =0x00000c03 - cmp r7, r0 - beq _08165420 - b _0816554C -_08165420: - movs r0, 0 - mov r10, r0 - mov r1, sp - adds r1, 0x44 - str r1, [sp, 0x64] -_0816542A: - mov r2, r10 - lsls r2, 2 - mov r9, r2 - mov r3, r10 - adds r3, 0x1 - str r3, [sp, 0x60] - mov r0, r9 - add r0, r10 - lsls r0, 2 - ldr r6, =gUnknown_085DD6D0 - adds r5, r0, r6 -_08165440: - bl Random - adds r4, r0, 0 - bl Random - lsls r4, 16 - lsrs r4, 16 - lsls r0, 16 - orrs r4, r0 - str r4, [sp, 0x44] - ldr r0, =0x0000ef2a - adds r1, r4, 0 - bl IsShinyOtIdPersonality - lsls r0, 24 - lsrs r7, r0, 24 - cmp r7, 0 - bne _08165440 - ldr r0, [sp, 0x44] - bl GetNatureFromPersonality - ldrb r1, [r5, 0x4] - lsls r0, 24 - lsrs r0, 24 - cmp r1, r0 - bne _08165440 - movs r0, 0x64 - mov r6, r10 - muls r6, r0 - ldr r1, =gPlayerParty + 300 - mov r8, r1 - adds r0, r6, r1 - mov r5, r9 - add r5, r10 - lsls r5, 2 - ldr r2, =gUnknown_085DD6D0 - adds r3, r5, r2 - ldrh r1, [r3] - ldrb r2, [r3, 0x3] - ldrb r3, [r3, 0x2] - mov r12, r3 - movs r4, 0x1 - str r4, [sp] - mov r3, r10 - str r3, [sp, 0x4] - str r4, [sp, 0x8] - ldr r4, =0x0000ef2a - str r4, [sp, 0xC] - mov r3, r12 - bl CreateMon - str r7, [sp, 0x44] - movs r3, 0 - mov r4, r8 - ldr r0, =gUnknown_085DD6D5 - adds r5, r0 -_081654B0: - adds r1, r3, 0 - adds r1, 0x1A - adds r2, r5, r3 - adds r0, r6, r4 - bl SetMonData - ldr r0, [sp, 0x44] - adds r0, 0x1 - str r0, [sp, 0x44] - adds r3, r0, 0 - cmp r3, 0x5 - ble _081654B0 - movs r0, 0 - str r0, [sp, 0x44] - movs r1, 0 - movs r6, 0x64 - mov r4, r10 - muls r4, r6 - ldr r7, =gUnknown_085DD6DC - ldr r6, =gPlayerParty + 300 - mov r0, r9 - add r0, r10 - lsls r5, r0, 2 -_081654DE: - lsls r0, r1, 1 - adds r0, r5 - adds r0, r7 - ldrh r1, [r0] - ldr r0, [sp, 0x64] - ldrb r2, [r0] - adds r0, r4, r6 - bl SetMonMoveSlot - ldr r0, [sp, 0x44] - adds r0, 0x1 - str r0, [sp, 0x44] - adds r1, r0, 0 - cmp r1, 0x3 - ble _081654DE - movs r1, 0x64 - mov r4, r10 - muls r4, r1 - ldr r0, =gPlayerParty + 300 - adds r4, r0 - adds r0, r4, 0 - movs r1, 0x7 - ldr r2, =gTrainers + 804 * 0x28 + 0x4 @ TRAINER_STEVEN name - bl SetMonData - movs r0, 0 - str r0, [sp, 0x44] - adds r0, r4, 0 - movs r1, 0x31 - ldr r2, [sp, 0x64] - bl SetMonData - adds r0, r4, 0 - bl CalculateMonStats - ldr r2, [sp, 0x60] - mov r10, r2 - cmp r2, 0x2 - bgt _0816552E - b _0816542A -_0816552E: - b _0816585A - .pool -_0816554C: - movs r0, 0xFA - lsls r0, 1 - cmp r7, r0 - bne _08165564 - add r0, sp, 0x10 - ldr r1, =gGameLanguage - ldrb r1, [r1] - strb r1, [r0] - b _0816585A - .pool -_08165564: - ldr r0, =0x0000012b - cmp r7, r0 - bls _0816556C - b _081656E8 -_0816556C: - bl GetFacilityEnemyMonLevel - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x50] - adds r0, r7, 0 - bl GetFrontierTrainerFixedIvs - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4C] - bl Random - adds r4, r0, 0 - bl Random - lsls r4, 16 - lsrs r4, 16 - lsls r0, 16 - orrs r4, r0 - str r4, [sp, 0x58] - movs r3, 0 - mov r10, r3 - mov r6, sp - adds r6, 0x44 - str r6, [sp, 0x64] - mov r0, sp - adds r0, 0x48 - str r0, [sp, 0x5C] -_081655A6: - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - mov r0, r10 - adds r0, 0x12 - lsls r0, 1 - ldr r2, =0x00000cb4 - adds r1, r2 - adds r1, r0 - ldrh r1, [r1] - str r1, [sp, 0x54] - movs r6, 0x64 - mov r3, r10 - muls r3, r6 - mov r8, r3 - ldr r0, =gPlayerParty + 300 - mov r9, r0 - mov r0, r8 - add r0, r9 - ldr r6, =gFacilityTrainerMons - ldr r4, [r6] - lsls r5, r1, 4 - adds r4, r5, r4 - ldrh r1, [r4] - ldr r3, [sp, 0x50] - lsls r2, r3, 24 - ldrb r3, [r4, 0xC] - mov r12, r3 - ldr r3, [sp, 0x4C] - str r3, [sp] - ldrb r4, [r4, 0xB] - str r4, [sp, 0x4] - ldr r3, [sp, 0x58] - str r3, [sp, 0x8] - lsrs r2, 24 - mov r3, r12 - bl CreateMonWithEVSpreadPersonalityOTID - movs r0, 0xFF - str r0, [sp, 0x48] - movs r0, 0 - str r0, [sp, 0x44] - movs r2, 0 - mov r0, r10 - adds r0, 0x1 - str r0, [sp, 0x60] - mov r4, r8 - mov r3, r9 -_08165604: - ldr r0, [r6] - adds r0, r5, r0 - lsls r1, r2, 1 - adds r0, 0x2 - adds r0, r1 - ldrh r1, [r0] - lsls r2, 24 - lsrs r2, 24 - adds r0, r4, r3 - str r3, [sp, 0x68] - bl SetMonMoveSlot - ldr r0, [r6] - adds r0, r5, r0 - ldr r2, [sp, 0x44] - lsls r1, r2, 1 - adds r0, 0x2 - adds r0, r1 - ldrh r0, [r0] - ldr r3, [sp, 0x68] - cmp r0, 0xDA - bne _08165634 - movs r0, 0 - str r0, [sp, 0x48] -_08165634: - adds r0, r2, 0x1 - str r0, [sp, 0x44] - adds r2, r0, 0 - cmp r2, 0x3 - ble _08165604 - movs r1, 0x64 - mov r4, r10 - muls r4, r1 - ldr r0, =gPlayerParty + 300 - adds r4, r0 - adds r0, r4, 0 - movs r1, 0x20 - ldr r2, [sp, 0x5C] - bl SetMonData - ldr r0, =gFacilityTrainerMons - ldr r1, [r0] - ldr r2, [sp, 0x54] - lsls r0, r2, 4 - adds r0, r1 - ldrb r2, [r0, 0xA] - lsls r2, 1 - ldr r0, =gBattleFrontierHeldItems - adds r2, r0 - adds r0, r4, 0 - movs r1, 0xC - bl SetMonData - movs r0, 0 - str r0, [sp, 0x44] - movs r2, 0 - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r7 - adds r0, r1 - adds r3, r0, 0x4 -_0816567E: - mov r1, sp - adds r1, r2 - adds r1, 0x10 - adds r0, r3, r2 - ldrb r0, [r0] - strb r0, [r1] - ldr r0, [sp, 0x44] - adds r0, 0x1 - str r0, [sp, 0x44] - adds r2, r0, 0 - cmp r2, 0x7 - ble _0816567E - movs r3, 0x64 - mov r4, r10 - muls r4, r3 - ldr r0, =gPlayerParty + 300 - adds r4, r0 - adds r0, r4, 0 - movs r1, 0x7 - add r2, sp, 0x10 - bl SetMonData - adds r0, r7, 0 - bl IsFrontierTrainerFemale - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x44] - adds r0, r4, 0 - movs r1, 0x31 - ldr r2, [sp, 0x64] - bl SetMonData - ldr r6, [sp, 0x60] - mov r10, r6 - cmp r6, 0x1 - bgt _081656CA - b _081655A6 -_081656CA: - b _0816585A - .pool -_081656E8: - ldr r0, =0x0000018f - cmp r7, r0 - bls _081656F0 - b _081657F0 -_081656F0: - ldr r1, =0xfffffed4 - adds r0, r7, r1 - lsls r0, 16 - lsrs r7, r0, 16 - movs r2, 0 - mov r10, r2 - mov r3, sp - adds r3, 0x44 - str r3, [sp, 0x64] - add r5, sp, 0x18 - ldr r6, =0x000015fc - mov r9, r6 - ldr r0, =0x0000ffff - mov r8, r0 - movs r1, 0x24 - str r1, [sp, 0x6C] -_08165710: - ldr r1, =gSaveBlock2Ptr - movs r0, 0xEC - adds r4, r7, 0 - muls r4, r0 - movs r2, 0xE7 - lsls r2, 3 - adds r4, r2 - ldr r0, [r1] - adds r4, r0, r4 - ldr r3, =0x00000cb4 - adds r0, r3 - ldr r6, [sp, 0x6C] - adds r0, r6 - ldrh r1, [r0] - movs r0, 0x2C - muls r1, r0 - adds r1, r4, r1 - adds r0, r5, 0 - adds r1, 0x34 - ldm r1!, {r2,r3,r6} - stm r0!, {r2,r3,r6} - ldm r1!, {r2,r3,r6} - stm r0!, {r2,r3,r6} - ldm r1!, {r2,r3,r6} - stm r0!, {r2,r3,r6} - ldm r1!, {r2,r3} - stm r0!, {r2,r3} - adds r1, r4, 0x4 - add r0, sp, 0x10 - bl StringCopy - adds r4, 0xE4 - ldrb r0, [r4] - cmp r0, 0x1 - bne _0816578C - ldrh r0, [r5, 0x20] - mov r6, r8 - ands r0, r6 - cmp r0, r9 - beq _0816579C - mov r1, sp - adds r1, 0x3D - movs r0, 0xFF - strb r0, [r1] - add r0, sp, 0x38 - movs r1, 0x1 - bl ConvertInternationalString - b _0816579C - .pool -_0816578C: - ldrh r0, [r5, 0x20] - mov r1, r8 - ands r0, r1 - cmp r0, r9 - bne _0816579C - add r1, sp, 0x10 - movs r0, 0xFF - strb r0, [r1, 0x5] -_0816579C: - movs r0, 0x64 - mov r4, r10 - muls r4, r0 - ldr r0, =gPlayerParty + 300 - adds r4, r0 - adds r0, r4, 0 - adds r1, r5, 0 - movs r2, 0x1 - bl sub_8068338 - adds r0, r4, 0 - movs r1, 0x7 - add r2, sp, 0x10 - bl SetMonData - movs r2, 0x96 - lsls r2, 1 - adds r0, r7, r2 - lsls r0, 16 - lsrs r0, 16 - bl IsFrontierTrainerFemale - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x44] - adds r0, r4, 0 - movs r1, 0x31 - ldr r2, [sp, 0x64] - bl SetMonData - ldr r3, [sp, 0x6C] - adds r3, 0x2 - str r3, [sp, 0x6C] - movs r6, 0x1 - add r10, r6 - mov r0, r10 - cmp r0, 0x1 - ble _08165710 - b _0816585A - .pool -_081657F0: - ldr r1, =0xfffffe70 - adds r0, r7, r1 - lsls r0, 16 - lsrs r7, r0, 16 - movs r2, 0 - mov r10, r2 - mov r3, sp - adds r3, 0x44 - str r3, [sp, 0x64] - ldr r6, =gSaveBlock2Ptr - mov r8, r6 - movs r5, 0x24 - lsls r0, r7, 4 - adds r0, r7 - lsls r0, 2 - adds r6, r0, 0 - adds r6, 0xDC -_08165812: - movs r0, 0x64 - mov r4, r10 - muls r4, r0 - ldr r0, =gPlayerParty + 300 - adds r4, r0 - mov r1, r8 - ldr r0, [r1] - adds r1, r0, r6 - ldr r2, =0x00000cb4 - adds r0, r2 - adds r0, r5 - ldrb r2, [r0] - adds r0, r4, 0 - bl CreateApprenticeMon - movs r3, 0xC8 - lsls r3, 1 - adds r0, r7, r3 - lsls r0, 16 - lsrs r0, 16 - bl IsFrontierTrainerFemale - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x44] - adds r0, r4, 0 - movs r1, 0x31 - ldr r2, [sp, 0x64] - bl SetMonData - adds r5, 0x2 - movs r0, 0x1 - add r10, r0 - mov r1, r10 - cmp r1, 0x1 - ble _08165812 -_0816585A: - add sp, 0x70 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8165404 - - thumb_func_start sub_816587C -sub_816587C: @ 816587C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - adds r6, r0, 0 - adds r5, r1, 0 - movs r2, 0 - adds r1, r6, 0 - adds r3, r6, 0 - adds r3, 0x58 -_08165894: - ldrh r0, [r1, 0x1C] - cmp r0, 0 - beq _0816589C - adds r2, 0x1 -_0816589C: - adds r1, 0x2C - cmp r1, r3 - ble _08165894 - cmp r2, 0x3 - beq _081658B4 - adds r0, r5, 0 - movs r1, 0 - movs r2, 0xEC - bl memset - movs r0, 0 - b _081659BE -_081658B4: - ldrb r0, [r6] - strb r0, [r5] - ldrh r0, [r6, 0x2] - strh r0, [r5, 0x2] - movs r2, 0 - ldr r0, =gUnknown_085DCF40 - ldrb r1, [r0] - ldrb r3, [r6, 0x1] - mov r12, r0 - adds r4, r5, 0x4 - adds r7, r6, 0x4 - movs r0, 0xC - adds r0, r5 - mov r9, r0 - movs r0, 0xC - adds r0, r6 - mov r8, r0 - adds r0, r5, 0 - adds r0, 0x10 - str r0, [sp, 0x4] - movs r0, 0x10 - adds r0, r6 - mov r10, r0 - adds r0, r5, 0 - adds r0, 0x1C - str r0, [sp, 0x8] - adds r0, 0xC - str r0, [sp, 0xC] - adds r0, 0x90 - str r0, [sp, 0x10] - cmp r1, r3 - beq _08165904 - mov r1, r12 -_081658F6: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, 0x51 - bgt _08165904 - ldrb r0, [r1] - cmp r0, r3 - bne _081658F6 -_08165904: - cmp r2, 0x52 - beq _08165918 - lsls r0, r2, 1 - mov r1, r12 - adds r1, 0x1 - adds r0, r1 - ldrb r0, [r0] - b _0816591A - .pool -_08165918: - movs r0, 0x2B -_0816591A: - strb r0, [r5, 0x1] - movs r2, 0 - adds r3, r7, 0 -_08165920: - adds r0, r4, r2 - adds r1, r3, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x7 - ble _08165920 - movs r2, 0 - mov r4, r9 - mov r3, r8 -_08165934: - adds r0, r4, r2 - adds r1, r3, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x3 - ble _08165934 - mov r3, r10 - ldr r1, [sp, 0x4] - movs r2, 0x5 -_08165948: - ldrh r0, [r3] - strh r0, [r1] - adds r3, 0x2 - adds r1, 0x2 - subs r2, 0x1 - cmp r2, 0 - bge _08165948 - ldr r3, =gUnknown_085DFA46 - ldr r1, [sp, 0x8] - movs r2, 0x5 -_0816595C: - ldrh r0, [r3] - strh r0, [r1] - adds r3, 0x2 - adds r1, 0x2 - subs r2, 0x1 - cmp r2, 0 - bge _0816595C - ldr r3, =gUnknown_085DFA52 - ldr r1, [sp, 0xC] - movs r2, 0x5 -_08165970: - ldrh r0, [r3] - strh r0, [r1] - adds r3, 0x2 - adds r1, 0x2 - subs r2, 0x1 - cmp r2, 0 - bge _08165970 - adds r2, r6, 0 - adds r3, r5, 0 - movs r4, 0x58 - adds r4, r2 - mov r8, r4 -_08165988: - adds r1, r3, 0 - adds r1, 0x34 - adds r0, r2, 0 - adds r0, 0x1C - ldm r0!, {r4,r6,r7} - stm r1!, {r4,r6,r7} - ldm r0!, {r4,r6,r7} - stm r1!, {r4,r6,r7} - ldm r0!, {r4,r6,r7} - stm r1!, {r4,r6,r7} - ldm r0!, {r6,r7} - stm r1!, {r6,r7} - adds r2, 0x2C - adds r3, 0x2C - cmp r2, r8 - ble _08165988 - movs r0, 0 - str r0, [sp] - ldr r2, =0x0500000b - mov r0, sp - ldr r1, [sp, 0x10] - bl CpuSet - adds r0, r5, 0 - bl CalcEmeraldBattleTowerChecksum - movs r0, 0x1 -_081659BE: - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_816587C thumb_func_start sub_81659DC sub_81659DC: @ 81659DC @@ -2264,7 +43,7 @@ _08165A14: ldrh r0, [r4, 0x2] strh r0, [r6, 0x2] movs r2, 0 - ldr r0, =gUnknown_085DCF40 + ldr r0, =sRubyFacilityClassToEmerald ldrb r1, [r0, 0x1] ldrb r3, [r4, 0x1] mov r12, r0 @@ -2361,7 +140,7 @@ _08165AB0: cmp r2, r8 ble _08165AB0 adds r0, r6, 0 - bl sub_8164F94 + bl CalcRubyBattleTowerChecksum movs r0, 0x1 _08165AD8: add sp, 0x4 @@ -3201,7 +980,7 @@ _08166174: lsls r3, 3 adds r0, r1, r3 adds r0, r2, r0 - bl sub_8164FB8 + bl ClearBattleTowerRecord _08166180: movs r0, 0 _08166182: diff --git a/asm/rom_8011DC0.s b/asm/rom_8011DC0.s index 415ebfc0c..1c02f93cd 100644 --- a/asm/rom_8011DC0.s +++ b/asm/rom_8011DC0.s @@ -10934,7 +10934,7 @@ sub_801B1E8: @ 801B1E8 ldr r0, [r0] ldr r1, =0x00000bec adds r0, r1 - bl sub_816534C + bl ClearEReaderTrainer pop {r0} bx r0 .pool diff --git a/data/battle_tower.s b/data/battle_tower.s index 296db3577..63eec4347 100644 --- a/data/battle_tower.s +++ b/data/battle_tower.s @@ -33,7 +33,7 @@ gTowerMaleTrainerGfxIds:: @ 85DCF0E gTowerFemaleTrainerGfxIds:: @ 85DCF2C .byte 0x14, 0x35, 0x22, 0x28, 0x14, 0x2d, 0x2f, 0x0e, 0x12, 0x16, 0x39, 0x34, 0x34, 0x0e, 0x22, 0x34, 0x20, 0x14, 0x20, 0x2f -gUnknown_085DCF40:: @ 85DCF40 +sRubyFacilityClassToEmerald:: @ 85DCF40 .byte 0x00, 0x0b, 0x01, 0x01, 0x02, 0x06, 0x03, 0x0d, 0x04, 0x0e, 0x05, 0x0f, 0x06, 0x10, 0x07, 0x11, 0x08, 0x03, 0x09, 0x12, 0x0a, 0x0c, 0x0b, 0x13, 0x0c, 0x14, 0x0d, 0x15, 0x0e, 0x17, 0x0f, 0x07 .byte 0x10, 0x0a, 0x11, 0x19, 0x12, 0x1a, 0x13, 0x1b, 0x14, 0x1d, 0x15, 0x1e, 0x16, 0x1f, 0x17, 0x20, 0x18, 0x21, 0x19, 0x22, 0x1a, 0x23, 0x1b, 0x24, 0x1c, 0x25, 0x1d, 0x26, 0x1e, 0x27, 0x1f, 0x28 .byte 0x20, 0x29, 0x21, 0x2a, 0x22, 0x09, 0x23, 0x16, 0x24, 0x2b, 0x25, 0x2c, 0x26, 0x2d, 0x27, 0x2e, 0x28, 0x2f, 0x29, 0x30, 0x2a, 0x31, 0x2b, 0x32, 0x2c, 0x33, 0x2d, 0x34, 0x2e, 0x04, 0x2f, 0x35 @@ -640,7 +640,7 @@ gUnknown_085DD690:: @ 85DD690 .4byte gUnknown_085DD0F0 .4byte gUnknown_085DD104 -gUnknown_085DD6D0:: @ 85DD6D0 +sStevenMons:: @ 85DD6D0 .byte 0x8f, 0x01, 0x1f, 0x2a, 0x02 gUnknown_085DD6D5:: @ 85DD6D5 @@ -685,7 +685,7 @@ gUnknown_085DF96C:: @ 85DF96C .4byte sub_81620F4 .4byte ChooseNextBattleTowerTrainer .4byte sub_81621C0 - .4byte sub_816502C + .4byte AwardBattleTowerRibbons .4byte SaveBattleTowerProgress .4byte sub_8163914 .4byte nullsub_61 diff --git a/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc b/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc index 1ecf08399..eb21ead54 100644 --- a/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc +++ b/data/maps/SootopolisCity_MysteryEventsHouse_B1F/scripts.inc @@ -15,7 +15,7 @@ SootopolisCity_MysteryEventsHouse_B1F_EventScript_227E68:: @ 8227E68 lockall applymovement 255, SootopolisCity_MysteryEventsHouse_B1F_Movement_227EF3 waitmovement 0 - special sub_8165360 + special CopyEReaderTrainerGreeting msgbox gStringVar4, 4 closemessage setvar VAR_0x8004, SPECIAL_BATTLE_EREADER diff --git a/data/specials.inc b/data/specials.inc index 09f74cb51..08e12e5e0 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -246,7 +246,7 @@ gSpecials:: @ 81DBA64 def_special sub_8161F74 def_special CallBattleDomeFunction def_special sub_8195960 - def_special sub_8165360 + def_special CopyEReaderTrainerGreeting def_special DoSpecialTrainerBattle def_special sub_81A5238 def_special sub_81A5E74 diff --git a/include/battle_tower.h b/include/battle_tower.h index a47007122..4b68be923 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -7,15 +7,14 @@ struct RSBattleTowerRecord { - /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 - /*0x01*/ u8 trainerClass; + /*0x00*/ u8 lvlMode; // 0 = level 50, 1 = level 100 + /*0x01*/ u8 facilityClass; /*0x02*/ u16 winStreak; /*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1]; /*0x0C*/ u8 trainerId[4]; /*0x10*/ u16 greeting[6]; /*0x1C*/ struct UnknownPokemonStruct party[3]; /*0xA0*/ u32 checksum; - /*0xA4*/ u16 unk_11c8; }; union BattleTowerRecord @@ -54,12 +53,14 @@ extern const struct FacilityMon *gFacilityTrainerMons; u16 GetCurrentBattleTowerWinStreak(u8, u8); void sub_81659DC(struct RSBattleTowerRecord *a0, struct RSBattleTowerRecord *a1); -bool32 sub_816587C(union BattleTowerRecord *, union BattleTowerRecord *); +bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct EmeraldBattleTowerRecord *dst); void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *); -void PutNewBattleTowerRecord(union BattleTowerRecord *); +void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm); void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId); void FrontierSpeechToString(const u16 *words); void GetFrontierTrainerName(u8 *dest, u16 trainerIdx); void GetEreaderTrainerName(u8 *dest); +void FillFrontierTrainerParty(u8 monsCount); +void FillFrontierTrainersParties(u8 monsCount); #endif //GUARD_BATTLE_TOWER_H diff --git a/include/global.h b/include/global.h index 6840d5fe2..a7b50278c 100644 --- a/include/global.h +++ b/include/global.h @@ -288,7 +288,7 @@ struct Apprentice u8 lvlMode:2; // + 1 u8 field_1; u8 number; - struct ApprenticeMon monData[3]; + struct ApprenticeMon party[3]; u16 easyChatWords[6]; u8 playerId[4]; u8 playerName[PLAYER_NAME_LENGTH]; @@ -383,8 +383,8 @@ struct BattleFrontier /*0x738*/ struct EmeraldBattleTowerRecord towerRecords[5]; // From record mixing. /*0xBD4*/ u16 field_BD4; /*0xBD6*/ u16 field_BD6; - /*0xBD8*/ u8 field_BD8[11]; - /*0xBE3*/ u8 field_BE3[8]; + /*0xBD8*/ u8 field_BD8[PLAYER_NAME_LENGTH + 1]; + /*0xBE3*/ u8 field_BE0[POKEMON_NAME_LENGTH + 1]; /*0xBEB*/ u8 field_BEB; /*0xBEC*/ struct BattleTowerEReaderTrainer ereaderTrainer; /*0xCA8*/ u8 field_CA8; @@ -395,15 +395,12 @@ struct BattleFrontier /*0xCA9*/ u8 field_CA9_d:1; // 0x20 /*0xCA9*/ u8 field_CA9_e:1; // 0x40 /*0xCA9*/ u8 field_CA9_f:1; // 0x80 - /*0xCAA*/ u16 field_CAA[3]; + /*0xCAA*/ u16 selectedPartyMons[3]; /*0xCB0*/ u16 field_CB0; /*0xCB2*/ u16 curChallengeBattleNum; // In case of battle pyramid, the floor. - /*0xCB4*/ u16 battledTrainerIds[17]; - u16 field_CD6; - u16 field_CD8; - u16 field_CDA; + /*0xCB4*/ u16 field_CB4[20]; /*0xCDC*/ u32 field_CDC; - /*0xCE0*/ u16 field_CE0[4][2]; + /*0xCE0*/ u16 winStreaks[4][2]; /*0xCF0*/ u16 field_CF0[2]; /*0xCF4*/ u16 field_CF4[2]; /*0xCF8*/ u16 field_CF8[2]; diff --git a/src/battle_setup.c b/src/battle_setup.c index b5ae0d6ea..c18176706 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -31,6 +31,7 @@ #include "string_util.h" #include "overworld.h" #include "field_weather.h" +#include "battle_tower.h" #include "gym_leader_rematch.h" #include "constants/map_types.h" #include "constants/battle_frontier.h" @@ -67,8 +68,6 @@ extern u16 sub_81D6180(u8 localId); extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjId); extern bool8 GetTrainerHillTrainerFlag(u8 eventObjId); extern bool8 sub_81D5C18(void); -extern void sub_816306C(u8 a0); -extern void sub_8163048(u8 a0); extern void sub_81A9B04(void); extern void sub_81D639C(void); extern void sub_81D6384(void); @@ -885,8 +884,8 @@ u8 sub_80B100C(s32 arg0) return sUnknown_0854FE98[Random() % ARRAY_COUNT(sUnknown_0854FE98)]; } - var = gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 0] - + gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 1]; + var = gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 0] + + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 1]; return sUnknown_0854FE98[var % ARRAY_COUNT(sUnknown_0854FE98)]; } @@ -1264,7 +1263,7 @@ void BattleSetup_StartTrainerBattle(void) if (gNoOfApproachingTrainers == 2) { - sub_816306C(1); + FillFrontierTrainersParties(1); ZeroMonData(&gEnemyParty[1]); ZeroMonData(&gEnemyParty[2]); ZeroMonData(&gEnemyParty[4]); @@ -1272,7 +1271,7 @@ void BattleSetup_StartTrainerBattle(void) } else { - sub_8163048(1); + FillFrontierTrainerParty(1); ZeroMonData(&gEnemyParty[1]); ZeroMonData(&gEnemyParty[2]); } diff --git a/src/battle_tower.c b/src/battle_tower.c index 75253792e..25a46d073 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -18,6 +18,10 @@ #include "trainer_see.h" #include "new_game.h" #include "string_util.h" +#include "data2.h" +#include "link.h" +#include "field_message_box.h" +#include "tv.h" #include "constants/battle_frontier.h" #include "constants/trainers.h" #include "constants/event_objects.h" @@ -44,21 +48,23 @@ extern const u8 gUnknown_085DF9EC[]; extern const u16 gBattleFrontierHeldItems[]; // This file's functions. -void sub_8164ED8(void); +void ValidateBattleTowerRecordChecksums(void); void SaveCurrentWinStreak(void); void sub_8165B20(void); void sub_8165E18(void); -void sub_816537C(void); -void sub_8164FB8(struct EmeraldBattleTowerRecord *record); +void CopyEReaderTrainerFarewellMessage(void); +void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record); u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode); -void sub_816534C(void *); u16 sub_8162548(u8, u8); -void sub_81630C4(u16 trainerId, u8 firstMonId, u8 monCount); +static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount); void sub_8165EA4(u16 trainerId, u8 firstMonId, u8 monCount); void sub_81635D4(u16 trainerId, u8 firstMonId); void sub_816379C(u16 trainerId, u8 firstMonId); u8 GetFrontierTrainerFixedIvs(u16 trainerId); void sub_8165404(u16 trainerId); +void sub_8165B88(u8 *dst, u16 trainerId); +void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer); +void ClearEReaderTrainer(struct BattleTowerEReaderTrainer *ereaderTrainer); // code void sub_8161F74(void) @@ -77,9 +83,9 @@ void sub_8161F94(void) gSaveBlock2Ptr->frontier.field_CA9_b = 0; sub_81A3ACC(); if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_085DF9AC[battleMode][lvlMode])) - gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] = 0; + gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] = 0; - sub_8164ED8(); + ValidateBattleTowerRecordChecksums(); saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); gTrainerBattleOpponent_A = 0; } @@ -115,7 +121,7 @@ void sub_81620F4(void) case 0: break; case 1: - gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] = gSpecialVar_0x8006; + gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] = gSpecialVar_0x8006; break; case 2: if (gSpecialVar_0x8006) @@ -132,7 +138,7 @@ void sub_81620F4(void) void sub_81621C0(void) { if (gTrainerBattleOpponent_A == BATTLE_TOWER_EREADER_TRAINER_ID) - sub_816534C(&gSaveBlock2Ptr->frontier.ereaderTrainer); + ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); if (gSaveBlock2Ptr->frontier.field_D04 < 9999) gSaveBlock2Ptr->frontier.field_D04++; @@ -227,15 +233,15 @@ void ChooseNextBattleTowerTrainer(void) if (battleMode == FRONTIER_MODE_MULTIS || battleMode == FRONTIER_MODE_LINK_MULTIS) { id = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.battledTrainerIds[id * 2]; - gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.battledTrainerIds[id * 2 + 1]; + gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.field_CB4[id * 2]; + gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.field_CB4[id * 2 + 1]; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); } else if (ChooseSpecialBattleTowerTrainer()) { SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; } else { @@ -247,7 +253,7 @@ void ChooseNextBattleTowerTrainer(void) // Ensure trainer wasn't previously fought in this challenge. for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) { - if (gSaveBlock2Ptr->frontier.battledTrainerIds[i] == id) + if (gSaveBlock2Ptr->frontier.field_CB4[i] == id) break; } if (i == gSaveBlock2Ptr->frontier.curChallengeBattleNum) @@ -257,7 +263,7 @@ void ChooseNextBattleTowerTrainer(void) gTrainerBattleOpponent_A = id; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 7) - gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; } } } @@ -522,13 +528,13 @@ u8 GetBattleFacilityTrainerGfxId(u16 trainerId) } } -void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) +void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) { u16 slotValues[6]; u16 slotIds[6]; s32 i, j, k; s32 slotsCount = 0; - struct EmeraldBattleTowerRecord *newRecordEm = &newRecord->emerald; + struct EmeraldBattleTowerRecord *newRecord = newRecordEm; // Needed to match. // Find a record slot of the same player and replace it. for (i = 0; i < 5; i++) @@ -536,7 +542,7 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) k = 0; for (j = 0; j < 4; j++) { - if (gSaveBlock2Ptr->frontier.towerRecords[i].trainerId[j] != newRecordEm->trainerId[j]) + if (gSaveBlock2Ptr->frontier.towerRecords[i].trainerId[j] != newRecord->trainerId[j]) break; } if (j == 4) @@ -544,9 +550,9 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) for (k = 0; k < PLAYER_NAME_LENGTH; k++) { // BUG: Wrong variable used, 'j' instead of 'k'. - if (gSaveBlock2Ptr->frontier.towerRecords[i].name[j] != newRecordEm->name[j]) + if (gSaveBlock2Ptr->frontier.towerRecords[i].name[j] != newRecord->name[j]) break; - if (newRecordEm->name[j] == EOS) + if (newRecord->name[j] == EOS) { k = PLAYER_NAME_LENGTH; break; @@ -559,7 +565,7 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) } if (i < 5) { - gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecordEm; + gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord; return; } @@ -571,7 +577,7 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) } if (i < 5) { - gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecordEm; + gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord; return; } @@ -607,7 +613,7 @@ void PutNewBattleTowerRecord(union BattleTowerRecord *newRecord) } i = Random() % slotsCount; - gSaveBlock2Ptr->frontier.towerRecords[slotIds[i]] = *newRecordEm; + gSaveBlock2Ptr->frontier.towerRecords[slotIds[i]] = *newRecord; } u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) @@ -822,17 +828,17 @@ bool8 IsFrontierTrainerFemale(u16 trainerId) return FALSE; } -void sub_8163048(u8 monsCount) +void FillFrontierTrainerParty(u8 monsCount) { ZeroEnemyPartyMons(); - sub_81630C4(gTrainerBattleOpponent_A, 0, monsCount); + FillTrainerParty(gTrainerBattleOpponent_A, 0, monsCount); } -void sub_816306C(u8 monsCount) +void FillFrontierTrainersParties(u8 monsCount) { ZeroEnemyPartyMons(); - sub_81630C4(gTrainerBattleOpponent_A, 0, monsCount); - sub_81630C4(gTrainerBattleOpponent_B, 3, monsCount); + FillTrainerParty(gTrainerBattleOpponent_A, 0, monsCount); + FillTrainerParty(gTrainerBattleOpponent_B, 3, monsCount); } void sub_81630A0(u8 monsCount) @@ -841,7 +847,7 @@ void sub_81630A0(u8 monsCount) sub_8165EA4(gTrainerBattleOpponent_A, 0, monsCount); } -void sub_81630C4(u16 trainerId, u8 firstMonId, u8 monCount) +static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) { s32 i, j; u16 chosenMonIndices[4]; @@ -983,15 +989,15 @@ void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) for (i = 0; i != 3; i++) { - CreateMonWithEVSpread(&gEnemyParty[firstMonId + i], apprentice->monData[i].species, level, fixedIV, 8); + CreateMonWithEVSpread(&gEnemyParty[firstMonId + i], apprentice->party[i].species, level, fixedIV, 8); friendship = 0xFF; for (j = 0; j < 4; j++) { - if (apprentice->monData[i].moves[j] == MOVE_FRUSTRATION) + if (apprentice->party[i].moves[j] == MOVE_FRUSTRATION) friendship = 0; } SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship); - SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &apprentice->monData[i].item); + SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &apprentice->party[i].item); } } @@ -1053,7 +1059,7 @@ void sub_81635D4(u16 trainerId, u8 firstMonId) { u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; // Unused variable. u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); - u8 challengeNum = gSaveBlock2Ptr->frontier.field_CE0[battleMode][0] / 7; + u8 challengeNum = gSaveBlock2Ptr->frontier.winStreaks[battleMode][0] / 7; if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6) fixedIV = sub_81A6CA8(challengeNum, 0); else @@ -1201,7 +1207,7 @@ static void HandleSpecialTrainerBattleEnd(void) } break; case SPECIAL_BATTLE_EREADER: - sub_816537C(); + CopyEReaderTrainerFarewellMessage(); break; } @@ -1233,21 +1239,21 @@ void DoSpecialTrainerBattle(void) switch (VarGet(VAR_FRONTIER_BATTLE_MODE)) { case FRONTIER_MODE_SINGLES: - sub_8163048(3); + FillFrontierTrainerParty(3); break; case FRONTIER_MODE_DOUBLES: - sub_8163048(4); + FillFrontierTrainerParty(4); gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; break; case FRONTIER_MODE_MULTIS: - sub_816306C(2); - gPartnerTrainerId = gSaveBlock2Ptr->frontier.field_CD6; + FillFrontierTrainersParties(2); + gPartnerTrainerId = gSaveBlock2Ptr->frontier.field_CB4[17]; sub_8165404(gPartnerTrainerId); gBattleTypeFlags |= BATTLE_TYPE_DOUBLE | BATTLE_TYPE_INGAME_PARTNER | BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS; break; case FRONTIER_MODE_LINK_MULTIS: gBattleTypeFlags |= BATTLE_TYPE_DOUBLE | BATTLE_TYPE_LINK | BATTLE_TYPE_MULTI | BATTLE_TYPE_x800000; - sub_816306C(2); + FillFrontierTrainersParties(2); break; } CreateTask(Task_StartBattleAfterTransition, 1); @@ -1279,7 +1285,7 @@ void DoSpecialTrainerBattle(void) if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES) gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) - sub_8163048(2); + FillFrontierTrainerParty(2); CreateTask(Task_StartBattleAfterTransition, 1); sub_806E694(0); BattleTransition_StartOnField(sub_80B100C(3)); @@ -1289,7 +1295,7 @@ void DoSpecialTrainerBattle(void) if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES) gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) - sub_8163048(3); + FillFrontierTrainerParty(3); else sub_81630A0(3); CreateTask(Task_StartBattleAfterTransition, 1); @@ -1299,7 +1305,7 @@ void DoSpecialTrainerBattle(void) case SPECIAL_BATTLE_ARENA: gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_ARENA; if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) - sub_8163048(3); + FillFrontierTrainerParty(3); else sub_81630A0(3); CreateTask(Task_StartBattleAfterTransition, 1); @@ -1317,21 +1323,21 @@ void DoSpecialTrainerBattle(void) break; case SPECIAL_BATTLE_PIKE_SINGLE: gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER; - sub_8163048(3); + FillFrontierTrainerParty(3); CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(sub_80B100C(7)); break; case SPECIAL_BATTLE_PYRAMID: gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_PYRAMID; - sub_8163048(3); + FillFrontierTrainerParty(3); CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(sub_80B100C(10)); break; case SPECIAL_BATTLE_PIKE_DOUBLE: gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS; - sub_816306C(1); + FillFrontierTrainersParties(1); CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(sub_80B100C(7)); @@ -1357,8 +1363,8 @@ void SaveCurrentWinStreak(void) u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); u16 winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode); - if (gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] < winStreak) - gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] = winStreak; + if (gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] < winStreak) + gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] = winStreak; } void sub_8163EE4(void) @@ -1367,7 +1373,7 @@ void sub_8163EE4(void) u8 lvlMode, battleMode, class; struct EmeraldBattleTowerRecord *playerRecord = &gSaveBlock2Ptr->frontier.towerPlayer; - sub_8164FB8(playerRecord); + ClearBattleTowerRecord(playerRecord); lvlMode = gSaveBlock2Ptr->frontier.lvlMode; battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); if (gSaveBlock2Ptr->playerGender != MALE) @@ -1399,8 +1405,8 @@ void sub_8163EE4(void) for (i = 0; i < 4; i++) { - if (gSaveBlock2Ptr->frontier.field_CAA[i] != 0) - sub_80686FC(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], &playerRecord->party[i]); + if (gSaveBlock2Ptr->frontier.selectedPartyMons[i] != 0) + sub_80686FC(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], &playerRecord->party[i]); } playerRecord->language = gGameLanguage; @@ -1412,7 +1418,7 @@ void SaveBattleTowerProgress(void) { u16 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); - s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] / 7); + s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] / 7); if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0)) sub_8163EE4(); @@ -1443,7 +1449,7 @@ void sub_81640E0(u16 trainerId) count = 0; for (i = 0; i < 3; i++) { - u16 apprenticeSpecies = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].monData[i].species; + u16 apprenticeSpecies = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].party[i].species; if (apprenticeSpecies != species1 && apprenticeSpecies != species2) { validSpecies[count] = i; @@ -1502,43 +1508,45 @@ void sub_81642A0(void) eventObjTemplates = gSaveBlock1Ptr->eventObjectTemplates; lvlMode = gSaveBlock2Ptr->frontier.lvlMode; battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); - challengeNum = gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] / 7; species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); level = GetFacilityEnemyMonLevel(); - for (j = 0; j < 6; j++) + j = 0; + do { do { trainerId = sub_8162548(challengeNum, 0); for (i = 0; i < j; i++) { - if (gSaveBlock2Ptr->frontier.battledTrainerIds[i] == trainerId) + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) break; - if (gFacilityTrainers[gSaveBlock2Ptr->frontier.battledTrainerIds[i]].facilityClass == gFacilityTrainers[trainerId].facilityClass) + if (gFacilityTrainers[gSaveBlock2Ptr->frontier.field_CB4[i]].facilityClass == gFacilityTrainers[trainerId].facilityClass) break; } } while (i != j); - gSaveBlock2Ptr->frontier.battledTrainerIds[j] = trainerId; - } + gSaveBlock2Ptr->frontier.field_CB4[j] = trainerId; + j++; + } while (j < 6); r10 = 8; for (i = 0; i < 6; i++) { - trainerId = gSaveBlock2Ptr->frontier.battledTrainerIds[i]; + trainerId = gSaveBlock2Ptr->frontier.field_CB4[i]; eventObjTemplates[i + 1].graphicsId = GetBattleFacilityTrainerGfxId(trainerId); for (j = 0; j < 2; j++) { while (1) { monPoolId = RandomizeFacilityTrainerMonId(trainerId); - if (j % 2 != 0 && gFacilityTrainerMons[gSaveBlock2Ptr->frontier.battledTrainerIds[r10 - 1]].itemTableId == gFacilityTrainerMons[monPoolId].itemTableId) + if (j % 2 != 0 && gFacilityTrainerMons[gSaveBlock2Ptr->frontier.field_CB4[r10 - 1]].itemTableId == gFacilityTrainerMons[monPoolId].itemTableId) continue; for (k = 8; k < r10; k++) { - if (gFacilityTrainerMons[gSaveBlock2Ptr->frontier.battledTrainerIds[k]].species == gFacilityTrainerMons[monPoolId].species) + if (gFacilityTrainerMons[gSaveBlock2Ptr->frontier.field_CB4[k]].species == gFacilityTrainerMons[monPoolId].species) break; if (species1 == gFacilityTrainerMons[monPoolId].species) break; @@ -1549,7 +1557,7 @@ void sub_81642A0(void) break; } - gSaveBlock2Ptr->frontier.battledTrainerIds[r10] = monPoolId; + gSaveBlock2Ptr->frontier.field_CB4[r10] = monPoolId; r10++; } } @@ -1565,8 +1573,8 @@ void sub_81642A0(void) k = 0; for (j = 0; j < 3; j++) { - if (species1 != gSaveBlock2Ptr->apprentices[i].monData[j].species - && species2 != gSaveBlock2Ptr->apprentices[i].monData[j].species) + if (species1 != gSaveBlock2Ptr->apprentices[i].party[j].species + && species2 != gSaveBlock2Ptr->apprentices[i].party[j].species) { k++; } @@ -1580,10 +1588,10 @@ void sub_81642A0(void) } if (r10 != 0) { - gSaveBlock2Ptr->frontier.battledTrainerIds[6] = spArray[Random() % r10]; - eventObjTemplates[7].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.battledTrainerIds[6]); + gSaveBlock2Ptr->frontier.field_CB4[6] = spArray[Random() % r10]; + eventObjTemplates[7].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.field_CB4[6]); FlagClear(FLAG_HIDE_BATTLE_TOWER_MULTI_BATTLE_PARTNER_ALT_1); - sub_81640E0(gSaveBlock2Ptr->frontier.battledTrainerIds[6]); + sub_81640E0(gSaveBlock2Ptr->frontier.field_CB4[6]); } r10 = 0; @@ -1623,9 +1631,716 @@ void sub_81642A0(void) } if (r10 != 0) { - gSaveBlock2Ptr->frontier.battledTrainerIds[7] = spArray[Random() % r10]; - eventObjTemplates[8].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.battledTrainerIds[7]); + gSaveBlock2Ptr->frontier.field_CB4[7] = spArray[Random() % r10]; + eventObjTemplates[8].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.field_CB4[7]); FlagClear(FLAG_HIDE_BATTLE_TOWER_MULTI_BATTLE_PARTNER_ALT_2); - sub_8164188(gSaveBlock2Ptr->frontier.battledTrainerIds[7]); + sub_8164188(gSaveBlock2Ptr->frontier.field_CB4[7]); + } +} + +void sub_81646BC(u16 trainerId, u16 monPoolId) +{ + u16 move = 0; + u16 species = 0; + GetFacilityEnemyMonLevel(); // Pointless function call. + + if (trainerId != BATTLE_TOWER_EREADER_TRAINER_ID) + { + if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + move = gFacilityTrainerMons[monPoolId].moves[0]; + species = gFacilityTrainerMons[monPoolId].species; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + move = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].moves[0]; + species = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].species; + } + else + { + s32 i; + + move = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].moves[0]; + species = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].species; + for (i = 0; i < PLAYER_NAME_LENGTH; i++) + gStringVar3[i] = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].playerName[i]; + gStringVar3[i] = EOS; + ConvertInternationalString(gStringVar3, gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].language); + } + } + + StringCopy(gStringVar1, gMoveNames[move]); + StringCopy(gStringVar2, gSpeciesNames[species]); +} + +struct +{ + u32 facilityClass; + const u8 *const *strings; +} extern const gUnknown_085DD500[50]; + +extern const u8 *const *const gUnknown_085DD690[]; +extern const u8 gUnknown_085DFA42[4]; + +void sub_8164828(void) +{ + s32 i, j, arrId; + s32 monPoolId; + s32 level = GetFacilityEnemyMonLevel(); // Unused variable. + s32 challengeNum = sub_81A39C4() / 7; + s32 k = gSpecialVar_LastTalked - 2; + s32 trainerId = gSaveBlock2Ptr->frontier.field_CB4[k]; + + for (arrId = 0; arrId < ARRAY_COUNT(gUnknown_085DD500); arrId++) + { + if (gUnknown_085DD500[arrId].facilityClass == GetFrontierTrainerFacilityClass(trainerId)) + break; + } + + switch (gSpecialVar_0x8005) + { + case 0: + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + return; + if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + GetFrontierTrainerName(gStringVar1, trainerId); + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + GetFrontierTrainerName(gStringVar1, trainerId); + } + else + { + s32 i; + for (i = 0; i < PLAYER_NAME_LENGTH; i++) + gStringVar1[i] = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].playerName[i]; + gStringVar1[i] = EOS; + ConvertInternationalString(gStringVar1, gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].language); + ConvertIntToDecimalStringN(gStringVar2, gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].number, STR_CONV_MODE_LEFT_ALIGN, 3); + GetFrontierTrainerName(gStringVar3, trainerId); + } + break; + case 1: + monPoolId = gSaveBlock2Ptr->frontier.field_CB4[8 + k * 2]; + sub_81646BC(trainerId, monPoolId); + break; + case 2: + monPoolId = gSaveBlock2Ptr->frontier.field_CB4[9 + k * 2]; + sub_81646BC(trainerId, monPoolId); + break; + case 3: + gPartnerTrainerId = trainerId; + if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + gSaveBlock2Ptr->frontier.field_CB4[18] = gSaveBlock2Ptr->frontier.field_CB4[8 + k * 2]; + gSaveBlock2Ptr->frontier.field_CB4[19] = gSaveBlock2Ptr->frontier.field_CB4[9 + k * 2]; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + gSaveBlock2Ptr->frontier.field_CB4[18] = gUnknown_03006298[2]; + gSaveBlock2Ptr->frontier.field_CB4[19] = gUnknown_03006298[3]; + } + else + { + gSaveBlock2Ptr->frontier.field_CB4[18] = gUnknown_03006298[0]; + gSaveBlock2Ptr->frontier.field_CB4[19] = gUnknown_03006298[1]; + } + for (k = 0; k < 14; k++) + { + while (1) + { + i = sub_8162548(challengeNum, k / 2); + if (gPartnerTrainerId == i) + continue; + + for (j = 0; j < k; j++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[j] == i) + break; + } + if (j == k) + break; + } + gSaveBlock2Ptr->frontier.field_CB4[k] = i; + } + gSaveBlock2Ptr->frontier.field_CB4[17] = trainerId; + break; + case 4: + break; + } + + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + return; + + if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + ShowFieldMessage(gUnknown_085DD500[arrId].strings[gSpecialVar_0x8005]); + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + ShowFieldMessage(gUnknown_085DD500[arrId].strings[gSpecialVar_0x8005]); + } + else + { + u8 id = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id; + ShowFieldMessage(gUnknown_085DD690[id][gSpecialVar_0x8005]); + } +} + +void sub_8164B74(void) +{ + s32 challengeNum; + s32 i, j; + s32 trainerId = 0; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + u32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + GetMultiplayerId(); // Yet another pointless function call. + + switch (gSpecialVar_Result) + { + case 0: + if (battleMode == FRONTIER_MODE_LINK_MULTIS) + { + challengeNum = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] / 7; + if (sub_800A520()) + { + SendBlock(bitmask_all_link_players_but_self(), &challengeNum, sizeof(challengeNum)); + gSpecialVar_Result = 1; + } + } + else + { + gSpecialVar_Result = 6; + } + break; + case 1: + if ((GetBlockReceivedStatus() & 3) == 3) + { + ResetBlockReceivedFlags(); + if (gBlockRecvBuffer[0][0] > gBlockRecvBuffer[1][0]) + challengeNum = gBlockRecvBuffer[0][0]; + else + challengeNum = gBlockRecvBuffer[1][0]; + for (i = 0; i < 14; i++) + { + do + { + trainerId = sub_8162548(challengeNum, i / 2); + for (j = 0; j < i; j++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[j] == trainerId) + break; + } + } while (i != j); + if (i == j) // This condition is always true, because of the loop above. + gSaveBlock2Ptr->frontier.field_CB4[i] = trainerId; + } + gSpecialVar_Result = 2; + } + break; + case 2: + if (sub_800A520()) + { + SendBlock(bitmask_all_link_players_but_self(), &gSaveBlock2Ptr->frontier.field_CB4, sizeof(gSaveBlock2Ptr->frontier.field_CB4)); + gSpecialVar_Result = 3; + } + break; + case 3: + if ((GetBlockReceivedStatus() & 3) == 3) + { + ResetBlockReceivedFlags(); + memcpy(&gSaveBlock2Ptr->frontier.field_CB4, gBlockRecvBuffer, sizeof(gSaveBlock2Ptr->frontier.field_CB4)); + gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.field_CB4[battleNum * 2]; + gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.field_CB4[battleNum * 2 + 1]; + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); + if (gReceivedRemoteLinkPlayers != 0 && gWirelessCommType == 0) + gSpecialVar_Result = 4; + else + gSpecialVar_Result = 6; + } + break; + case 4: + sub_800AC34(); + gSpecialVar_Result = 5; + break; + case 5: + if (gReceivedRemoteLinkPlayers == 0) + { + gSpecialVar_Result = 6; + } + break; + case 6: + return; + } +} + +void sub_8164DCC(void) +{ + if (gWirelessCommType != 0) + sub_800AC34(); +} + +void sub_8164DE4(void) +{ + SetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.field_CB4[17], 0xF); +} + +void sub_8164E04(void) +{ + s32 i; + u8 text[32]; + + if (VarGet(VAR_FRONTIER_BATTLE_MODE) != FRONTIER_MODE_SINGLES) + return; + + GetFrontierTrainerName(text, gTrainerBattleOpponent_A); + StripExtCtrlCodes(text); + StringCopy(gSaveBlock2Ptr->frontier.field_BD8, text); + sub_8165B88(&gSaveBlock2Ptr->frontier.field_BEB, gTrainerBattleOpponent_A); + gSaveBlock2Ptr->frontier.field_BD6 = GetMonData(&gEnemyParty[gBattlerPartyIndexes[1]], MON_DATA_SPECIES, NULL); + gSaveBlock2Ptr->frontier.field_BD4 = GetMonData(&gPlayerParty[gBattlerPartyIndexes[0]], MON_DATA_SPECIES, NULL); + for (i = 0; i < POKEMON_NAME_LENGTH + 1; i++) + gSaveBlock2Ptr->frontier.field_BE0[i] = gBattleMons[0].nickname[i]; + gSaveBlock2Ptr->frontier.field_D06 = gBattleOutcome; +} + +void ValidateBattleTowerRecordChecksums(void) +{ + s32 i, j; + u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerPlayer); + u32 checksum = 0; + + for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself. + { + checksum += record[j]; + } + if (gSaveBlock2Ptr->frontier.towerPlayer.checksum != checksum) + ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerPlayer); + + for (i = 0; i < 5; i++) + { + record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]); + checksum = 0; + for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself. + { + checksum += record[j]; + } + if (gSaveBlock2Ptr->frontier.towerRecords[i].checksum != checksum) + ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerRecords[i]); + } +} + +void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *record) +{ + u32 i; + + record->checksum = 0; + for (i = 0; i < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; i++) // - 4, because of the last field being the checksum itself. + record->checksum += ((u32 *)record)[i]; +} + +void CalcRubyBattleTowerChecksum(struct RSBattleTowerRecord *record) +{ + u32 i; + + record->checksum = 0; + for (i = 0; i < (sizeof(struct RSBattleTowerRecord) - 4) / 4; i++) // - 4, because of the last field being the checksum itself. + record->checksum += ((u32 *)record)[i]; +} + +void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record) +{ + u32 i; + + for (i = 0; i < sizeof(struct EmeraldBattleTowerRecord) / 4; i++) + ((u32 *)record)[i] = 0; +} + +u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode) +{ + u16 winStreak = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode]; + + if (winStreak > 9999) + return 9999; + else + return winStreak; +} + +u8 GetMonCountForBattleMode(u8 battleMode) +{ + u8 sp[ARRAY_COUNT(gUnknown_085DFA42)]; + memcpy(sp, gUnknown_085DFA42, sizeof(gUnknown_085DFA42)); + + if (battleMode < ARRAY_COUNT(gUnknown_085DFA42)) + return sp[battleMode]; + else + return 3; +} + +struct RibbonCounter +{ + u8 partyIndex; + u8 count; +}; + +void AwardBattleTowerRibbons(void) +{ + s32 i; + u32 partyIndex; + struct RibbonCounter ribbons[3]; // BUG: 4 Pokemon can receive ribbons in a double battle mode. + u8 ribbonType = 0; + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); + u8 monCount = GetMonCountForBattleMode(battleMode); + + if (lvlMode != FRONTIER_LVL_50) + ribbonType = MON_DATA_VICTORY_RIBBON; + else + ribbonType = MON_DATA_WINNING_RIBBON; + + gSpecialVar_Result = FALSE; + + if (GetCurrentBattleTowerWinStreak(lvlMode, battleMode) > 55) + { + for (i = 0; i < monCount; i++) + { + partyIndex = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1; + ribbons[i].partyIndex = partyIndex; + ribbons[i].count = 0; + if (!GetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], ribbonType)) + { + gSpecialVar_Result = TRUE; + SetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], ribbonType, &gSpecialVar_Result); + ribbons[i].count = GetRibbonCount(&gSaveBlock1Ptr->playerParty[partyIndex]); + } + } + } + + if (gSpecialVar_Result) + { + IncrementGameStat(GAME_STAT_RECEIVED_RIBBONS); + for (i = 1; i < monCount; i++) + { + if (ribbons[i].count > ribbons[0].count) + { + struct RibbonCounter prevBest = ribbons[0]; + ribbons[0] = ribbons[i]; + ribbons[i] = prevBest; + } + } + if (ribbons[0].count > 4) + { + sub_80EE4DC(&gSaveBlock1Ptr->playerParty[ribbons[0].partyIndex], ribbonType); + } + } +} + +// This is a leftover debugging function that is used to populate the E-Reader +// trainer with the player's current data. +void FillEReaderTrainerWithPlayerData(void) +{ + struct BattleTowerEReaderTrainer *ereaderTrainer = &gSaveBlock2Ptr->frontier.ereaderTrainer; + s32 i, j; + + if (gSaveBlock2Ptr->playerGender != MALE) + { + ereaderTrainer->facilityClass = gTowerFemaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] + gSaveBlock2Ptr->playerTrainerId[1] + + gSaveBlock2Ptr->playerTrainerId[2] + gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerFemaleFacilityClasses)]; + } + else + { + ereaderTrainer->facilityClass = gTowerMaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] + gSaveBlock2Ptr->playerTrainerId[1] + + gSaveBlock2Ptr->playerTrainerId[2] + gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerMaleFacilityClasses)]; + } + + CopyUnalignedWord(ereaderTrainer->trainerId, gSaveBlock2Ptr->playerTrainerId); + StringCopy7(ereaderTrainer->name, gSaveBlock2Ptr->playerName); + + ereaderTrainer->winStreak = 1; + + j = 7; + for (i = 0; i < 6; i++) + { + ereaderTrainer->greeting[i] = gSaveBlock1Ptr->unk2BBC[i]; + ereaderTrainer->farewellPlayerLost[i] = j; + ereaderTrainer->farewellPlayerWon[i] = j + 6; + j++; + } + + for (i = 0; i < 3; i++) + sub_80686FC(&gPlayerParty[i], &ereaderTrainer->party[i]); + + SetEReaderTrainerChecksum(ereaderTrainer); +} + +u8 GetEreaderTrainerFrontSpriteId(void) +{ + return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass]; +} + +u8 GetEreaderTrainerClassId(void) +{ + return gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass]; +} + +void GetEreaderTrainerName(u8 *trainerName) +{ + s32 i; + + for (i = 0; i < 5; i++) + trainerName[i] = gSaveBlock2Ptr->frontier.ereaderTrainer.name[i]; + + trainerName[i] = EOS; +} + +// Checks if the saved E-Reader trainer is valid. +void ValidateEReaderTrainer(void) +{ + u32 i; + u32 checksum; + struct BattleTowerEReaderTrainer *ereaderTrainer; + + gSpecialVar_Result = FALSE; + ereaderTrainer = &gSaveBlock2Ptr->frontier.ereaderTrainer; + + checksum = 0; + for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer) - 4) / 4; i++) // - 4, because of the last field being the checksum itself. + checksum |= ((u32 *)ereaderTrainer)[i]; + + if (checksum == 0) + { + gSpecialVar_Result = TRUE; + return; + } + + checksum = 0; + for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer) - 4) / 4; i++) // - 4, because of the last field being the checksum itself. + checksum += ((u32 *)ereaderTrainer)[i]; + + if (gSaveBlock2Ptr->frontier.ereaderTrainer.checksum != checksum) + { + ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); + gSpecialVar_Result = TRUE; + } +} + +void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer) +{ + s32 i; + + ereaderTrainer->checksum = 0; + for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer) - 4) / 4; i++) // - 4, because of the last field being the checksum itself. + ereaderTrainer->checksum += ((u32 *)ereaderTrainer)[i]; +} + +void ClearEReaderTrainer(struct BattleTowerEReaderTrainer *ereaderTrainer) +{ + u32 i; + + for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer)) / 4; i++) + ((u32 *)ereaderTrainer)[i] = 0; +} + +void CopyEReaderTrainerGreeting(void) +{ + FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.greeting); +} + +void CopyEReaderTrainerFarewellMessage(void) +{ + if (gBattleOutcome == B_OUTCOME_DREW) + gStringVar4[0] = EOS; + else if (gBattleOutcome == B_OUTCOME_WON) + FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.farewellPlayerWon); + else + FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.farewellPlayerLost); +} + +void sub_81653CC(void) +{ + if (gSaveBlock2Ptr->frontier.field_CA8 == 1) + sub_80F01B8(); + if (FlagGet(FLAG_0x077) == TRUE) + { + sub_80F01B8(); + FlagClear(FLAG_0x077); + } +} + +struct StevenMon +{ + u16 species; + u8 fixedIV; + u8 level; + u8 nature; + u8 evs[6]; + u16 moves[4]; +}; + +extern const struct StevenMon sStevenMons[3]; + +#define STEVEN_OTID 61226 + +void sub_8165404(u16 trainerId) +{ + s32 i, j; + u32 ivs, level; + u32 friendship; + u16 monPoolId; + u32 otID; + u8 trainerName[PLAYER_NAME_LENGTH + 1]; + GetFacilityEnemyMonLevel(); // Unused return variable. + + if (trainerId == TRAINER_STEVEN_PARTNER) + { + for (i = 0; i < 3; i++) + { + do + { + j = Random32(); + } while (IsShinyOtIdPersonality(STEVEN_OTID, j) || sStevenMons[i].nature != GetNatureFromPersonality(j)); + CreateMon(&gPlayerParty[3 + i], + sStevenMons[i].species, + sStevenMons[i].level, + sStevenMons[i].fixedIV, + TRUE, i, // BUG: personality was stored in the 'j' variable. As a result, Steven's pokemon do not have the intended natures. + TRUE, STEVEN_OTID); + for (j = 0; j < 6; j++) + SetMonData(&gPlayerParty[3 + i], MON_DATA_HP_EV + j, &sStevenMons[i].evs[j]); + for (j = 0; j < 4; j++) + SetMonMoveSlot(&gPlayerParty[3 + i], sStevenMons[i].moves[j], j); + SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, gTrainers[TRAINER_STEVEN].trainerName); + j = MALE; + SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j); + CalculateMonStats(&gPlayerParty[3 + i]); + } + } + else if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + // Scrapped, lol. + trainerName[0] = gGameLanguage; + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + level = GetFacilityEnemyMonLevel(); + ivs = GetFrontierTrainerFixedIvs(trainerId); + otID = Random32(); + for (i = 0; i < 2; i++) + { + monPoolId = gSaveBlock2Ptr->frontier.field_CB4[i + 18]; + CreateMonWithEVSpreadPersonalityOTID(&gPlayerParty[3 + i], + gFacilityTrainerMons[monPoolId].species, + level, + gFacilityTrainerMons[monPoolId].nature, + ivs, + gFacilityTrainerMons[monPoolId].evSpread, + otID); + friendship = 0xFF; + for (j = 0; j < 4; j++) + { + SetMonMoveSlot(&gPlayerParty[3 + i], gFacilityTrainerMons[monPoolId].moves[j], j); + if (gFacilityTrainerMons[monPoolId].moves[j] == MOVE_FRUSTRATION) + friendship = 0; + } + SetMonData(&gPlayerParty[3 + i], MON_DATA_FRIENDSHIP, &friendship); + SetMonData(&gPlayerParty[3 + i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]); + for (j = 0; j < PLAYER_NAME_LENGTH + 1; j++) + trainerName[j] = gFacilityTrainers[trainerId].trainerName[j]; + SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, &trainerName); + j = IsFrontierTrainerFemale(trainerId); + SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j); + } + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + trainerId -= BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID; + for (i = 0; i < 2; i++) + { + struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.towerRecords[trainerId]; + struct UnknownPokemonStruct monData = record->party[gSaveBlock2Ptr->frontier.field_CB4[18 + i]]; + StringCopy(trainerName, record->name); + if (record->language == LANGUAGE_JAPANESE) + { + if (monData.nickname[0] != EXT_CTRL_CODE_BEGIN || monData.nickname[1] != EXT_CTRL_CODE_JPN) + { + monData.nickname[5] = EOS; + ConvertInternationalString(monData.nickname, LANGUAGE_JAPANESE); + } + } + else + { + if (monData.nickname[0] == EXT_CTRL_CODE_BEGIN && monData.nickname[1] == EXT_CTRL_CODE_JPN) + trainerName[5] = EOS; + } + sub_8068338(&gPlayerParty[3 + i], &monData, TRUE); + SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, trainerName); + j = IsFrontierTrainerFemale(trainerId + BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID); + SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j); + } + } + else + { + trainerId -= BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID; + for (i = 0; i < 2; i++) + { + CreateApprenticeMon(&gPlayerParty[3 + i], &gSaveBlock2Ptr->apprentices[trainerId], gSaveBlock2Ptr->frontier.field_CB4[18 + i]); + j = IsFrontierTrainerFemale(trainerId + BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID); + SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j); + } + } +} + +extern const u8 sRubyFacilityClassToEmerald[82][2]; +extern const u16 gUnknown_085DFA46[]; +extern const u16 gUnknown_085DFA52[]; + +bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct EmeraldBattleTowerRecord *dst) +{ + s32 i, validMons = 0; + + for (i = 0; i < 3; i++) + { + if (src->party[i].species) + validMons++; + } + + if (validMons != 3) + { + memset(dst, 0, sizeof(*dst)); + return FALSE; + } + else + { + dst->lvlMode = src->lvlMode; + dst->winStreak = src->winStreak; + for (i = 0; i < (signed) ARRAY_COUNT(sRubyFacilityClassToEmerald); i++) + { + if (sRubyFacilityClassToEmerald[i][0] == src->facilityClass) + break; + } + if (i != ARRAY_COUNT(sRubyFacilityClassToEmerald)) + dst->facilityClass = sRubyFacilityClassToEmerald[i][1]; + else + dst->facilityClass = FACILITY_CLASS_YOUNGSTER; + + for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) + dst->name[i] = src->name[i]; + for (i = 0; i < 4; i++) + dst->trainerId[i] = src->trainerId[i]; + for (i = 0; i < 6; i++) + dst->greeting[i] = src->greeting[i]; + for (i = 0; i < 6; i++) + dst->unk1C[i] = gUnknown_085DFA46[i]; + for (i = 0; i < 6; i++) + dst->unk28[i] = gUnknown_085DFA52[i]; + for (i = 0; i < 3; i++) + dst->party[i] = src->party[i]; + + CpuFill32(0, &dst->party[3], sizeof(dst->party[3])); + CalcEmeraldBattleTowerChecksum(dst); + return TRUE; } } diff --git a/src/record_mixing.c b/src/record_mixing.c index c9fe3fd47..11c3f2fef 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -69,6 +69,7 @@ struct PlayerRecordsRS struct EasyChatPair easyChatPairs[5]; struct RecordMixingDayCareMail dayCareMail; struct RSBattleTowerRecord battleTowerRecord; + u16 giftItem; u16 filler11C8[0x32]; }; @@ -81,7 +82,7 @@ struct PlayerRecordsEmerald /* 0x1084 */ struct EasyChatPair easyChatPairs[5]; /* 0x10ac */ struct RecordMixingDayCareMail dayCareMail; /* 0x1124 */ struct EmeraldBattleTowerRecord battleTowerRecord; - /* 0x1210 */ u16 unk_1210; + /* 0x1210 */ u16 giftItem; /* 0x1214 */ LilycoveLady lilycoveLady; /* 0x1254 */ struct Apprentice apprentice[2]; /* 0x12dc */ struct UnkRecordMixingStruct2 unk_12dc; @@ -132,7 +133,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t, u8); static void ReceiveLilycoveLadyData(LilycoveLady *, size_t, u8); static void sub_80E7B2C(const u8 *); static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); -static void sub_80E7F68(u16 *item, u8 which); +static void ReceiveGiftItem(u16 *item, u8 which); static void sub_80E7FF8(u8 taskId); static void sub_80E8110(struct Apprentice *arg0, struct Apprentice *arg1); static void ReceiveApprenticeData(struct Apprentice *arg0, size_t arg1, u32 arg2); @@ -215,7 +216,7 @@ static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest) sub_81659DC(sBattleTowerSave, &dest->battleTowerRecord); if (GetMultiplayerId() == 0) - dest->battleTowerRecord.unk_11c8 = GetRecordMixingGift(); + dest->giftItem = GetRecordMixingGift(); } static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest) @@ -234,7 +235,7 @@ static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest) SanitizeRubyBattleTowerRecord(&dest->battleTowerRecord); if (GetMultiplayerId() == 0) - dest->battleTowerRecord.unk_11c8 = GetRecordMixingGift(); + dest->giftItem = GetRecordMixingGift(); } static void PrepareExchangePacket(void) @@ -263,7 +264,7 @@ static void PrepareExchangePacket(void) SanitizeEmeraldBattleTowerRecord(&sSentRecord->emerald.battleTowerRecord); if (GetMultiplayerId() == 0) - sSentRecord->emerald.unk_1210 = GetRecordMixingGift(); + sSentRecord->emerald.giftItem = GetRecordMixingGift(); sub_80E8110(sSentRecord->emerald.apprentice, gUnknown_03001154); sub_80E8260(&sSentRecord->emerald.unk_12dc); @@ -283,7 +284,7 @@ static void ReceiveExchangePacket(u32 which) ReceivePokeNewsData(sReceivedRecords->ruby.pokeNews, sizeof(struct PlayerRecordsRS), which); ReceiveOldManData(&sReceivedRecords->ruby.oldMan, sizeof(struct PlayerRecordsRS), which); ReceiveEasyChatPairsData(sReceivedRecords->ruby.easyChatPairs, sizeof(struct PlayerRecordsRS), which); - sub_80E7F68(&sReceivedRecords->ruby.battleTowerRecord.unk_11c8, which); + ReceiveGiftItem(&sReceivedRecords->ruby.giftItem, which); } else { @@ -296,7 +297,7 @@ static void ReceiveExchangePacket(u32 which) ReceiveEasyChatPairsData(sReceivedRecords->emerald.easyChatPairs, sizeof(struct PlayerRecordsEmerald), which); ReceiveDaycareMailData(&sReceivedRecords->emerald.dayCareMail, sizeof(struct PlayerRecordsEmerald), which, sReceivedRecords->emerald.tvShows); ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(struct PlayerRecordsEmerald), which); - sub_80E7F68(&sReceivedRecords->emerald.unk_1210, which); + ReceiveGiftItem(&sReceivedRecords->emerald.giftItem, which); ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(struct PlayerRecordsEmerald), which); ReceiveApprenticeData(sReceivedRecords->emerald.apprentice, sizeof(struct PlayerRecordsEmerald), (u8) which); sub_80E89AC(&sReceivedRecords->emerald.unk_12dc, sizeof(struct PlayerRecordsEmerald), (u8) which); @@ -667,7 +668,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u ShufflePlayerIndices(mixIndices); if (Link_AnyPartnersPlayingRubyOrSapphire()) { - if (sub_816587C((void *)battleTowerRecord + recordSize * mixIndices[which], (void *)battleTowerRecord + recordSize * which) == TRUE) + if (RubyBattleTowerRecordToEmerald((void *)battleTowerRecord + recordSize * mixIndices[which], (void *)battleTowerRecord + recordSize * which) == TRUE) { dest = (void *)battleTowerRecord + recordSize * which; dest->language = gLinkPlayers[mixIndices[which]].language; @@ -676,7 +677,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u } else { - memcpy((void *)battleTowerRecord + recordSize * which, (void *)battleTowerRecord + recordSize * mixIndices[which], sizeof(union BattleTowerRecord)); + memcpy((void *)battleTowerRecord + recordSize * which, (void *)battleTowerRecord + recordSize * mixIndices[which], sizeof(struct EmeraldBattleTowerRecord)); dest = (void *)battleTowerRecord + recordSize * which; for (i = 0; i < 4; i ++) { @@ -1460,7 +1461,7 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r } #endif // NONMATCHING -static void sub_80E7F68(u16 *item, u8 which) +static void ReceiveGiftItem(u16 *item, u8 which) { if (which != 0 && *item != ITEM_NONE && GetPocketByItemId(*item) == POCKET_KEY_ITEMS) { From 549b669f2aa397c9d784de2ff9b91459ab26c060 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 24 Oct 2018 23:14:45 +0200 Subject: [PATCH 5/8] battle tower, match sth and dumb loop instead of goto --- asm/battle_frontier_2.s | 8 +- asm/battle_tower.s | 868 +--------------------------- asm/pokenav.s | 2 +- include/battle_tower.h | 2 +- include/constants/battle_frontier.h | 4 + include/global.h | 2 +- src/apprentice.c | 14 +- src/battle_dome.c | 24 +- src/battle_main.c | 6 +- src/battle_tent.c | 4 +- src/battle_tower.c | 431 ++++++++++++-- src/field_specials.c | 84 +-- src/pokemon.c | 8 +- src/record_mixing.c | 4 +- src/tv.c | 4 +- 15 files changed, 439 insertions(+), 1026 deletions(-) diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 108f1996c..6f267bcc1 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -6261,7 +6261,7 @@ _081A4E46: bl ZeroEnemyPartyMons movs r1, 0 str r1, [sp, 0x18] - bl GetFacilityEnemyMonLevel + bl SetFacilityPtrsGetLevel lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x1C] @@ -9904,7 +9904,7 @@ sub_81A6CD0: @ 81A6CD0 lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x24] - bl GetFacilityEnemyMonLevel + bl SetFacilityPtrsGetLevel lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x20] @@ -11734,7 +11734,7 @@ TryGenerateBattlePikeWildMon: @ 81A7B90 ands r0, r1 cmp r0, 0 beq _081A7C1C - bl sub_8165CB4 + bl GetHighestLevelInPlayerParty adds r7, r0, 0 cmp r7, 0x3B ble _081A7C08 @@ -15719,7 +15719,7 @@ _081A9C56: bl SetMonData cmp r5, 0 beq _081A9CD4 - bl GetFacilityEnemyMonLevel + bl SetFacilityPtrsGetLevel lsls r0, 24 lsrs r5, r0, 24 ldr r1, [sp, 0x10] diff --git a/asm/battle_tower.s b/asm/battle_tower.s index 46d10acd1..975596c7b 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -6,873 +6,7 @@ .text - thumb_func_start sub_81659DC -sub_81659DC: @ 81659DC - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - adds r4, r0, 0 - adds r6, r1, 0 - movs r2, 0 - adds r1, r4, 0 - adds r3, r4, 0 - adds r3, 0x58 -_081659F4: - ldrh r0, [r1, 0x34] - cmp r0, 0 - beq _081659FC - adds r2, 0x1 -_081659FC: - adds r1, 0x2C - cmp r1, r3 - ble _081659F4 - cmp r2, 0x3 - beq _08165A14 - adds r0, r6, 0 - movs r1, 0 - movs r2, 0xA4 - bl memset - movs r0, 0 - b _08165AD8 -_08165A14: - ldrb r0, [r4] - strb r0, [r6] - ldrh r0, [r4, 0x2] - strh r0, [r6, 0x2] - movs r2, 0 - ldr r0, =sRubyFacilityClassToEmerald - ldrb r1, [r0, 0x1] - ldrb r3, [r4, 0x1] - mov r12, r0 - adds r5, r6, 0x4 - adds r7, r4, 0x4 - movs r0, 0xC - adds r0, r6 - mov r9, r0 - movs r0, 0xC - adds r0, r4 - mov r8, r0 - adds r0, r6, 0 - adds r0, 0x10 - str r0, [sp] - movs r0, 0x10 - adds r0, r4 - mov r10, r0 - cmp r1, r3 - beq _08165A58 - mov r1, r12 - adds r1, 0x1 -_08165A4A: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, 0x51 - bgt _08165A58 - ldrb r0, [r1] - cmp r0, r3 - bne _08165A4A -_08165A58: - cmp r2, 0x52 - beq _08165A68 - lsls r0, r2, 1 - add r0, r12 - ldrb r0, [r0] - b _08165A6A - .pool -_08165A68: - movs r0, 0x24 -_08165A6A: - strb r0, [r6, 0x1] - movs r2, 0 - adds r3, r7, 0 -_08165A70: - adds r0, r5, r2 - adds r1, r3, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x7 - ble _08165A70 - movs r2, 0 - mov r5, r9 - mov r3, r8 -_08165A84: - adds r0, r5, r2 - adds r1, r3, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x3 - ble _08165A84 - mov r3, r10 - ldr r1, [sp] - movs r2, 0x5 -_08165A98: - ldrh r0, [r3] - strh r0, [r1] - adds r3, 0x2 - adds r1, 0x2 - subs r2, 0x1 - cmp r2, 0 - bge _08165A98 - adds r2, r4, 0 - adds r3, r6, 0 - movs r4, 0x58 - adds r4, r2 - mov r8, r4 -_08165AB0: - adds r1, r3, 0 - adds r1, 0x1C - adds r0, r2, 0 - adds r0, 0x34 - ldm r0!, {r4,r5,r7} - stm r1!, {r4,r5,r7} - ldm r0!, {r4,r5,r7} - stm r1!, {r4,r5,r7} - ldm r0!, {r4,r5,r7} - stm r1!, {r4,r5,r7} - ldm r0!, {r5,r7} - stm r1!, {r5,r7} - adds r2, 0x2C - adds r3, 0x2C - cmp r2, r8 - ble _08165AB0 - adds r0, r6, 0 - bl CalcRubyBattleTowerChecksum - movs r0, 0x1 -_08165AD8: - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81659DC - thumb_func_start sub_8165AE8 -sub_8165AE8: @ 8165AE8 - push {r4,lr} - adds r2, r0, 0 - movs r0, 0 - str r0, [r2, 0x40] - movs r3, 0 - adds r4, r2, 0 -_08165AF4: - ldr r0, [r2, 0x40] - ldm r4!, {r1} - adds r0, r1 - str r0, [r2, 0x40] - adds r3, 0x1 - cmp r3, 0xF - bls _08165AF4 - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8165AE8 - - thumb_func_start sub_8165B08 -sub_8165B08: @ 8165B08 - push {lr} - movs r1, 0 - movs r3, 0 - adds r2, r0, 0 -_08165B10: - stm r2!, {r3} - adds r1, 0x1 - cmp r1, 0x10 - bls _08165B10 - bl ResetApprenticeStruct - pop {r0} - bx r0 - thumb_func_end sub_8165B08 - - thumb_func_start sub_8165B20 -sub_8165B20: @ 8165B20 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - movs r5, 0 - ldr r0, =gSaveBlock2Ptr - mov r8, r0 - mov r9, r8 -_08165B30: - lsls r0, r5, 4 - adds r1, r0, r5 - lsls r1, 2 - adds r1, 0xDC - mov r3, r9 - ldr r2, [r3] - movs r4, 0 - movs r3, 0 - adds r6, r0, 0 - adds r7, r5, 0x1 - adds r2, r1 -_08165B46: - ldm r2!, {r0} - adds r4, r0 - adds r3, 0x1 - cmp r3, 0xF - bls _08165B46 - mov r0, r8 - ldr r2, [r0] - adds r0, r6, r5 - lsls r1, r0, 2 - movs r3, 0x8E - lsls r3, 1 - adds r0, r2, r3 - adds r0, r1 - ldr r0, [r0] - cmp r0, r4 - beq _08165B70 - adds r0, r1, 0 - adds r0, 0xDC - adds r0, r2, r0 - bl sub_8165B08 -_08165B70: - adds r5, r7, 0 - cmp r5, 0x3 - ble _08165B30 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8165B20 - - thumb_func_start sub_8165B88 -sub_8165B88: @ 8165B88 - push {r4,lr} - adds r4, r0, 0 - lsls r1, 16 - lsrs r2, r1, 16 - adds r3, r2, 0 - movs r0, 0xFA - lsls r0, 1 - cmp r2, r0 - bne _08165BA4 - ldr r0, =gGameLanguage - b _08165C28 - .pool -_08165BA4: - ldr r0, =0x0000012b - cmp r2, r0 - bhi _08165BB8 - ldr r0, =gGameLanguage - b _08165C28 - .pool -_08165BB8: - ldr r0, =0x0000018f - cmp r2, r0 - bhi _08165BFC - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08165BDC - bl sub_81864B4 - b _08165C2A - .pool -_08165BDC: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0xfffffed4 - adds r2, r1 - movs r1, 0xEC - muls r1, r2 - adds r0, r1 - ldr r1, =0x0000081c - adds r0, r1 - b _08165C28 - .pool -_08165BFC: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - ands r0, r1 - cmp r0, 0 - beq _08165C14 - bl sub_81864C0 - b _08165C2A - .pool -_08165C14: - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldr r0, =0xfffffe70 - adds r1, r3, r0 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, r0 - ldr r1, =0x0000011b - adds r0, r2, r1 -_08165C28: - ldrb r0, [r0] -_08165C2A: - strb r0, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8165B88 - - thumb_func_start GetFacilityEnemyMonLevel -GetFacilityEnemyMonLevel: @ 8165C40 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca9 - adds r2, r0, r1 - ldrb r1, [r2] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - beq _08165C84 - ldr r1, =gFacilityTrainers - ldr r0, =gBattleFrontierTrainers - str r0, [r1] - ldr r1, =gFacilityTrainerMons - ldr r0, =gBattleFrontierMons - str r0, [r1] - ldrb r0, [r2] - lsls r0, 30 - lsrs r0, 30 - bl GetFrontierEnemyMonLevel - b _08165C88 - .pool -_08165C84: - bl GetTentEnemyMonLevel -_08165C88: - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - thumb_func_end GetFacilityEnemyMonLevel - - thumb_func_start GetFrontierEnemyMonLevel -GetFrontierEnemyMonLevel: @ 8165C90 - push {lr} - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0 - beq _08165C9E - cmp r0, 0x1 - beq _08165CA2 -_08165C9E: - movs r0, 0x32 - b _08165CB0 -_08165CA2: - bl sub_8165CB4 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3B - bhi _08165CB0 - movs r0, 0x3C -_08165CB0: - pop {r1} - bx r1 - thumb_func_end GetFrontierEnemyMonLevel - - thumb_func_start sub_8165CB4 -sub_8165CB4: @ 8165CB4 - push {r4-r6,lr} - movs r6, 0 - movs r5, 0 -_08165CBA: - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - cmp r0, 0 - beq _08165CF4 - adds r0, r4, 0 - movs r1, 0x41 - movs r2, 0 - bl GetMonData - movs r1, 0xCE - lsls r1, 1 - cmp r0, r1 - beq _08165CF4 - adds r0, r4, 0 - movs r1, 0x38 - movs r2, 0 - bl GetMonData - cmp r0, r6 - ble _08165CF4 - adds r6, r0, 0 -_08165CF4: - adds r5, 0x1 - cmp r5, 0x5 - ble _08165CBA - adds r0, r6, 0 - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8165CB4 - - thumb_func_start GetFrontierTrainerFixedIvs -GetFrontierTrainerFixedIvs: @ 8165D08 - push {lr} - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - cmp r0, 0x63 - bls _08165D3A - movs r1, 0x6 - cmp r0, 0x77 - bls _08165D3A - movs r1, 0x9 - cmp r0, 0x8B - bls _08165D3A - movs r1, 0xC - cmp r0, 0x9F - bls _08165D3A - movs r1, 0xF - cmp r0, 0xB3 - bls _08165D3A - movs r1, 0x12 - cmp r0, 0xC7 - bls _08165D3A - movs r1, 0x1F - cmp r0, 0xDB - bhi _08165D3A - movs r1, 0x15 -_08165D3A: - adds r0, r1, 0 - pop {r1} - bx r1 - thumb_func_end GetFrontierTrainerFixedIvs - - thumb_func_start sub_8165D40 -sub_8165D40: @ 8165D40 - push {lr} - ldr r0, =0x000040cf - bl VarGet - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x2 - beq _08165D58 - cmp r0, 0x3 - beq _08165D58 - cmp r0, 0x4 - bne _08165D70 -_08165D58: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1E - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - b _08165D72 - .pool -_08165D70: - movs r0, 0 -_08165D72: - pop {r1} - bx r1 - thumb_func_end sub_8165D40 - - thumb_func_start GetTentEnemyMonLevel -GetTentEnemyMonLevel: @ 8165D78 - push {lr} - ldr r0, =0x000040cf - bl VarGet - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x4 - bne _08165DA8 - ldr r1, =gFacilityTrainers - ldr r0, =gSlateportBattleTentTrainers - str r0, [r1] - ldr r1, =gFacilityTrainerMons - ldr r0, =gSlateportBattleTentMons - b _08165DF2 - .pool -_08165DA8: - cmp r0, 0x2 - bne _08165DC8 - ldr r1, =gFacilityTrainers - ldr r0, =gVerdanturfBattleTentTrainers - str r0, [r1] - ldr r1, =gFacilityTrainerMons - ldr r0, =gVerdanturfBattleTentMons - b _08165DF2 - .pool -_08165DC8: - cmp r0, 0x3 - bne _08165DE8 - ldr r1, =gFacilityTrainers - ldr r0, =gFallarborBattleTentTrainers - str r0, [r1] - ldr r1, =gFacilityTrainerMons - ldr r0, =gFallarborBattleTentMons - b _08165DF2 - .pool -_08165DE8: - ldr r1, =gFacilityTrainers - ldr r0, =gBattleFrontierTrainers - str r0, [r1] - ldr r1, =gFacilityTrainerMons - ldr r0, =gBattleFrontierMons -_08165DF2: - str r0, [r1] - bl sub_8165CB4 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1D - bhi _08165E02 - movs r0, 0x1E -_08165E02: - pop {r1} - bx r1 - .pool - thumb_func_end GetTentEnemyMonLevel - - thumb_func_start sub_8165E18 -sub_8165E18: @ 8165E18 - push {r4,r5,lr} - ldr r5, =gSaveBlock2Ptr -_08165E1C: - bl sub_8165D40 - lsls r0, 16 - lsrs r4, r0, 16 - movs r3, 0 - ldr r1, [r5] - ldr r2, =0x00000cb2 - adds r0, r1, r2 - ldrh r0, [r0] - cmp r3, r0 - bge _08165E58 - adds r2, 0x2 - adds r0, r1, r2 - ldrh r0, [r0] - cmp r0, r4 - beq _08165E58 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - subs r2, 0x2 - adds r0, r1, r2 - ldrh r2, [r0] - ldr r0, =0x00000cb4 - adds r1, r0 -_08165E4A: - adds r1, 0x2 - adds r3, 0x1 - cmp r3, r2 - bge _08165E58 - ldrh r0, [r1] - cmp r0, r4 - bne _08165E4A -_08165E58: - ldr r0, [r5] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - cmp r3, r0 - bne _08165E1C - ldr r5, =gTrainerBattleOpponent_A - strh r4, [r5] - ldrh r0, [r5] - movs r1, 0 - bl SetBattleFacilityTrainerGfxId - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000cb2 - adds r0, r1, r2 - ldrh r2, [r0] - adds r0, r2, 0x1 - cmp r0, 0x2 - bgt _08165E8C - lsls r0, r2, 1 - ldr r2, =0x00000cb4 - adds r1, r2 - adds r1, r0 - ldrh r0, [r5] - strh r0, [r1] -_08165E8C: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8165E18 - - thumb_func_start sub_8165EA4 -sub_8165EA4: @ 8165EA4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x38 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x18] - lsls r2, 24 - lsrs r2, 24 - str r2, [sp, 0x1C] - bl GetTentEnemyMonLevel - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x20] - ldr r0, =gTrainerBattleOpponent_A - ldrh r2, [r0] - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r2 - adds r0, r1 - ldr r0, [r0, 0x30] - str r0, [sp, 0x28] - movs r0, 0 - str r0, [sp, 0x24] - ldr r2, [sp, 0x28] - ldrh r1, [r2] - b _08165EFE - .pool -_08165EEC: - ldr r0, [sp, 0x24] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x24] - lsls r0, 1 - ldr r6, [sp, 0x28] - adds r0, r6 - ldrh r1, [r0] -_08165EFE: - ldr r0, =0x0000ffff - cmp r1, r0 - bne _08165EEC - movs r0, 0 - mov r8, r0 - bl Random - adds r4, r0, 0 - bl Random - lsls r4, 16 - lsrs r4, 16 - lsls r0, 16 - orrs r4, r0 - str r4, [sp, 0x2C] - b _08166092 - .pool -_08165F24: - bl Random - lsls r0, 16 - lsrs r0, 16 - ldr r1, [sp, 0x24] - bl __modsi3 - lsls r0, 1 - ldr r2, [sp, 0x28] - adds r0, r2 - ldrh r4, [r0] - movs r6, 0 - ldr r7, [sp, 0x18] - add r7, r8 - b _08165F44 -_08165F42: - adds r6, 0x1 -_08165F44: - cmp r6, r7 - bge _08165F68 - movs r1, 0x64 - adds r0, r6, 0 - muls r0, r1 - ldr r2, =gEnemyParty - adds r0, r2 - movs r1, 0xB - movs r2, 0 - bl GetMonData - ldr r1, =gFacilityTrainerMons - ldr r2, [r1] - lsls r1, r4, 4 - adds r1, r2 - ldrh r1, [r1] - cmp r0, r1 - bne _08165F42 -_08165F68: - cmp r6, r7 - beq _08165F6E - b _08166092 -_08165F6E: - movs r6, 0 - cmp r6, r7 - bge _08165FB8 - ldr r0, =gBattleFrontierHeldItems - mov r9, r0 - movs r3, 0 -_08165F7A: - ldr r1, =gEnemyParty - adds r5, r3, r1 - adds r0, r5, 0 - movs r1, 0xC - movs r2, 0 - str r3, [sp, 0x34] - bl GetMonData - ldr r3, [sp, 0x34] - cmp r0, 0 - beq _08165FB0 - adds r0, r5, 0 - movs r1, 0xC - movs r2, 0 - bl GetMonData - ldr r1, =gFacilityTrainerMons - ldr r2, [r1] - lsls r1, r4, 4 - adds r1, r2 - ldrb r1, [r1, 0xA] - lsls r1, 1 - add r1, r9 - ldr r3, [sp, 0x34] - ldrh r1, [r1] - cmp r0, r1 - beq _08165FB8 -_08165FB0: - adds r3, 0x64 - adds r6, 0x1 - cmp r6, r7 - blt _08165F7A -_08165FB8: - cmp r6, r7 - bne _08166092 - movs r6, 0 - cmp r6, r8 - bge _08165FDA - add r0, sp, 0xC - ldrh r0, [r0] - cmp r0, r4 - beq _08165FDA - add r1, sp, 0xC -_08165FCC: - adds r1, 0x2 - adds r6, 0x1 - cmp r6, r8 - bge _08165FDA - ldrh r0, [r1] - cmp r0, r4 - bne _08165FCC -_08165FDA: - cmp r6, r8 - bne _08166092 - mov r2, r8 - lsls r0, r2, 1 - add r0, sp - adds r0, 0xC - strh r4, [r0] - movs r6, 0x64 - adds r0, r7, 0 - muls r0, r6 - ldr r1, =gEnemyParty - adds r0, r1 - ldr r5, =gFacilityTrainerMons - ldr r2, [r5] - lsls r4, 4 - adds r2, r4, r2 - ldrh r1, [r2] - ldrb r3, [r2, 0xC] - movs r6, 0 - str r6, [sp] - ldrb r2, [r2, 0xB] - str r2, [sp, 0x4] - ldr r2, [sp, 0x2C] - str r2, [sp, 0x8] - ldr r2, [sp, 0x20] - bl CreateMonWithEVSpreadPersonalityOTID - add r1, sp, 0x14 - movs r0, 0xFF - strb r0, [r1] - mov r9, r4 - mov r0, r8 - adds r0, 0x1 - str r0, [sp, 0x30] - movs r0, 0x64 - adds r1, r7, 0 - muls r1, r0 - mov r8, r1 - adds r3, r5, 0 - mov r5, r9 - ldr r2, =gEnemyParty - mov r10, r2 -_0816602E: - ldr r0, [r3] - adds r0, r5, r0 - lsls r4, r6, 1 - adds r0, 0x2 - adds r0, r4 - ldrh r1, [r0] - lsls r2, r6, 24 - lsrs r2, 24 - mov r0, r8 - add r0, r10 - str r3, [sp, 0x34] - bl SetMonMoveSlot - ldr r3, [sp, 0x34] - ldr r0, [r3] - adds r0, r5, r0 - adds r0, 0x2 - adds r0, r4 - ldrh r0, [r0] - cmp r0, 0xDA - bne _0816605E - movs r0, 0 - mov r1, sp - strb r0, [r1, 0x14] -_0816605E: - adds r6, 0x1 - cmp r6, 0x3 - ble _0816602E - movs r2, 0x64 - adds r4, r7, 0 - muls r4, r2 - ldr r6, =gEnemyParty - adds r4, r6 - adds r0, r4, 0 - movs r1, 0x20 - add r2, sp, 0x14 - bl SetMonData - ldr r0, =gFacilityTrainerMons - ldr r0, [r0] - add r0, r9 - ldrb r2, [r0, 0xA] - lsls r2, 1 - ldr r0, =gBattleFrontierHeldItems - adds r2, r0 - adds r0, r4, 0 - movs r1, 0xC - bl SetMonData - ldr r0, [sp, 0x30] - mov r8, r0 -_08166092: - ldr r1, [sp, 0x1C] - cmp r8, r1 - beq _0816609A - b _08165F24 -_0816609A: - add sp, 0x38 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8165EA4 thumb_func_start sub_81660B8 sub_81660B8: @ 81660B8 @@ -998,7 +132,7 @@ sub_8166188: @ 8166188 ands r0, r1 cmp r0, 0 beq _081661E8 - bl GetFacilityEnemyMonLevel + bl SetFacilityPtrsGetLevel lsls r0, 24 movs r5, 0 ldr r7, =gBaseStats diff --git a/asm/pokenav.s b/asm/pokenav.s index b3a174bdc..732f0ef2e 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -29731,7 +29731,7 @@ sub_81D62CC: @ 81D62CC lsls r0, r1, 24 lsrs r6, r0, 24 bl sub_81D56B0 - bl sub_8165CB4 + bl GetHighestLevelInPlayerParty lsls r0, 24 lsrs r0, 24 mov r10, r0 diff --git a/include/battle_tower.h b/include/battle_tower.h index 4b68be923..39d75f8be 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -52,7 +52,7 @@ extern const struct BattleFrontierTrainer *gFacilityTrainers; extern const struct FacilityMon *gFacilityTrainerMons; u16 GetCurrentBattleTowerWinStreak(u8, u8); -void sub_81659DC(struct RSBattleTowerRecord *a0, struct RSBattleTowerRecord *a1); +bool32 EmeraldBattleTowerRecordToRuby(struct EmeraldBattleTowerRecord *src, struct RSBattleTowerRecord *dst); bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct EmeraldBattleTowerRecord *dst); void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *); void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm); diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index ca110aeb7..204a09f60 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -10,6 +10,10 @@ #define FRONTIER_FACILITY_PIKE 5 #define FRONTIER_FACILITY_PYRAMID 6 +#define TENT_VERDANTURF 2 +#define TENT_FALLARBOR 3 +#define TENT_SLATEPORT 4 + // Battle Frontier lvl modes. #define FRONTIER_LVL_50 0 #define FRONTIER_LVL_OPEN 1 diff --git a/include/global.h b/include/global.h index a7b50278c..0cff281e7 100644 --- a/include/global.h +++ b/include/global.h @@ -293,7 +293,7 @@ struct Apprentice u8 playerId[4]; u8 playerName[PLAYER_NAME_LENGTH]; u8 language; - u32 unk40; + u32 checksum; }; struct UnknownPokemonStruct diff --git a/src/apprentice.c b/src/apprentice.c index d45cff430..9e01a072a 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -344,7 +344,7 @@ extern struct Unk030062ECStruct *gUnknown_030062EC; extern struct Unk030062F0Struct *gUnknown_030062F0; extern void (*gUnknown_030062F4)(void); -extern void sub_8165AE8(struct Apprentice *); +extern void CalcApprenticeChecksum(struct Apprentice *); // This file's functions. static u16 sub_819FF98(u8 arg0); @@ -1087,7 +1087,7 @@ void ResetAllApprenticeData(void) for (j = 0; j < 4; j++) gSaveBlock2Ptr->apprentices[i].playerId[j] = 0; gSaveBlock2Ptr->apprentices[i].language = gGameLanguage; - gSaveBlock2Ptr->apprentices[i].unk40 = 0; + gSaveBlock2Ptr->apprentices[i].checksum = 0; } Script_ResetPlayerApprentice(); @@ -1430,16 +1430,16 @@ static void sub_81A0390(u8 arg0) for (i = 0; i < 3; i++) { - gSaveBlock2Ptr->apprentices[0].monData[i].species = 0; - gSaveBlock2Ptr->apprentices[0].monData[i].item = 0; + gSaveBlock2Ptr->apprentices[0].party[i].species = 0; + gSaveBlock2Ptr->apprentices[0].party[i].item = 0; for (j = 0; j < 4; j++) - gSaveBlock2Ptr->apprentices[0].monData[i].moves[j] = 0; + gSaveBlock2Ptr->apprentices[0].party[i].moves[j] = 0; } j = PLAYER_APPRENTICE.field_B1_2; for (i = 0; i < 3; i++) { - apprenticeMons[j] = &gSaveBlock2Ptr->apprentices[0].monData[i]; + apprenticeMons[j] = &gSaveBlock2Ptr->apprentices[0].party[i]; j = (j + 1) % 3; } @@ -2256,7 +2256,7 @@ static void sub_81A1438(void) StringCopy(gSaveBlock2Ptr->apprentices[0].playerName, gSaveBlock2Ptr->playerName); gSaveBlock2Ptr->apprentices[0].language = gGameLanguage; - sub_8165AE8(&gSaveBlock2Ptr->apprentices[0]); + CalcApprenticeChecksum(&gSaveBlock2Ptr->apprentices[0]); } static void sub_81A150C(void) diff --git a/src/battle_dome.c b/src/battle_dome.c index 6401530d7..6b32bf812 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -58,7 +58,7 @@ extern void sub_81B8558(void); extern u32 sub_81A39C4(void); extern u16 sub_8162548(u8, u8); extern u16 RandomizeFacilityTrainerMonId(u16); -extern u8 GetFacilityEnemyMonLevel(void); +extern u8 SetFacilityPtrsGetLevel(void); extern u16 sub_81A5060(u8 monId, u8 moveSlotId); extern u8 sub_81A50F0(u8, u8); extern u8 sub_81A50B0(u8); @@ -2595,13 +2595,13 @@ static void InitDomeTrainers(void) for (i = 0; i < 3; i++) { - gSaveBlock2Ptr->frontier.domeMonId[0][i] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], MON_DATA_SPECIES, NULL); + gSaveBlock2Ptr->frontier.domeMonId[0][i] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_SPECIES, NULL); for (j = 0; j < 4; j++) - gSaveBlock2Ptr->frontier.field_EFC[i].moves[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], MON_DATA_MOVE1 + j, NULL); + gSaveBlock2Ptr->frontier.field_EFC[i].moves[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_MOVE1 + j, NULL); for (j = 0; j < 6; j++) - gSaveBlock2Ptr->frontier.field_EFC[i].evs[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], MON_DATA_HP_EV + j, NULL); + gSaveBlock2Ptr->frontier.field_EFC[i].evs[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_HP_EV + j, NULL); - gSaveBlock2Ptr->frontier.field_EFC[i].nature = GetNature(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1]); + gSaveBlock2Ptr->frontier.field_EFC[i].nature = GetNature(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1]); } for (i = 1; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++) @@ -2663,7 +2663,7 @@ static void InitDomeTrainers(void) statSums[0] = 0; for (i = 0; i < 3; i++) { - trainerId = gSaveBlock2Ptr->frontier.field_CAA[i] - 1; // Great variable choice, gamefreak. + trainerId = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1; // Great variable choice, gamefreak. statSums[0] += GetMonData(&gPlayerParty[trainerId], MON_DATA_ATK, NULL); statSums[0] += GetMonData(&gPlayerParty[trainerId], MON_DATA_DEF, NULL); statSums[0] += GetMonData(&gPlayerParty[trainerId], MON_DATA_SPATK, NULL); @@ -2681,7 +2681,7 @@ static void InitDomeTrainers(void) monTypesBits >>= 1; } - monLevel = GetFacilityEnemyMonLevel(); + monLevel = SetFacilityPtrsGetLevel(); statSums[0] += (monTypesCount * monLevel) / 20; for (i = 1; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++) @@ -2847,7 +2847,7 @@ static void CreateDomeMon(u8 monPartyId, u16 tournamentTrainerId, u8 tournamentM s32 i; u8 happiness = 0xFF; u8 fixedIv = GetDomeTrainerMonIvs(tournamentTrainerId); // BUG: Should be using trainerId instead of tournamentTrainerId. As a result, all Pokemon have ivs of 3. - u8 level = GetFacilityEnemyMonLevel(); + u8 level = SetFacilityPtrsGetLevel(); CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[monPartyId], gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[tournamentTrainerId][tournamentMonId]].species, level, @@ -5575,7 +5575,7 @@ static u16 GetWinningMove(s32 winnerTournamentId, s32 loserTournamentId, u8 roun u16 bestScore = 0; u16 bestId = 0; s32 movePower = 0; - GetFacilityEnemyMonLevel(); // Unused return variable. + SetFacilityPtrsGetLevel(); // Unused return variable. // Calc move points of all 4 moves for all 3 pokemon hitting all 3 target mons. for (i = 0; i < 3; i++) @@ -6098,7 +6098,7 @@ static void sub_8194D68(void) for (i = 0; i < 2; i++) { - s32 playerMonId = gSaveBlock2Ptr->frontier.field_CAA[gUnknown_0203CEF8[i] - 1] - 1; + s32 playerMonId = gSaveBlock2Ptr->frontier.selectedPartyMons[gUnknown_0203CEF8[i] - 1] - 1; s32 count; for (moveSlot = 0; moveSlot < 4; moveSlot++) @@ -6124,7 +6124,7 @@ static void sub_8194E44(void) for (i = 0; i < 2; i++) { - s32 playerMonId = gSaveBlock2Ptr->frontier.field_CAA[gUnknown_0203CEF8[i] - 1] - 1; + s32 playerMonId = gSaveBlock2Ptr->frontier.selectedPartyMons[gUnknown_0203CEF8[i] - 1] - 1; u16 item = GetMonData(&gSaveBlock1Ptr->playerParty[playerMonId], MON_DATA_HELD_ITEM, NULL); SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &item); } @@ -6439,7 +6439,7 @@ static void DecideRoundWinners(u8 roundId) static void CopyDomeTrainerName(u8 *dst, u16 trainerId) { s32 i = 0; - GetFacilityEnemyMonLevel(); // Unused return value. + SetFacilityPtrsGetLevel(); // Unused return value. if (trainerId == TRAINER_FRONTIER_BRAIN) { diff --git a/src/battle_main.c b/src/battle_main.c index 80ee5c425..b3fcaeeda 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -108,7 +108,7 @@ extern const u8 gText_Love[]; // functions extern void GetFrontierTrainerName(u8* dst, u16 trainerId); // battle tower extern void sub_8166188(void); // battle tower, sets link battle mons level but why? -extern void sub_8165B88(u8* dst, u16 trainerId); // battle tower, gets language +extern void GetBattleTowerTrainerLanguage(u8* dst, u16 trainerId); // battle tower, gets language extern void sub_81B9150(void); extern void sub_80B3AF8(u8 taskId); // cable club extern void sub_81A56B4(void); // battle frontier 2 @@ -1159,9 +1159,9 @@ static void CB2_HandleStartMultiPartnerBattle(void) gLinkPlayers[3].id = 3; GetFrontierTrainerName(gLinkPlayers[2].name, gTrainerBattleOpponent_A); GetFrontierTrainerName(gLinkPlayers[3].name, gTrainerBattleOpponent_B); - sub_8165B88(&language, gTrainerBattleOpponent_A); + GetBattleTowerTrainerLanguage(&language, gTrainerBattleOpponent_A); gLinkPlayers[2].language = language; - sub_8165B88(&language, gTrainerBattleOpponent_B); + GetBattleTowerTrainerLanguage(&language, gTrainerBattleOpponent_B); gLinkPlayers[3].language = language; if (sub_800A520()) diff --git a/src/battle_tent.c b/src/battle_tent.c index 4ad045043..4c4bd7fc3 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -553,7 +553,7 @@ static void sub_81BA040(void) trainerId = Random() % 30; for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) { - if (gSaveBlock2Ptr->frontier.battledTrainerIds[i] == trainerId) + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) break; } } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); @@ -567,7 +567,7 @@ static void sub_81BA040(void) } if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 2) - gSaveBlock2Ptr->frontier.battledTrainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; monSetsPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool; i = 0; diff --git a/src/battle_tower.c b/src/battle_tower.c index 25a46d073..cefb02c8d 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -26,12 +26,13 @@ #include "constants/trainers.h" #include "constants/event_objects.h" #include "constants/moves.h" +#include "constants/species.h" extern void sub_81A3ACC(void); extern void CreateFrontierBrainPokemon(void); extern void sub_81A6CD0(void); extern u8 GetFrontierEnemyMonLevel(u8); -extern u8 GetFacilityEnemyMonLevel(void); +extern u8 SetFacilityPtrsGetLevel(void); extern u16 sub_81A39C4(void); extern void SetFrontierBrainTrainerGfxId(void); extern u8 GetFrontierBrainTrainerPicIndex(void); @@ -50,19 +51,19 @@ extern const u16 gBattleFrontierHeldItems[]; // This file's functions. void ValidateBattleTowerRecordChecksums(void); void SaveCurrentWinStreak(void); -void sub_8165B20(void); +void ValidateApprenticesChecksums(void); void sub_8165E18(void); void CopyEReaderTrainerFarewellMessage(void); void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record); u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode); u16 sub_8162548(u8, u8); static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount); -void sub_8165EA4(u16 trainerId, u8 firstMonId, u8 monCount); +void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount); void sub_81635D4(u16 trainerId, u8 firstMonId); void sub_816379C(u16 trainerId, u8 firstMonId); u8 GetFrontierTrainerFixedIvs(u16 trainerId); -void sub_8165404(u16 trainerId); -void sub_8165B88(u8 *dst, u16 trainerId); +void FillPartnerParty(u16 trainerId); +void GetBattleTowerTrainerLanguage(u8 *dst, u16 trainerId); void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer); void ClearEReaderTrainer(struct BattleTowerEReaderTrainer *ereaderTrainer); @@ -192,7 +193,7 @@ bool8 ChooseSpecialBattleTowerTrainer(void) if (battleMode == FRONTIER_MODE_SINGLES) { - sub_8165B20(); + ValidateApprenticesChecksums(); for (i = 0; i < 4; i++) { if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0 @@ -228,7 +229,7 @@ void ChooseNextBattleTowerTrainer(void) u16 id; u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); u32 r5 = sub_81A39C4() / 7; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (battleMode == FRONTIER_MODE_MULTIS || battleMode == FRONTIER_MODE_LINK_MULTIS) { @@ -384,7 +385,7 @@ void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId) u8 facilityClass; u8 trainerObjectGfxId; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; @@ -481,7 +482,7 @@ u8 GetBattleFacilityTrainerGfxId(u16 trainerId) u8 facilityClass; u8 trainerObjectGfxId; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; @@ -618,7 +619,7 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) { - GetFacilityEnemyMonLevel(); // Pointless function call + SetFacilityPtrsGetLevel(); // Pointless function call if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { @@ -651,7 +652,7 @@ u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) u8 GetFrontierOpponentClass(u16 trainerId) { u8 trainerClass = 0; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { @@ -700,7 +701,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) u8 GetFrontierTrainerFacilityClass(u16 trainerId) { u8 facilityClass; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { @@ -731,7 +732,7 @@ u8 GetFrontierTrainerFacilityClass(u16 trainerId) void GetFrontierTrainerName(u8 *dst, u16 trainerId) { s32 i = 0; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { @@ -794,7 +795,7 @@ bool8 IsFrontierTrainerFemale(u16 trainerId) u32 i; u8 facilityClass; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; @@ -841,10 +842,10 @@ void FillFrontierTrainersParties(u8 monsCount) FillTrainerParty(gTrainerBattleOpponent_B, 3, monsCount); } -void sub_81630A0(u8 monsCount) +void FillTentTrainerParty(u8 monsCount) { ZeroEnemyPartyMons(); - sub_8165EA4(gTrainerBattleOpponent_A, 0, monsCount); + FillTentTrainerParty_(gTrainerBattleOpponent_A, 0, monsCount); } static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) @@ -852,7 +853,7 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) s32 i, j; u16 chosenMonIndices[4]; u8 friendship = 0xFF; - u8 level = GetFacilityEnemyMonLevel(); + u8 level = SetFacilityPtrsGetLevel(); u8 fixedIV = 0; u8 bfMonCount; const u16 *bfMonPool = NULL; @@ -1003,27 +1004,15 @@ void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) u16 RandomizeFacilityTrainerMonId(u16 trainerId) { - u32 monPoolId; - u8 level = GetFacilityEnemyMonLevel(); + u8 level = SetFacilityPtrsGetLevel(); const u16 *bfMonPool = gFacilityTrainers[trainerId].bfMonPool; u8 bfMonCount = 0; + u32 monPoolId = bfMonPool[bfMonCount]; - /* - I had to use ugly C tricks to get this part to match. - A cleaner version would look like this - - for (bfMonCount = 0; bfMonPool[bfMonCount] != 0xFFFF; bfMonCount++) - ; - - */ - - monPoolId = bfMonPool[bfMonCount]; - goto COMPARE; - while (1) + while (monPoolId != 0xFFFF) { bfMonCount++; monPoolId = bfMonPool[bfMonCount]; - COMPARE: if (monPoolId == 0xFFFF) break; } @@ -1082,7 +1071,7 @@ void sub_81635D4(u16 trainerId, u8 firstMonId) } - level = GetFacilityEnemyMonLevel(); + level = SetFacilityPtrsGetLevel(); otID = T1_READ_32(gSaveBlock2Ptr->playerTrainerId); for (i = 0; i < 3; i++) { @@ -1156,7 +1145,7 @@ void FrontierSpeechToString(const u16 *words) void sub_8163914(void) { u16 trainerId; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (gSpecialVar_0x8005) trainerId = gTrainerBattleOpponent_B; @@ -1248,7 +1237,7 @@ void DoSpecialTrainerBattle(void) case FRONTIER_MODE_MULTIS: FillFrontierTrainersParties(2); gPartnerTrainerId = gSaveBlock2Ptr->frontier.field_CB4[17]; - sub_8165404(gPartnerTrainerId); + FillPartnerParty(gPartnerTrainerId); gBattleTypeFlags |= BATTLE_TYPE_DOUBLE | BATTLE_TYPE_INGAME_PARTNER | BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS; break; case FRONTIER_MODE_LINK_MULTIS: @@ -1297,7 +1286,7 @@ void DoSpecialTrainerBattle(void) if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) FillFrontierTrainerParty(3); else - sub_81630A0(3); + FillTentTrainerParty(3); CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(sub_80B100C(4)); @@ -1307,7 +1296,7 @@ void DoSpecialTrainerBattle(void) if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) FillFrontierTrainerParty(3); else - sub_81630A0(3); + FillTentTrainerParty(3); CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(sub_80B100C(5)); @@ -1344,7 +1333,7 @@ void DoSpecialTrainerBattle(void) break; case SPECIAL_BATTLE_STEVEN: gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER; - sub_8165404(TRAINER_STEVEN_PARTNER); + FillPartnerParty(TRAINER_STEVEN_PARTNER); gApproachingTrainerId = 0; BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_224157 + 1); gApproachingTrainerId = 1; @@ -1511,7 +1500,7 @@ void sub_81642A0(void) challengeNum = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] / 7; species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); - level = GetFacilityEnemyMonLevel(); + level = SetFacilityPtrsGetLevel(); j = 0; do @@ -1563,7 +1552,7 @@ void sub_81642A0(void) } r10 = 0; - sub_8165B20(); + ValidateApprenticesChecksums(); for (i = 0; i < 4; i++) { if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0 @@ -1642,7 +1631,7 @@ void sub_81646BC(u16 trainerId, u16 monPoolId) { u16 move = 0; u16 species = 0; - GetFacilityEnemyMonLevel(); // Pointless function call. + SetFacilityPtrsGetLevel(); if (trainerId != BATTLE_TOWER_EREADER_TRAINER_ID) { @@ -1686,7 +1675,7 @@ void sub_8164828(void) { s32 i, j, arrId; s32 monPoolId; - s32 level = GetFacilityEnemyMonLevel(); // Unused variable. + s32 level = SetFacilityPtrsGetLevel(); s32 challengeNum = sub_81A39C4() / 7; s32 k = gSpecialVar_LastTalked - 2; s32 trainerId = gSaveBlock2Ptr->frontier.field_CB4[k]; @@ -1899,7 +1888,7 @@ void sub_8164E04(void) GetFrontierTrainerName(text, gTrainerBattleOpponent_A); StripExtCtrlCodes(text); StringCopy(gSaveBlock2Ptr->frontier.field_BD8, text); - sub_8165B88(&gSaveBlock2Ptr->frontier.field_BEB, gTrainerBattleOpponent_A); + GetBattleTowerTrainerLanguage(&gSaveBlock2Ptr->frontier.field_BEB, gTrainerBattleOpponent_A); gSaveBlock2Ptr->frontier.field_BD6 = GetMonData(&gEnemyParty[gBattlerPartyIndexes[1]], MON_DATA_SPECIES, NULL); gSaveBlock2Ptr->frontier.field_BD4 = GetMonData(&gPlayerParty[gBattlerPartyIndexes[0]], MON_DATA_SPECIES, NULL); for (i = 0; i < POKEMON_NAME_LENGTH + 1; i++) @@ -2184,7 +2173,7 @@ extern const struct StevenMon sStevenMons[3]; #define STEVEN_OTID 61226 -void sub_8165404(u16 trainerId) +void FillPartnerParty(u16 trainerId) { s32 i, j; u32 ivs, level; @@ -2192,7 +2181,7 @@ void sub_8165404(u16 trainerId) u16 monPoolId; u32 otID; u8 trainerName[PLAYER_NAME_LENGTH + 1]; - GetFacilityEnemyMonLevel(); // Unused return variable. + SetFacilityPtrsGetLevel(); if (trainerId == TRAINER_STEVEN_PARTNER) { @@ -2225,7 +2214,7 @@ void sub_8165404(u16 trainerId) } else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) { - level = GetFacilityEnemyMonLevel(); + level = SetFacilityPtrsGetLevel(); ivs = GetFrontierTrainerFixedIvs(trainerId); otID = Random32(); for (i = 0; i < 2; i++) @@ -2344,3 +2333,353 @@ bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct Em return TRUE; } } + +bool32 EmeraldBattleTowerRecordToRuby(struct EmeraldBattleTowerRecord *src, struct RSBattleTowerRecord *dst) +{ + s32 i, validMons = 0; + + for (i = 0; i < 3; i++) + { + if (src->party[i].species) + validMons++; + } + + if (validMons != 3) + { + memset(dst, 0, sizeof(*dst)); + return FALSE; + } + else + { + dst->lvlMode = src->lvlMode; + dst->winStreak = src->winStreak; + for (i = 0; i < (signed) ARRAY_COUNT(sRubyFacilityClassToEmerald); i++) + { + if (sRubyFacilityClassToEmerald[i][1] == src->facilityClass) + break; + } + if (i != ARRAY_COUNT(sRubyFacilityClassToEmerald)) + dst->facilityClass = sRubyFacilityClassToEmerald[i][0]; + else + dst->facilityClass = 0x24; // FACILITY_CLASS_YOUNGSTER in Ruby/Sapphire. + + for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) + dst->name[i] = src->name[i]; + for (i = 0; i < 4; i++) + dst->trainerId[i] = src->trainerId[i]; + for (i = 0; i < 6; i++) + dst->greeting[i] = src->greeting[i]; + for (i = 0; i < 3; i++) + dst->party[i] = src->party[i]; + + CalcRubyBattleTowerChecksum(dst); + return TRUE; + } +} + +void CalcApprenticeChecksum(struct Apprentice *apprentice) +{ + s32 i; + + apprentice->checksum = 0; + for (i = 0; i < (sizeof(struct Apprentice) - 4) / 4; i++) + apprentice->checksum += ((u32 *)apprentice)[i]; +} + +void ClearApprentice(struct Apprentice *apprentice) +{ + s32 i; + + for (i = 0; i < (sizeof(struct Apprentice)) / 4; i++) + ((u32 *)apprentice)[i] = 0; + ResetApprenticeStruct(apprentice); +} + +void ValidateApprenticesChecksums(void) +{ + s32 i, j; + + for (i = 0; i < 4; i++) + { + u32 *data = (u32*) &gSaveBlock2Ptr->apprentices[i]; + u32 checksum = 0; + for (j = 0; j < (sizeof(struct Apprentice) - 4) / 4; j++) + checksum += data[j]; + if (gSaveBlock2Ptr->apprentices[i].checksum != checksum) + ClearApprentice(&gSaveBlock2Ptr->apprentices[i]); + } +} + +void GetBattleTowerTrainerLanguage(u8 *dst, u16 trainerId) +{ + if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + { + *dst = gGameLanguage; + } + else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + { + *dst = gGameLanguage; + } + else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + *dst = sub_81864B4(); + else + *dst = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].language; + } + else + { + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + *dst = sub_81864C0(); + else + *dst = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].language; + } +} + +extern const struct FacilityMon gBattleFrontierMons[]; +extern const struct FacilityMon gSlateportBattleTentMons[]; +extern const struct FacilityMon gVerdanturfBattleTentMons[]; +extern const struct FacilityMon gFallarborBattleTentMons[]; + +extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; +extern const struct BattleFrontierTrainer gSlateportBattleTentTrainers[]; +extern const struct BattleFrontierTrainer gVerdanturfBattleTentTrainers[]; +extern const struct BattleFrontierTrainer gFallarborBattleTentTrainers[]; + +u8 SetTentPtrsGetLevel(void); +s32 GetHighestLevelInPlayerParty(void); + +u8 SetFacilityPtrsGetLevel(void) +{ + if (gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_TENT) + { + return SetTentPtrsGetLevel(); + } + else + { + gFacilityTrainers = gBattleFrontierTrainers; + gFacilityTrainerMons = gBattleFrontierMons; + return GetFrontierEnemyMonLevel(gSaveBlock2Ptr->frontier.lvlMode); + } +} + +u8 GetFrontierEnemyMonLevel(u8 lvlMode) +{ + u8 level; + + switch (lvlMode) + { + default: + case FRONTIER_LVL_50: + level = 50; + break; + case FRONTIER_LVL_OPEN: + level = GetHighestLevelInPlayerParty(); + if (level < 60) + level = 60; + break; + } + + return level; +} + +s32 GetHighestLevelInPlayerParty(void) +{ + s32 highestLevel = 0; + s32 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG) + { + s32 level = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL, NULL); + if (level > highestLevel) + highestLevel = level; + } + } + + return highestLevel; +} + +u8 GetFrontierTrainerFixedIvs(u16 trainerId) +{ + u8 fixedIV = 0; + + if (trainerId < 100) + fixedIV = 3; + else if (trainerId < 120) + fixedIV = 6; + else if (trainerId < 140) + fixedIV = 9; + else if (trainerId < 160) + fixedIV = 12; + else if (trainerId < 180) + fixedIV = 15; + else if (trainerId < 200) + fixedIV = 18; + else if (trainerId < 220) + fixedIV = 21; + else + fixedIV = 31; + + return fixedIV; +} + +u16 sub_8165D40(void) +{ + u32 facility = VarGet(VAR_FRONTIER_FACILITY); + + if (facility == FRONTIER_FACILITY_PALACE) + return Random() % 30; + else if (facility == FRONTIER_FACILITY_ARENA) + return Random() % 30; + else if (facility == FRONTIER_FACILITY_FACTORY) + return Random() % 30; + else if (facility == FRONTIER_FACILITY_TOWER) + return 0; + else + return 0; +} + +u8 SetTentPtrsGetLevel(void) +{ + u8 level = 30; + u32 tentFacility = VarGet(VAR_FRONTIER_FACILITY); + + if (tentFacility == TENT_SLATEPORT) + { + gFacilityTrainers = gSlateportBattleTentTrainers; + gFacilityTrainerMons = gSlateportBattleTentMons; + } + else if (tentFacility == TENT_VERDANTURF) + { + gFacilityTrainers = gVerdanturfBattleTentTrainers; + gFacilityTrainerMons = gVerdanturfBattleTentMons; + } + else if (tentFacility == TENT_FALLARBOR) + { + gFacilityTrainers = gFallarborBattleTentTrainers; + gFacilityTrainerMons = gFallarborBattleTentMons; + } + else + { + gFacilityTrainers = gBattleFrontierTrainers; + gFacilityTrainerMons = gBattleFrontierMons; + } + + level = GetHighestLevelInPlayerParty(); + if (level < 30) + level = 30; + + return level; +} + +void sub_8165E18(void) +{ + s32 i; + u16 trainerId; + + do + { + trainerId = sub_8165D40(); + for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); + + gTrainerBattleOpponent_A = trainerId; + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 3) + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; +} + +void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount) +{ + s32 i, j; + u16 chosenMonIndices[4]; + u8 friendship; + u8 level = SetTentPtrsGetLevel(); + u8 fixedIV = 0; + u8 bfMonCount; + const u16 *bfMonPool = NULL; + u32 otID = 0; + u16 monPoolId; + + bfMonPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool; + + bfMonCount = 0; + monPoolId = bfMonPool[bfMonCount]; + while (monPoolId != 0xFFFF) + { + bfMonCount++; + monPoolId = bfMonPool[bfMonCount]; + if (monPoolId == 0xFFFF) + break; + } + + i = 0; + otID = Random32(); + while (i != monCount) + { + u16 monPoolId = bfMonPool[Random() % bfMonCount]; + + // Ensure this pokemon species isn't a duplicate. + for (j = 0; j < i + firstMonId; j++) + { + if (GetMonData(&gEnemyParty[j], MON_DATA_SPECIES, NULL) == gFacilityTrainerMons[monPoolId].species) + break; + } + if (j != i + firstMonId) + continue; + + // Ensure this Pokemon's held item isn't a duplicate. + for (j = 0; j < i + firstMonId; j++) + { + if (GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) != 0 + && GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) == gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]) + break; + } + if (j != i + firstMonId) + continue; + + // Ensure this exact pokemon index isn't a duplicate. This check doesn't seem necessary + // because the species and held items were already checked directly above. + for (j = 0; j < i; j++) + { + if (chosenMonIndices[j] == monPoolId) + break; + } + if (j != i) + continue; + + chosenMonIndices[i] = monPoolId; + + // Place the chosen pokemon into the trainer's party. + CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[i + firstMonId], + gFacilityTrainerMons[monPoolId].species, + level, + gFacilityTrainerMons[monPoolId].nature, + fixedIV, + gFacilityTrainerMons[monPoolId].evSpread, + otID); + + friendship = 255; + // Give the chosen pokemon its specified moves. + for (j = 0; j < 4; j++) + { + SetMonMoveSlot(&gEnemyParty[i + firstMonId], gFacilityTrainerMons[monPoolId].moves[j], j); + if (gFacilityTrainerMons[monPoolId].moves[j] == MOVE_FRUSTRATION) + friendship = 0; // Frustration is more powerful the lower the pokemon's friendship is. + } + + SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_FRIENDSHIP, &friendship); + SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]); + + // The pokemon was successfully added to the trainer's party, so it's safe to move on to + // the next party slot. + i++; + } +} diff --git a/src/field_specials.c b/src/field_specials.c index a74bf40f6..a3308f872 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -2158,13 +2158,13 @@ void sub_8139F20(void) case 1: case 2: case 3: - if (gSaveBlock2Ptr->frontier.field_CE0[var][0] >= gSaveBlock2Ptr->frontier.field_CE0[var][1]) + if (gSaveBlock2Ptr->frontier.winStreaks[var][0] >= gSaveBlock2Ptr->frontier.winStreaks[var][1]) { - unk = gSaveBlock2Ptr->frontier.field_CE0[var][0]; + unk = gSaveBlock2Ptr->frontier.winStreaks[var][0]; } else { - unk = gSaveBlock2Ptr->frontier.field_CE0[var][1]; + unk = gSaveBlock2Ptr->frontier.winStreaks[var][1]; } break; case 4: @@ -2244,7 +2244,7 @@ void sub_813A080(void) u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; - if (battleMode == 2 && !FlagGet(FLAG_0x152)) + if (battleMode == FRONTIER_MODE_MULTIS && !FlagGet(FLAG_0x152)) { gSpecialVar_0x8005 = 5; gSpecialVar_0x8006 = 4; @@ -2253,7 +2253,7 @@ void sub_813A080(void) for (i = 0; i < 9; i++) { - if (gUnknown_085B2CDC[i] > gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode]) + if (gUnknown_085B2CDC[i] > gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode]) { gSpecialVar_0x8005 = 4; gSpecialVar_0x8006 = i + 5; @@ -2733,8 +2733,6 @@ static void sub_813A46C(s32 itemIndex, bool8 onInit, struct ListMenu *list) } } -// stupid r5<->r6 swap -#ifdef NONMATCHING static void sub_813A4EC(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -2752,7 +2750,11 @@ static void sub_813A4EC(u8 taskId) default: gSpecialVar_Result = itemId; PlaySE(SE_SELECT); - if (!task->data[6] || itemId == task->data[1] - 1) + if (!task->data[6]) + { + sub_813A570(taskId); + } + else if (itemId == task->data[1] - 1) { sub_813A570(taskId); } @@ -2765,72 +2767,6 @@ static void sub_813A4EC(u8 taskId) break; } } -#else -NAKED -static void sub_813A4EC(u8 taskId) -{ - asm_unified("push {r4-r6,lr}\n\ - lsls r0, 24\n\ - lsrs r5, r0, 24\n\ - lsls r0, r5, 2\n\ - adds r0, r5\n\ - lsls r0, 3\n\ - ldr r1, =gTasks\n\ - adds r6, r0, r1\n\ - ldrh r0, [r6, 0x24]\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - bl ListMenuHandleInputGetItemId\n\ - adds r4, r0, 0\n\ - movs r0, 0x2\n\ - negs r0, r0\n\ - cmp r4, r0\n\ - beq _0813A51C\n\ - adds r0, 0x1\n\ - cmp r4, r0\n\ - bne _0813A530\n\ - b _0813A566\n\ - .pool\n\ -_0813A51C:\n\ - ldr r1, =gSpecialVar_Result\n\ - movs r0, 0x7F\n\ - strh r0, [r1]\n\ - movs r0, 0x5\n\ - bl PlaySE\n\ - b _0813A54C\n\ - .pool\n\ -_0813A530:\n\ - ldr r0, =gSpecialVar_Result\n\ - strh r4, [r0]\n\ - movs r0, 0x5\n\ - bl PlaySE\n\ - movs r1, 0x14\n\ - ldrsh r0, [r6, r1]\n\ - cmp r0, 0\n\ - beq _0813A54C\n\ - movs r1, 0xA\n\ - ldrsh r0, [r6, r1]\n\ - subs r0, 0x1\n\ - cmp r4, r0\n\ - bne _0813A558\n\ -_0813A54C:\n\ - adds r0, r5, 0\n\ - bl sub_813A570\n\ - b _0813A566\n\ - .pool\n\ -_0813A558:\n\ - adds r0, r5, 0\n\ - bl sub_813A738\n\ - ldr r0, =sub_813A600\n\ - str r0, [r6]\n\ - bl EnableBothScriptContexts\n\ -_0813A566:\n\ - pop {r4-r6}\n\ - pop {r0}\n\ - bx r0\n\ - .pool"); -} -#endif // NONMATCHING static void sub_813A570(u8 taskId) { diff --git a/src/pokemon.c b/src/pokemon.c index 7227d28cb..e29aab75b 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2879,10 +2879,10 @@ void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 m u8 language; u32 otId = gApprentices[src->id].otId; u32 personality = ((gApprentices[src->id].otId >> 8) | ((gApprentices[src->id].otId & 0xFF) << 8)) - + src->monData[monId].species + src->number; + + src->party[monId].species + src->number; CreateMon(mon, - src->monData[monId].species, + src->party[monId].species, GetFrontierEnemyMonLevel(src->lvlMode - 1), 0x1F, TRUE, @@ -2890,9 +2890,9 @@ void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 m TRUE, otId); - SetMonData(mon, MON_DATA_HELD_ITEM, &src->monData[monId].item); + SetMonData(mon, MON_DATA_HELD_ITEM, &src->party[monId].item); for (i = 0; i < 4; i++) - SetMonMoveSlot(mon, src->monData[monId].moves[i], i); + SetMonMoveSlot(mon, src->party[monId].moves[i], i); evAmount = MAX_TOTAL_EVS / NUM_STATS; for (i = 0; i < NUM_STATS; i++) diff --git a/src/record_mixing.c b/src/record_mixing.c index 11c3f2fef..4bb97cf1d 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -213,7 +213,7 @@ static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest) memcpy(&dest->oldMan, sOldManSave, sizeof(dest->oldMan)); memcpy(dest->easyChatPairs, sEasyChatPairsSave, sizeof(dest->easyChatPairs)); sub_80E89F8(&dest->dayCareMail); - sub_81659DC(sBattleTowerSave, &dest->battleTowerRecord); + EmeraldBattleTowerRecordToRuby(sBattleTowerSave, &dest->battleTowerRecord); if (GetMultiplayerId() == 0) dest->giftItem = GetRecordMixingGift(); @@ -231,7 +231,7 @@ static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest) memcpy(dest->easyChatPairs, sEasyChatPairsSave, sizeof(dest->easyChatPairs)); sub_80E89F8(&dest->dayCareMail); SanitizeDayCareMailForRuby(&dest->dayCareMail); - sub_81659DC(sBattleTowerSave, &dest->battleTowerRecord); + EmeraldBattleTowerRecordToRuby(sBattleTowerSave, &dest->battleTowerRecord); SanitizeRubyBattleTowerRecord(&dest->battleTowerRecord); if (GetMultiplayerId() == 0) diff --git a/src/tv.c b/src/tv.c index 3625c6cee..897f9950b 100644 --- a/src/tv.c +++ b/src/tv.c @@ -2540,8 +2540,8 @@ void sub_80EE8C8(u16 winStreak, u8 facility) show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); break; case 4: - show->frontier.species1 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.field_CAA[0] - 1], MON_DATA_SPECIES, NULL); - show->frontier.species2 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.field_CAA[1] - 1], MON_DATA_SPECIES, NULL); + show->frontier.species1 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[0] - 1], MON_DATA_SPECIES, NULL); + show->frontier.species2 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[1] - 1], MON_DATA_SPECIES, NULL); break; } tv_store_id_3x(show); From 1efdaebe2395c8c202b2086d485b7f348dc42783 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 25 Oct 2018 21:27:10 +0200 Subject: [PATCH 6/8] finish decompiling battle tower --- asm/battle_tower.s | 181 -------------------- data/battle_tower.s | 54 ------ data/use_pokeblock.s | 2 + include/battle_tower.h | 45 +++-- ld_script.txt | 2 +- src/battle_tower.c | 380 +++++++++++++++++++++++++++++------------ 6 files changed, 308 insertions(+), 356 deletions(-) delete mode 100644 asm/battle_tower.s diff --git a/asm/battle_tower.s b/asm/battle_tower.s deleted file mode 100644 index 975596c7b..000000000 --- a/asm/battle_tower.s +++ /dev/null @@ -1,181 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - - - thumb_func_start sub_81660B8 -sub_81660B8: @ 81660B8 - push {lr} - lsls r0, 24 - lsrs r2, r0, 24 - movs r1, 0 - ldr r3, =gTowerMaleFacilityClasses - ldrb r0, [r3] - cmp r0, r2 - beq _081660DA -_081660C8: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x1D - bhi _081660DA - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _081660C8 -_081660DA: - cmp r1, 0x1E - beq _081660EC - ldr r0, =gTowerMaleTrainerGfxIds - b _08166116 - .pool -_081660EC: - movs r1, 0 - ldr r3, =gTowerFemaleFacilityClasses - ldrb r0, [r3] - cmp r0, r2 - beq _08166108 -_081660F6: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x13 - bhi _08166108 - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _081660F6 -_08166108: - cmp r1, 0x14 - bne _08166114 - movs r0, 0x7 - b _0816611A - .pool -_08166114: - ldr r0, =gTowerFemaleTrainerGfxIds -_08166116: - adds r0, r1, r0 - ldrb r0, [r0] -_0816611A: - pop {r1} - bx r1 - .pool - thumb_func_end sub_81660B8 - - thumb_func_start sub_8166124 -sub_8166124: @ 8166124 - push {r4-r6,lr} - lsls r0, 24 - lsrs r6, r0, 24 - ldr r2, =gSaveBlock2Ptr - movs r0, 0xEC - muls r0, r6 - movs r1, 0xE7 - lsls r1, 3 - adds r0, r1 - ldr r1, [r2] - movs r5, 0 - movs r4, 0 - movs r3, 0 - adds r1, r0 -_08166140: - ldm r1!, {r0} - adds r5, r0 - orrs r4, r0 - adds r3, 0x1 - cmp r3, 0x39 - bls _08166140 - cmp r5, 0 - bne _08166154 - cmp r4, 0 - beq _08166180 -_08166154: - ldr r2, [r2] - movs r0, 0xEC - adds r1, r6, 0 - muls r1, r0 - movs r3, 0x82 - lsls r3, 4 - adds r0, r2, r3 - adds r0, r1 - ldr r0, [r0] - cmp r0, r5 - bne _08166174 - movs r0, 0x1 - b _08166182 - .pool -_08166174: - movs r3, 0xE7 - lsls r3, 3 - adds r0, r1, r3 - adds r0, r2, r0 - bl ClearBattleTowerRecord -_08166180: - movs r0, 0 -_08166182: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_8166124 - - thumb_func_start sub_8166188 -sub_8166188: @ 8166188 - push {r4-r7,lr} - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x02000002 - ands r0, r1 - cmp r0, 0 - beq _081661E8 - bl SetFacilityPtrsGetLevel - lsls r0, 24 - movs r5, 0 - ldr r7, =gBaseStats - lsrs r0, 22 - ldr r1, =gExperienceTables - adds r6, r0, r1 -_081661A6: - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gEnemyParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - cmp r1, 0 - beq _081661E2 - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r7 - ldrb r1, [r0, 0x13] - movs r0, 0xCA - lsls r0, 1 - adds r2, r1, 0 - muls r2, r0 - adds r2, r6 - adds r0, r4, 0 - movs r1, 0x19 - bl SetMonData - adds r0, r4, 0 - bl CalculateMonStats -_081661E2: - adds r5, 0x1 - cmp r5, 0x5 - ble _081661A6 -_081661E8: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8166188 - - .align 2, 0 @ Don't pad with nop. diff --git a/data/battle_tower.s b/data/battle_tower.s index 63eec4347..9f7e1ade4 100644 --- a/data/battle_tower.s +++ b/data/battle_tower.s @@ -677,57 +677,3 @@ gUnknown_085DD6DC:: @ 85DD6DC @ 85DF69C .include "data/battle_frontier/fallarbor_battle_tent_mons.inc" - - .align 2 -gUnknown_085DF96C:: @ 85DF96C - .4byte sub_8161F94 - .4byte sub_8162054 - .4byte sub_81620F4 - .4byte ChooseNextBattleTowerTrainer - .4byte sub_81621C0 - .4byte AwardBattleTowerRibbons - .4byte SaveBattleTowerProgress - .4byte sub_8163914 - .4byte nullsub_61 - .4byte nullsub_116 - .4byte sub_81642A0 - .4byte sub_8164828 - .4byte sub_8164B74 - .4byte sub_8164DCC - .4byte sub_8164DE4 - .4byte sub_8164E04 - - .align 2 -gUnknown_085DF9AC:: @ 85DF9AC - .4byte 0x00000001, 0x00000002, 0x00004000, 0x00008000, 0x00010000, 0x00020000, 0x00040000, 0x00080000 - - .align 2 -gUnknown_085DF9CC:: @ 85DF9CC - .4byte 0xfffffffe, 0xfffffffd, 0xffffbfff, 0xffff7fff, 0xfffeffff, 0xfffdffff, 0xfffbffff, 0xfff7ffff - -gUnknown_085DF9EC:: @ 85DF9EC - .byte 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0a, 0x0b, 0x0c - -gUnknown_085DF9F6:: @ 85DF9F6 - .byte 0x03, 0x04, 0x02, 0x02 - - .align 1 -gUnknown_085DF9FA:: @ 85DF9FA - .2byte 0x0000, 0x0063, 0x0050, 0x0077, 0x0064, 0x008b, 0x0078, 0x009f, 0x008c, 0x00b3, 0x00a0, 0x00c7, 0x00b4, 0x00db, 0x00c8, 0x012b - - .align 1 -gUnknown_085DFA1A:: @ 85DFA1A - .2byte 0x0064, 0x0077, 0x0078, 0x008b, 0x008c, 0x009f, 0x00a0, 0x00b3, 0x00b4, 0x00c7, 0x00c8, 0x00db, 0x00dc, 0x00ef, 0x00c8, 0x012b - .2byte 0x00b3, 0x008d, 0x00c8, 0x00b7 - -gUnknown_085DFA42:: @ 85DFA42 - .byte 0x03, 0x04, 0x02, 0x02 - - .align 1 -gUnknown_085DFA46:: @ 85DFA46 - .2byte 0x0c3a, 0x0c3a, 0x0c01, 0x0a2a, 0x0607, 0x0c01 - - .align 1 -gUnknown_085DFA52:: @ 85DFA52 - .2byte 0x1039, 0x122e, 0x0c04, 0x0a3d, 0x0630, 0x0c04, 0x0000 - diff --git a/data/use_pokeblock.s b/data/use_pokeblock.s index 8497f59ad..c257961d3 100644 --- a/data/use_pokeblock.s +++ b/data/use_pokeblock.s @@ -2,6 +2,8 @@ .include "constants/constants.inc" .section .rodata + +.align 4 gUnknown_085DFA60:: @ 85DFA60 .incbin "graphics/interface/85DFA60.bin" diff --git a/include/battle_tower.h b/include/battle_tower.h index 39d75f8be..137ce8a54 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -17,12 +17,6 @@ struct RSBattleTowerRecord /*0xA0*/ u32 checksum; }; -union BattleTowerRecord -{ - struct RSBattleTowerRecord ruby_sapphire; - struct EmeraldBattleTowerRecord emerald; -}; - struct BattleFrontierTrainer { u8 facilityClass; @@ -51,16 +45,39 @@ extern const u8 gTowerFemaleTrainerGfxIds[20]; extern const struct BattleFrontierTrainer *gFacilityTrainers; extern const struct FacilityMon *gFacilityTrainerMons; -u16 GetCurrentBattleTowerWinStreak(u8, u8); -bool32 EmeraldBattleTowerRecordToRuby(struct EmeraldBattleTowerRecord *src, struct RSBattleTowerRecord *dst); -bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct EmeraldBattleTowerRecord *dst); -void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *); -void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm); +void sub_8161F74(void); +u16 sub_8162548(u8 challengeNum, u8 battleNum); void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId); -void FrontierSpeechToString(const u16 *words); -void GetFrontierTrainerName(u8 *dest, u16 trainerIdx); -void GetEreaderTrainerName(u8 *dest); +void SetEReaderTrainerGfxId(void); +u8 GetBattleFacilityTrainerGfxId(u16 trainerId); +void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm); +u8 GetFrontierTrainerFrontSpriteId(u16 trainerId); +u8 GetFrontierOpponentClass(u16 trainerId); +void GetFrontierTrainerName(u8 *dst, u16 trainerId); void FillFrontierTrainerParty(u8 monsCount); void FillFrontierTrainersParties(u8 monsCount); +u16 RandomizeFacilityTrainerMonId(u16 trainerId); +void FrontierSpeechToString(const u16 *words); +void DoSpecialTrainerBattle(void); +void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *record); +void CalcRubyBattleTowerChecksum(struct RSBattleTowerRecord *record); +u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode); +u8 GetEreaderTrainerFrontSpriteId(void); +u8 GetEreaderTrainerClassId(void); +void GetEreaderTrainerName(u8 *dst); +void ValidateEReaderTrainer(void); +void ClearEReaderTrainer(struct BattleTowerEReaderTrainer *ereaderTrainer); +void CopyEReaderTrainerGreeting(void); +void sub_81653CC(void); +bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct EmeraldBattleTowerRecord *dst); +bool32 EmeraldBattleTowerRecordToRuby(struct EmeraldBattleTowerRecord *src, struct RSBattleTowerRecord *dst); +void CalcApprenticeChecksum(struct Apprentice *apprentice); +void GetBattleTowerTrainerLanguage(u8 *dst, u16 trainerId); +u8 SetFacilityPtrsGetLevel(void); +u8 GetFrontierEnemyMonLevel(u8 lvlMode); +s32 GetHighestLevelInPlayerParty(void); +u8 sub_81660B8(u8 facilityClass); +bool32 ValidateBattleTowerRecord(u8 recordId); // unused +void sub_8166188(void); #endif //GUARD_BATTLE_TOWER_H diff --git a/ld_script.txt b/ld_script.txt index 77f95e96f..1582f01e5 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -211,7 +211,6 @@ SECTIONS { src/decoration_inventory.o(.text); src/roamer.o(.text); src/battle_tower.o(.text); - asm/battle_tower.o(.text); src/use_pokeblock.o(.text); asm/use_pokeblock.o(.text); src/battle_controller_wally.o(.text); @@ -500,6 +499,7 @@ SECTIONS { src/learn_move.o(.rodata); src/roamer.o(.rodata); data/battle_tower.o(.rodata); + src/battle_tower.o(.rodata); src/use_pokeblock.o(.rodata); data/use_pokeblock.o(.rodata); src/battle_controller_wally.o(.rodata); diff --git a/src/battle_tower.c b/src/battle_tower.c index cefb02c8d..b03429554 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -28,11 +28,11 @@ #include "constants/moves.h" #include "constants/species.h" +extern u16 gUnknown_03006298[]; + extern void sub_81A3ACC(void); extern void CreateFrontierBrainPokemon(void); extern void sub_81A6CD0(void); -extern u8 GetFrontierEnemyMonLevel(u8); -extern u8 SetFacilityPtrsGetLevel(void); extern u16 sub_81A39C4(void); extern void SetFrontierBrainTrainerGfxId(void); extern u8 GetFrontierBrainTrainerPicIndex(void); @@ -41,31 +41,153 @@ extern u8 IsFrontierBrainFemale(void); extern void CopyFrontierBrainTrainerName(u8 *dst); extern void SetMonMoveAvoidReturn(struct Pokemon *mon, u16 move, u8 moveSlot); -extern const u32 gUnknown_085DF9AC[][2]; -extern const u32 gUnknown_085DF9CC[][2]; -extern void (* const gUnknown_085DF96C[])(void); -extern const u8 gUnknown_085DF9F6[]; -extern const u8 gUnknown_085DF9EC[]; +extern const u8 *const *const gUnknown_085DD690[]; extern const u16 gBattleFrontierHeldItems[]; +extern const u8 sRubyFacilityClassToEmerald[82][2]; +extern const u16 gUnknown_085DFA46[]; +extern const struct FacilityMon gBattleFrontierMons[]; +extern const struct FacilityMon gSlateportBattleTentMons[]; +extern const struct FacilityMon gVerdanturfBattleTentMons[]; +extern const struct FacilityMon gFallarborBattleTentMons[]; +extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; +extern const struct BattleFrontierTrainer gSlateportBattleTentTrainers[]; +extern const struct BattleFrontierTrainer gVerdanturfBattleTentTrainers[]; +extern const struct BattleFrontierTrainer gFallarborBattleTentTrainers[]; + +struct +{ + u32 facilityClass; + const u8 *const *strings; +} extern const gUnknown_085DD500[50]; + +extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224157[]; +extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224166[]; // This file's functions. -void ValidateBattleTowerRecordChecksums(void); -void SaveCurrentWinStreak(void); -void ValidateApprenticesChecksums(void); -void sub_8165E18(void); -void CopyEReaderTrainerFarewellMessage(void); -void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record); -u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode); -u16 sub_8162548(u8, u8); +static void sub_8161F94(void); +static void sub_8162054(void); +static void sub_81620F4(void); +static void ChooseNextBattleTowerTrainer(void); +static void sub_81621C0(void); +static void AwardBattleTowerRibbons(void); +static void SaveBattleTowerProgress(void); +static void sub_8163914(void); +static void nullsub_61(void); +static void nullsub_116(void); +static void sub_81642A0(void); +static void sub_8164828(void); +static void sub_8164B74(void); +static void sub_8164DCC(void); +static void sub_8164DE4(void); +static void sub_8164E04(void); +static void ValidateBattleTowerRecordChecksums(void); +static void SaveCurrentWinStreak(void); +static void ValidateApprenticesChecksums(void); +static void sub_8165E18(void); +static void CopyEReaderTrainerFarewellMessage(void); +static void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record); static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount); -void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount); -void sub_81635D4(u16 trainerId, u8 firstMonId); -void sub_816379C(u16 trainerId, u8 firstMonId); -u8 GetFrontierTrainerFixedIvs(u16 trainerId); -void FillPartnerParty(u16 trainerId); -void GetBattleTowerTrainerLanguage(u8 *dst, u16 trainerId); -void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer); -void ClearEReaderTrainer(struct BattleTowerEReaderTrainer *ereaderTrainer); +static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount); +static void sub_81635D4(u16 trainerId, u8 firstMonId); +static void sub_816379C(u16 trainerId, u8 firstMonId); +static u8 GetFrontierTrainerFixedIvs(u16 trainerId); +static void FillPartnerParty(u16 trainerId); +static void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer); +static u8 SetTentPtrsGetLevel(void); + +// Const rom data. +static void (* const gUnknown_085DF96C[])(void) = +{ + sub_8161F94, + sub_8162054, + sub_81620F4, + ChooseNextBattleTowerTrainer, + sub_81621C0, + AwardBattleTowerRibbons, + SaveBattleTowerProgress, + sub_8163914, + nullsub_61, + nullsub_116, + sub_81642A0, + sub_8164828, + sub_8164B74, + sub_8164DCC, + sub_8164DE4, + sub_8164E04, +}; + +static const u32 gUnknown_085DF9AC[][2] = +{ + {0x00000001, 0x00000002}, + {0x00004000, 0x00008000}, + {0x00010000, 0x00020000}, + {0x00040000, 0x00080000}, +}; + +static const u32 gUnknown_085DF9CC[][2] = +{ + {0xfffffffe, 0xfffffffd}, + {0xffffbfff, 0xffff7fff}, + {0xfffeffff, 0xfffdffff}, + {0xfffbffff, 0xfff7ffff}, +}; + +static const u8 gUnknown_085DF9EC[] = +{ + 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0a, 0x0b, 0x0c +}; + +static const u8 gUnknown_085DF9F6[] = +{ + [FRONTIER_MODE_SINGLES] = 3, + [FRONTIER_MODE_DOUBLES] = 4, + [FRONTIER_MODE_MULTIS] = 2, + [FRONTIER_MODE_LINK_MULTIS] = 2, +}; + +static const u16 gUnknown_085DF9FA[][2] = +{ + {0x0000, 0x0063}, + {0x0050, 0x0077}, + {0x0064, 0x008b}, + {0x0078, 0x009f}, + {0x008c, 0x00b3}, + {0x00a0, 0x00c7}, + {0x00b4, 0x00db}, + {0x00c8, 0x012b}, +}; + +static const u16 gUnknown_085DFA1A[][2] = +{ + {0x0064, 0x0077}, + {0x0078, 0x008b}, + {0x008c, 0x009f}, + {0x00a0, 0x00b3}, + {0x00b4, 0x00c7}, + {0x00c8, 0x00db}, + {0x00dc, 0x00ef}, + {0x00c8, 0x012b}, + {0x00b3, 0x008d}, + {0x00c8, 0x00b7}, +}; + +static const u8 gUnknown_085DFA42[4] = +{ + [FRONTIER_MODE_SINGLES] = 3, + [FRONTIER_MODE_DOUBLES] = 4, + [FRONTIER_MODE_MULTIS] = 2, + [FRONTIER_MODE_LINK_MULTIS] = 2, +}; + +static const u16 gUnknown_085DFA46[] = +{ + 0x0c3a, 0x0c3a, 0x0c01, 0x0a2a, 0x0607, 0x0c01 +}; + +static const u16 gUnknown_085DFA52[] = +{ + 0x1039, 0x122e, 0x0c04, 0x0a3d, 0x0630, 0x0c04 +}; // code void sub_8161F74(void) @@ -73,7 +195,7 @@ void sub_8161F74(void) gUnknown_085DF96C[gSpecialVar_0x8004](); } -void sub_8161F94(void) +static void sub_8161F94(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); @@ -91,7 +213,7 @@ void sub_8161F94(void) gTrainerBattleOpponent_A = 0; } -void sub_8162054(void) +static void sub_8162054(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); @@ -112,7 +234,7 @@ void sub_8162054(void) } } -void sub_81620F4(void) +static void sub_81620F4(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); @@ -136,7 +258,7 @@ void sub_81620F4(void) } } -void sub_81621C0(void) +static void sub_81621C0(void) { if (gTrainerBattleOpponent_A == BATTLE_TOWER_EREADER_TRAINER_ID) ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); @@ -149,7 +271,7 @@ void sub_81621C0(void) gSpecialVar_Result = gSaveBlock2Ptr->frontier.curChallengeBattleNum; } -bool8 ChooseSpecialBattleTowerTrainer(void) +static bool8 ChooseSpecialBattleTowerTrainer(void) { s32 i, j, validMons; s32 trainerIds[9]; @@ -217,7 +339,7 @@ bool8 ChooseSpecialBattleTowerTrainer(void) } } -void ChooseNextBattleTowerTrainer(void) +static void ChooseNextBattleTowerTrainer(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; if (lvlMode == FRONTIER_LVL_TENT) @@ -269,9 +391,6 @@ void ChooseNextBattleTowerTrainer(void) } } -extern const u16 gUnknown_085DFA1A[][2]; -extern const u16 gUnknown_085DF9FA[][2]; - u16 sub_8162548(u8 challengeNum, u8 battleNum) { u16 trainerId; @@ -299,7 +418,7 @@ u16 sub_8162548(u8 challengeNum, u8 battleNum) } #ifdef NONMATCHING -u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) // Unused +static u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) // Unused { register u16 trainerId, count; @@ -327,7 +446,7 @@ u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) // U } #else NAKED -u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) +static u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) { asm_unified(" push {r4,lr}\n\ adds r4, r2, 0\n\ @@ -619,7 +738,7 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) { - SetFacilityPtrsGetLevel(); // Pointless function call + SetFacilityPtrsGetLevel(); if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) { @@ -698,7 +817,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) return trainerClass; } -u8 GetFrontierTrainerFacilityClass(u16 trainerId) +static u8 GetFrontierTrainerFacilityClass(u16 trainerId) { u8 facilityClass; SetFacilityPtrsGetLevel(); @@ -790,7 +909,7 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) dst[i] = EOS; } -bool8 IsFrontierTrainerFemale(u16 trainerId) +static bool8 IsFrontierTrainerFemale(u16 trainerId) { u32 i; u8 facilityClass; @@ -842,7 +961,7 @@ void FillFrontierTrainersParties(u8 monsCount) FillTrainerParty(gTrainerBattleOpponent_B, 3, monsCount); } -void FillTentTrainerParty(u8 monsCount) +static void FillTentTrainerParty(u8 monsCount) { ZeroEnemyPartyMons(); FillTentTrainerParty_(gTrainerBattleOpponent_A, 0, monsCount); @@ -970,7 +1089,7 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) } // Probably an early draft before the 'CreateApprenticeMon' was written. -void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) +static void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) { s32 i, j; u8 friendship = 0xFF; @@ -1025,7 +1144,7 @@ u16 RandomizeFacilityTrainerMonId(u16 trainerId) return monPoolId; } -void sub_8163590(void) +static void sub_8163590(void) { ZeroEnemyPartyMons(); if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) @@ -1034,9 +1153,7 @@ void sub_8163590(void) sub_816379C(gTrainerBattleOpponent_A, 0); } -extern u16 gUnknown_03006298[]; - -void sub_81635D4(u16 trainerId, u8 firstMonId) +static void sub_81635D4(u16 trainerId, u8 firstMonId) { u8 i, j; u8 friendship; @@ -1093,7 +1210,7 @@ void sub_81635D4(u16 trainerId, u8 firstMonId) } } -void sub_816379C(u16 trainerId, u8 firstMonId) +static void sub_816379C(u16 trainerId, u8 firstMonId) { u8 i, j; u8 friendship; @@ -1142,7 +1259,7 @@ void FrontierSpeechToString(const u16 *words) } } -void sub_8163914(void) +static void sub_8163914(void) { u16 trainerId; SetFacilityPtrsGetLevel(); @@ -1213,9 +1330,6 @@ static void Task_StartBattleAfterTransition(u8 taskId) } } -extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224157[]; -extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224166[]; - void DoSpecialTrainerBattle(void) { s32 i; @@ -1346,7 +1460,7 @@ void DoSpecialTrainerBattle(void) } } -void SaveCurrentWinStreak(void) +static void SaveCurrentWinStreak(void) { u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); @@ -1356,7 +1470,7 @@ void SaveCurrentWinStreak(void) gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] = winStreak; } -void sub_8163EE4(void) +static void sub_8163EE4(void) { s32 i; u8 lvlMode, battleMode, class; @@ -1403,7 +1517,7 @@ void sub_8163EE4(void) SaveCurrentWinStreak(); } -void SaveBattleTowerProgress(void) +static void SaveBattleTowerProgress(void) { u16 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); @@ -1418,17 +1532,17 @@ void SaveBattleTowerProgress(void) sub_81A4C30(); } -void nullsub_61(void) +static void nullsub_61(void) { } -void nullsub_116(void) +static void nullsub_116(void) { } -void sub_81640E0(u16 trainerId) +static void sub_81640E0(u16 trainerId) { s32 i, count; u32 validSpecies[3]; @@ -1453,7 +1567,7 @@ void sub_81640E0(u16 trainerId) } while (gUnknown_03006298[0] == gUnknown_03006298[1]); } -void sub_8164188(u16 trainerId) +static void sub_8164188(u16 trainerId) { s32 i, count; u32 validSpecies[3]; @@ -1481,7 +1595,7 @@ void sub_8164188(u16 trainerId) } while (gUnknown_03006298[2] == gUnknown_03006298[3]); } -void sub_81642A0(void) +static void sub_81642A0(void) { s32 i, j, k; u32 spArray[5]; @@ -1627,7 +1741,7 @@ void sub_81642A0(void) } } -void sub_81646BC(u16 trainerId, u16 monPoolId) +static void sub_81646BC(u16 trainerId, u16 monPoolId) { u16 move = 0; u16 species = 0; @@ -1662,16 +1776,7 @@ void sub_81646BC(u16 trainerId, u16 monPoolId) StringCopy(gStringVar2, gSpeciesNames[species]); } -struct -{ - u32 facilityClass; - const u8 *const *strings; -} extern const gUnknown_085DD500[50]; - -extern const u8 *const *const gUnknown_085DD690[]; -extern const u8 gUnknown_085DFA42[4]; - -void sub_8164828(void) +static void sub_8164828(void) { s32 i, j, arrId; s32 monPoolId; @@ -1777,7 +1882,7 @@ void sub_8164828(void) } } -void sub_8164B74(void) +static void sub_8164B74(void) { s32 challengeNum; s32 i, j; @@ -1866,18 +1971,18 @@ void sub_8164B74(void) } } -void sub_8164DCC(void) +static void sub_8164DCC(void) { if (gWirelessCommType != 0) sub_800AC34(); } -void sub_8164DE4(void) +static void sub_8164DE4(void) { SetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.field_CB4[17], 0xF); } -void sub_8164E04(void) +static void sub_8164E04(void) { s32 i; u8 text[32]; @@ -1896,7 +2001,7 @@ void sub_8164E04(void) gSaveBlock2Ptr->frontier.field_D06 = gBattleOutcome; } -void ValidateBattleTowerRecordChecksums(void) +static void ValidateBattleTowerRecordChecksums(void) { s32 i, j; u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerPlayer); @@ -1940,7 +2045,7 @@ void CalcRubyBattleTowerChecksum(struct RSBattleTowerRecord *record) record->checksum += ((u32 *)record)[i]; } -void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record) +static void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record) { u32 i; @@ -1958,7 +2063,7 @@ u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode) return winStreak; } -u8 GetMonCountForBattleMode(u8 battleMode) +static u8 GetMonCountForBattleMode(u8 battleMode) { u8 sp[ARRAY_COUNT(gUnknown_085DFA42)]; memcpy(sp, gUnknown_085DFA42, sizeof(gUnknown_085DFA42)); @@ -1975,7 +2080,7 @@ struct RibbonCounter u8 count; }; -void AwardBattleTowerRibbons(void) +static void AwardBattleTowerRibbons(void) { s32 i; u32 partyIndex; @@ -2029,7 +2134,7 @@ void AwardBattleTowerRibbons(void) // This is a leftover debugging function that is used to populate the E-Reader // trainer with the player's current data. -void FillEReaderTrainerWithPlayerData(void) +static void FillEReaderTrainerWithPlayerData(void) { struct BattleTowerEReaderTrainer *ereaderTrainer = &gSaveBlock2Ptr->frontier.ereaderTrainer; s32 i, j; @@ -2075,14 +2180,14 @@ u8 GetEreaderTrainerClassId(void) return gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass]; } -void GetEreaderTrainerName(u8 *trainerName) +void GetEreaderTrainerName(u8 *dst) { s32 i; for (i = 0; i < 5; i++) - trainerName[i] = gSaveBlock2Ptr->frontier.ereaderTrainer.name[i]; + dst[i] = gSaveBlock2Ptr->frontier.ereaderTrainer.name[i]; - trainerName[i] = EOS; + dst[i] = EOS; } // Checks if the saved E-Reader trainer is valid. @@ -2116,7 +2221,7 @@ void ValidateEReaderTrainer(void) } } -void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer) +static void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer) { s32 i; @@ -2138,7 +2243,7 @@ void CopyEReaderTrainerGreeting(void) FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.greeting); } -void CopyEReaderTrainerFarewellMessage(void) +static void CopyEReaderTrainerFarewellMessage(void) { if (gBattleOutcome == B_OUTCOME_DREW) gStringVar4[0] = EOS; @@ -2173,7 +2278,7 @@ extern const struct StevenMon sStevenMons[3]; #define STEVEN_OTID 61226 -void FillPartnerParty(u16 trainerId) +static void FillPartnerParty(u16 trainerId) { s32 i, j; u32 ivs, level; @@ -2282,10 +2387,6 @@ void FillPartnerParty(u16 trainerId) } } -extern const u8 sRubyFacilityClassToEmerald[82][2]; -extern const u16 gUnknown_085DFA46[]; -extern const u16 gUnknown_085DFA52[]; - bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct EmeraldBattleTowerRecord *dst) { s32 i, validMons = 0; @@ -2386,7 +2487,7 @@ void CalcApprenticeChecksum(struct Apprentice *apprentice) apprentice->checksum += ((u32 *)apprentice)[i]; } -void ClearApprentice(struct Apprentice *apprentice) +static void ClearApprentice(struct Apprentice *apprentice) { s32 i; @@ -2395,7 +2496,7 @@ void ClearApprentice(struct Apprentice *apprentice) ResetApprenticeStruct(apprentice); } -void ValidateApprenticesChecksums(void) +static void ValidateApprenticesChecksums(void) { s32 i, j; @@ -2436,19 +2537,6 @@ void GetBattleTowerTrainerLanguage(u8 *dst, u16 trainerId) } } -extern const struct FacilityMon gBattleFrontierMons[]; -extern const struct FacilityMon gSlateportBattleTentMons[]; -extern const struct FacilityMon gVerdanturfBattleTentMons[]; -extern const struct FacilityMon gFallarborBattleTentMons[]; - -extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; -extern const struct BattleFrontierTrainer gSlateportBattleTentTrainers[]; -extern const struct BattleFrontierTrainer gVerdanturfBattleTentTrainers[]; -extern const struct BattleFrontierTrainer gFallarborBattleTentTrainers[]; - -u8 SetTentPtrsGetLevel(void); -s32 GetHighestLevelInPlayerParty(void); - u8 SetFacilityPtrsGetLevel(void) { if (gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_TENT) @@ -2502,7 +2590,7 @@ s32 GetHighestLevelInPlayerParty(void) return highestLevel; } -u8 GetFrontierTrainerFixedIvs(u16 trainerId) +static u8 GetFrontierTrainerFixedIvs(u16 trainerId) { u8 fixedIV = 0; @@ -2526,7 +2614,7 @@ u8 GetFrontierTrainerFixedIvs(u16 trainerId) return fixedIV; } -u16 sub_8165D40(void) +static u16 sub_8165D40(void) { u32 facility = VarGet(VAR_FRONTIER_FACILITY); @@ -2542,7 +2630,7 @@ u16 sub_8165D40(void) return 0; } -u8 SetTentPtrsGetLevel(void) +static u8 SetTentPtrsGetLevel(void) { u8 level = 30; u32 tentFacility = VarGet(VAR_FRONTIER_FACILITY); @@ -2575,7 +2663,7 @@ u8 SetTentPtrsGetLevel(void) return level; } -void sub_8165E18(void) +static void sub_8165E18(void) { s32 i; u16 trainerId; @@ -2596,7 +2684,7 @@ void sub_8165E18(void) gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; } -void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount) +static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount) { s32 i, j; u16 chosenMonIndices[4]; @@ -2683,3 +2771,83 @@ void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount) i++; } } + +u8 sub_81660B8(u8 facilityClass) +{ + u8 trainerObjectGfxId; + u8 i; + + // Search male classes. + for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses); i++) + { + if (gTowerMaleFacilityClasses[i] == facilityClass) + break; + } + if (i != ARRAY_COUNT(gTowerMaleFacilityClasses)) + { + trainerObjectGfxId = gTowerMaleTrainerGfxIds[i]; + return trainerObjectGfxId; + } + + // Search female classes. + for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++) + { + if (gTowerFemaleFacilityClasses[i] == facilityClass) + break; + } + if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses)) + { + trainerObjectGfxId = gTowerFemaleTrainerGfxIds[i]; + return trainerObjectGfxId; + } + else + { + return EVENT_OBJ_GFX_BOY_1; + } +} + +bool32 ValidateBattleTowerRecord(u8 recordId) // unused +{ + s32 i; + u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[recordId]); + u32 checksum = 0; + u32 hasData = 0; + for (i = 0; i < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; i++) // - 4, because of the last fjeld bejng the checksum jtself. + { + checksum += record[i]; + hasData |= record[i]; + } + + if (checksum == 0 && hasData == 0) + { + return FALSE; + } + else if (gSaveBlock2Ptr->frontier.towerRecords[recordId].checksum != checksum) + { + ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerRecords[recordId]); + return FALSE; + } + else + { + return TRUE; + } +} + +void sub_8166188(void) +{ + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + { + s32 i; + u8 enemyLevel = SetFacilityPtrsGetLevel(); + + for (i = 0; i < PARTY_SIZE; i++) + { + u32 species = GetMonData(&gEnemyParty[i], MON_DATA_SPECIES, NULL); + if (species) + { + SetMonData(&gEnemyParty[i], MON_DATA_EXP, &gExperienceTables[gBaseStats[species].growthRate][enemyLevel]); + CalculateMonStats(&gEnemyParty[i]); + } + } + } +} From dc273cc19d842e8831548a1342af857aae2886c9 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 26 Oct 2018 23:54:41 +0200 Subject: [PATCH 7/8] Battle tower - ewram variables --- include/battle_tower.h | 4 - include/constants/trainers.h | 15 ++- src/apprentice.c | 2 - src/battle_main.c | 4 +- src/battle_message.c | 7 +- src/battle_tower.c | 228 ++++++++++++++++++----------------- sym_ewram.txt | 8 +- 7 files changed, 128 insertions(+), 140 deletions(-) diff --git a/include/battle_tower.h b/include/battle_tower.h index 137ce8a54..5fe8d1190 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -1,10 +1,6 @@ #ifndef GUARD_BATTLE_TOWER_H #define GUARD_BATTLE_TOWER_H -#define BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID 300 -#define BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID 400 -#define BATTLE_TOWER_EREADER_TRAINER_ID 500 - struct RSBattleTowerRecord { /*0x00*/ u8 lvlMode; // 0 = level 50, 1 = level 100 diff --git a/include/constants/trainers.h b/include/constants/trainers.h index f79216d94..2ea9f7c62 100644 --- a/include/constants/trainers.h +++ b/include/constants/trainers.h @@ -4,12 +4,15 @@ #include "constants/opponents.h" // Special Trainer Ids. -#define TRAINER_FRONTIER_BRAIN 1022 -#define TRAINER_PLAYER 1023 -#define TRAINER_SECRET_BASE 1024 -#define TRAINER_LINK_OPPONENT 2048 -#define TRAINER_OPPONENT_C00 3072 -#define TRAINER_STEVEN_PARTNER 3075 +#define TRAINER_RECORD_MIXING_FRIEND 300 +#define TRAINER_RECORD_MIXING_APPRENTICE 400 +#define TRAINER_EREADER 500 +#define TRAINER_FRONTIER_BRAIN 1022 +#define TRAINER_PLAYER 1023 +#define TRAINER_SECRET_BASE 1024 +#define TRAINER_LINK_OPPONENT 2048 +#define TRAINER_OPPONENT_C00 3072 +#define TRAINER_STEVEN_PARTNER 3075 #define TRAINER_PIC_HIKER 0 #define TRAINER_PIC_AQUA_GRUNT_M 1 diff --git a/src/apprentice.c b/src/apprentice.c index 9e01a072a..065d9cf16 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -344,8 +344,6 @@ extern struct Unk030062ECStruct *gUnknown_030062EC; extern struct Unk030062F0Struct *gUnknown_030062F0; extern void (*gUnknown_030062F4)(void); -extern void CalcApprenticeChecksum(struct Apprentice *); - // This file's functions. static u16 sub_819FF98(u8 arg0); static bool8 sub_81A0194(u8 arg0, u16 moveId); diff --git a/src/battle_main.c b/src/battle_main.c index b3fcaeeda..9f1ea3c01 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -52,6 +52,7 @@ #include "international_string_util.h" #include "pokeball.h" #include "party_menu.h" +#include "battle_tower.h" struct UnknownPokemonStruct4 { @@ -106,9 +107,6 @@ extern const u8 gText_Confusion[]; extern const u8 gText_Love[]; // functions -extern void GetFrontierTrainerName(u8* dst, u16 trainerId); // battle tower -extern void sub_8166188(void); // battle tower, sets link battle mons level but why? -extern void GetBattleTowerTrainerLanguage(u8* dst, u16 trainerId); // battle tower, gets language extern void sub_81B9150(void); extern void sub_80B3AF8(u8 taskId); // cable club extern void sub_81A56B4(void); // battle frontier 2 diff --git a/src/battle_message.c b/src/battle_message.c index a5f549733..99ab8bbd6 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -18,6 +18,8 @@ #include "recorded_battle.h" #include "international_string_util.h" #include "battle_frontier_2.h" +#include "battle_tower.h" +#include "data2.h" struct BattleWindowText { @@ -35,7 +37,6 @@ struct BattleWindowText extern u8 gUnknown_0203C7B4; -extern const u8 gMoveNames[MOVES_COUNT][13]; extern const u8 gTrainerClassNames[][13]; extern const u16 gUnknown_08D85620[]; @@ -46,14 +47,10 @@ extern const u8 gText_PkmnTransferredSomeonesPC[]; extern const u8 gText_PkmnTransferredLanettesPC[]; extern u8 GetFrontierBrainTrainerClass(void); // battle_frontier_2 -extern u8 GetFrontierOpponentClass(u16 trainerId); // battle_tower extern u8 GetTrainerHillOpponentClass(u16 trainerId); // pokenav -extern u8 GetEreaderTrainerClassId(void); // battle_tower extern void CopyFrontierBrainTrainerName(u8 *txtPtr); // battle_frontier_2 extern void GetTrainerHillTrainerName(u8 *txtPtr, u16 trainerId); // pokenav -extern void GetEreaderTrainerName(u8 *txtPtr); extern void CopyTrainerHillTrainerText(u8 arg0, u16 trainerId); // pokenav -extern void GetFrontierTrainerName(u8 *dst, u16 trainerId); // this file's functions static void ChooseMoveUsedParticle(u8 *textPtr); diff --git a/src/battle_tower.c b/src/battle_tower.c index b03429554..4b63c2875 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -60,9 +60,23 @@ struct const u8 *const *strings; } extern const gUnknown_085DD500[50]; +struct +{ + u16 species; + u8 fixedIV; + u8 level; + u8 nature; + u8 evs[6]; + u16 moves[4]; +} extern const sStevenMons[3]; + extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224157[]; extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224166[]; +// EWRAM vars. +EWRAM_DATA const struct BattleFrontierTrainer *gFacilityTrainers = NULL; +EWRAM_DATA const struct FacilityMon *gFacilityTrainerMons = NULL; + // This file's functions. static void sub_8161F94(void); static void sub_8162054(void); @@ -88,8 +102,8 @@ static void CopyEReaderTrainerFarewellMessage(void); static void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record); static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount); static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount); -static void sub_81635D4(u16 trainerId, u8 firstMonId); -static void sub_816379C(u16 trainerId, u8 firstMonId); +static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId); +static void FillFactoryTentTrainerParty(u16 trainerId, u8 firstMonId); static u8 GetFrontierTrainerFixedIvs(u16 trainerId); static void FillPartnerParty(u16 trainerId); static void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer); @@ -260,7 +274,7 @@ static void sub_81620F4(void) static void sub_81621C0(void) { - if (gTrainerBattleOpponent_A == BATTLE_TOWER_EREADER_TRAINER_ID) + if (gTrainerBattleOpponent_A == TRAINER_EREADER) ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); if (gSaveBlock2Ptr->frontier.field_D04 < 9999) @@ -308,7 +322,7 @@ static bool8 ChooseSpecialBattleTowerTrainer(void) && recordHasData && gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum) { - trainerIds[idsCount] = i + BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID; + trainerIds[idsCount] = i + TRAINER_RECORD_MIXING_FRIEND; idsCount++; } } @@ -322,7 +336,7 @@ static bool8 ChooseSpecialBattleTowerTrainer(void) && gUnknown_085DF9EC[gSaveBlock2Ptr->apprentices[i].field_1] == winStreak && gSaveBlock2Ptr->apprentices[i].lvlMode - 1 == lvlMode) { - trainerIds[idsCount] = i + BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID; + trainerIds[idsCount] = i + TRAINER_RECORD_MIXING_APPRENTICE; idsCount++; } } @@ -505,7 +519,7 @@ void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId) u8 trainerObjectGfxId; SetFacilityPtrsGetLevel(); - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; } @@ -514,17 +528,17 @@ void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId) SetFrontierBrainTrainerGfxId(); return; } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { facilityClass = gFacilityTrainers[trainerId].facilityClass; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { - facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass; } else { - facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass; } // Search male classes. @@ -592,7 +606,7 @@ void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId) void SetEReaderTrainerGfxId(void) { - SetBattleFacilityTrainerGfxId(BATTLE_TOWER_EREADER_TRAINER_ID, 0); + SetBattleFacilityTrainerGfxId(TRAINER_EREADER, 0); } u8 GetBattleFacilityTrainerGfxId(u16 trainerId) @@ -602,21 +616,21 @@ u8 GetBattleFacilityTrainerGfxId(u16 trainerId) u8 trainerObjectGfxId; SetFacilityPtrsGetLevel(); - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { facilityClass = gFacilityTrainers[trainerId].facilityClass; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { - facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass; } else { - facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass; } // Search male classes. @@ -740,7 +754,7 @@ u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) { SetFacilityPtrsGetLevel(); - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass]; } @@ -748,23 +762,23 @@ u8 GetFrontierTrainerFrontSpriteId(u16 trainerId) { return GetFrontierBrainTrainerPicIndex(); } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { return gFacilityClassToPicIndex[gFacilityTrainers[trainerId].facilityClass]; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) return gFacilityClassToPicIndex[sub_818649C()]; else - return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; + return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass]; } else { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) return gFacilityClassToPicIndex[gApprentices[sub_81864A8()].facilityClass]; else - return gFacilityClassToPicIndex[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass]; + return gFacilityClassToPicIndex[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass]; } } @@ -773,7 +787,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) u8 trainerClass = 0; SetFacilityPtrsGetLevel(); - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass]; } @@ -785,11 +799,11 @@ u8 GetFrontierOpponentClass(u16 trainerId) { trainerClass = gTrainers[TRAINER_STEVEN].trainerClass; } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { trainerClass = gFacilityClassToTrainerClass[gFacilityTrainers[trainerId].facilityClass]; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { @@ -797,7 +811,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) } else { - trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass]; + trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass]; asm(""); } } @@ -809,7 +823,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) } else { - trainerClass = gFacilityClassToTrainerClass[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass]; + trainerClass = gFacilityClassToTrainerClass[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass]; asm(""); } } @@ -822,27 +836,27 @@ static u8 GetFrontierTrainerFacilityClass(u16 trainerId) u8 facilityClass; SetFacilityPtrsGetLevel(); - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { facilityClass = gFacilityTrainers[trainerId].facilityClass; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) facilityClass = sub_818649C(); else - facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass; } else { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) facilityClass = gApprentices[sub_81864A8()].facilityClass; else - facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass; } return facilityClass; @@ -853,7 +867,7 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) s32 i = 0; SetFacilityPtrsGetLevel(); - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { for (i = 0; i < PLAYER_NAME_LENGTH; i++) dst[i] = gSaveBlock2Ptr->frontier.ereaderTrainer.name[i]; @@ -868,12 +882,12 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) for (i = 0; i < PLAYER_NAME_LENGTH; i++) dst[i] = gTrainers[TRAINER_STEVEN].trainerName[i]; } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { for (i = 0; i < PLAYER_NAME_LENGTH; i++) dst[i] = gFacilityTrainers[trainerId].trainerName[i]; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { @@ -882,7 +896,7 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) } else { - struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID]; + struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND]; TVShowConvertInternationalString(dst, record->name, record->language); return; } @@ -898,7 +912,7 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) } else { - struct Apprentice *apprentice = &gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID]; + struct Apprentice *apprentice = &gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE]; id = apprentice->id; language = apprentice->language; } @@ -915,7 +929,7 @@ static bool8 IsFrontierTrainerFemale(u16 trainerId) u8 facilityClass; SetFacilityPtrsGetLevel(); - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass; } @@ -923,17 +937,17 @@ static bool8 IsFrontierTrainerFemale(u16 trainerId) { return IsFrontierBrainFemale(); } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { facilityClass = gFacilityTrainers[trainerId].facilityClass; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { - facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].facilityClass; + facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass; } else { - facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id].facilityClass; + facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass; } // Search female classes. @@ -978,13 +992,13 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) const u16 *bfMonPool = NULL; u32 otID = 0; - if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { // Normal battle frontier trainer. fixedIV = GetFrontierTrainerFixedIvs(trainerId); bfMonPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool; } - else if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + else if (trainerId == TRAINER_EREADER) { for (i = firstMonId; i < firstMonId + 3; i++) sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]); @@ -995,15 +1009,15 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) CreateFrontierBrainPokemon(); return; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { // Record mixed player. for (j = 0, i = firstMonId; i < firstMonId + monCount; j++, i++) { - if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].species != 0 - && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j].level <= level) + if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[j].species != 0 + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[j].level <= level) { - sub_8068338(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[j], FALSE); + sub_8068338(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[j], FALSE); } } return; @@ -1012,7 +1026,7 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) { // Apprentice. for (i = firstMonId; i < firstMonId + 3; i++) - CreateApprenticeMon(&gEnemyParty[i], &gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID], i - firstMonId); + CreateApprenticeMon(&gEnemyParty[i], &gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE], i - firstMonId); return; } @@ -1144,16 +1158,16 @@ u16 RandomizeFacilityTrainerMonId(u16 trainerId) return monPoolId; } -static void sub_8163590(void) +static void FillFactoryTrainerParty(void) { ZeroEnemyPartyMons(); if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) - sub_81635D4(gTrainerBattleOpponent_A, 0); + FillFactoryFrontierTrainerParty(gTrainerBattleOpponent_A, 0); else - sub_816379C(gTrainerBattleOpponent_A, 0); + FillFactoryTentTrainerParty(gTrainerBattleOpponent_A, 0); } -static void sub_81635D4(u16 trainerId, u8 firstMonId) +static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId) { u8 i, j; u8 friendship; @@ -1161,7 +1175,7 @@ static void sub_81635D4(u16 trainerId, u8 firstMonId) u8 fixedIV; u32 otID; - if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; // Unused variable. u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); @@ -1171,7 +1185,7 @@ static void sub_81635D4(u16 trainerId, u8 firstMonId) else fixedIV = sub_81A6CA8(challengeNum, 1); } - else if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + else if (trainerId == TRAINER_EREADER) { for (i = firstMonId; i < firstMonId + 3; i++) sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]); @@ -1210,7 +1224,7 @@ static void sub_81635D4(u16 trainerId, u8 firstMonId) } } -static void sub_816379C(u16 trainerId, u8 firstMonId) +static void FillFactoryTentTrainerParty(u16 trainerId, u8 firstMonId) { u8 i, j; u8 friendship; @@ -1269,14 +1283,14 @@ static void sub_8163914(void) else trainerId = gTrainerBattleOpponent_A; - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.greeting); - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore); - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) - FrontierSpeechToString(gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].greeting); + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) + FrontierSpeechToString(gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].greeting); else - CopyFriendsApprenticeChallengeText(trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID); + CopyFriendsApprenticeChallengeText(trainerId - TRAINER_RECORD_MIXING_APPRENTICE); } static void HandleSpecialTrainerBattleEnd(void) @@ -1419,7 +1433,7 @@ void DoSpecialTrainerBattle(void) gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_FACTORY; if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES) gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; - sub_8163590(); + FillFactoryTrainerParty(); CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(sub_80B100C(6)); @@ -1552,7 +1566,7 @@ static void sub_81640E0(u16 trainerId) count = 0; for (i = 0; i < 3; i++) { - u16 apprenticeSpecies = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].party[i].species; + u16 apprenticeSpecies = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].party[i].species; if (apprenticeSpecies != species1 && apprenticeSpecies != species2) { validSpecies[count] = i; @@ -1578,10 +1592,10 @@ static void sub_8164188(u16 trainerId) count = 0; for (i = 0; i < 4; i++) { - if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].species != species1 - && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].species != species2 - && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].level <= GetFrontierEnemyMonLevel(lvlMode) - && gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[i].species != 0) + if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species1 + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species2 + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].level <= GetFrontierEnemyMonLevel(lvlMode) + && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != 0) { validSpecies[count] = i; count++; @@ -1684,7 +1698,7 @@ static void sub_81642A0(void) } if (k > 2) { - spArray[r10] = i + BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID; + spArray[r10] = i + TRAINER_RECORD_MIXING_APPRENTICE; r10++; } } @@ -1727,7 +1741,7 @@ static void sub_81642A0(void) } if (k > 1) { - spArray[r10] = i + BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID; + spArray[r10] = i + TRAINER_RECORD_MIXING_FRIEND; r10++; } } @@ -1747,28 +1761,28 @@ static void sub_81646BC(u16 trainerId, u16 monPoolId) u16 species = 0; SetFacilityPtrsGetLevel(); - if (trainerId != BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId != TRAINER_EREADER) { - if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { move = gFacilityTrainerMons[monPoolId].moves[0]; species = gFacilityTrainerMons[monPoolId].species; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { - move = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].moves[0]; - species = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].species; + move = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].moves[0]; + species = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].species; } else { s32 i; - move = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].moves[0]; - species = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].species; + move = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].moves[0]; + species = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].species; for (i = 0; i < PLAYER_NAME_LENGTH; i++) - gStringVar3[i] = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].playerName[i]; + gStringVar3[i] = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].playerName[i]; gStringVar3[i] = EOS; - ConvertInternationalString(gStringVar3, gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].language); + ConvertInternationalString(gStringVar3, gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].language); } } @@ -1794,13 +1808,13 @@ static void sub_8164828(void) switch (gSpecialVar_0x8005) { case 0: - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) return; - if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { GetFrontierTrainerName(gStringVar1, trainerId); } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { GetFrontierTrainerName(gStringVar1, trainerId); } @@ -1808,10 +1822,10 @@ static void sub_8164828(void) { s32 i; for (i = 0; i < PLAYER_NAME_LENGTH; i++) - gStringVar1[i] = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].playerName[i]; + gStringVar1[i] = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].playerName[i]; gStringVar1[i] = EOS; - ConvertInternationalString(gStringVar1, gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].language); - ConvertIntToDecimalStringN(gStringVar2, gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].number, STR_CONV_MODE_LEFT_ALIGN, 3); + ConvertInternationalString(gStringVar1, gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].language); + ConvertIntToDecimalStringN(gStringVar2, gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].number, STR_CONV_MODE_LEFT_ALIGN, 3); GetFrontierTrainerName(gStringVar3, trainerId); } break; @@ -1825,12 +1839,12 @@ static void sub_8164828(void) break; case 3: gPartnerTrainerId = trainerId; - if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { gSaveBlock2Ptr->frontier.field_CB4[18] = gSaveBlock2Ptr->frontier.field_CB4[8 + k * 2]; gSaveBlock2Ptr->frontier.field_CB4[19] = gSaveBlock2Ptr->frontier.field_CB4[9 + k * 2]; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { gSaveBlock2Ptr->frontier.field_CB4[18] = gUnknown_03006298[2]; gSaveBlock2Ptr->frontier.field_CB4[19] = gUnknown_03006298[3]; @@ -1864,20 +1878,20 @@ static void sub_8164828(void) break; } - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) return; - if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { ShowFieldMessage(gUnknown_085DD500[arrId].strings[gSpecialVar_0x8005]); } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { ShowFieldMessage(gUnknown_085DD500[arrId].strings[gSpecialVar_0x8005]); } else { - u8 id = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].id; + u8 id = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id; ShowFieldMessage(gUnknown_085DD690[id][gSpecialVar_0x8005]); } } @@ -2264,18 +2278,6 @@ void sub_81653CC(void) } } -struct StevenMon -{ - u16 species; - u8 fixedIV; - u8 level; - u8 nature; - u8 evs[6]; - u16 moves[4]; -}; - -extern const struct StevenMon sStevenMons[3]; - #define STEVEN_OTID 61226 static void FillPartnerParty(u16 trainerId) @@ -2312,12 +2314,12 @@ static void FillPartnerParty(u16 trainerId) CalculateMonStats(&gPlayerParty[3 + i]); } } - else if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + else if (trainerId == TRAINER_EREADER) { // Scrapped, lol. trainerName[0] = gGameLanguage; } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { level = SetFacilityPtrsGetLevel(); ivs = GetFrontierTrainerFixedIvs(trainerId); @@ -2348,9 +2350,9 @@ static void FillPartnerParty(u16 trainerId) SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j); } } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { - trainerId -= BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID; + trainerId -= TRAINER_RECORD_MIXING_FRIEND; for (i = 0; i < 2; i++) { struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.towerRecords[trainerId]; @@ -2371,17 +2373,17 @@ static void FillPartnerParty(u16 trainerId) } sub_8068338(&gPlayerParty[3 + i], &monData, TRUE); SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, trainerName); - j = IsFrontierTrainerFemale(trainerId + BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID); + j = IsFrontierTrainerFemale(trainerId + TRAINER_RECORD_MIXING_FRIEND); SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j); } } else { - trainerId -= BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID; + trainerId -= TRAINER_RECORD_MIXING_APPRENTICE; for (i = 0; i < 2; i++) { CreateApprenticeMon(&gPlayerParty[3 + i], &gSaveBlock2Ptr->apprentices[trainerId], gSaveBlock2Ptr->frontier.field_CB4[18 + i]); - j = IsFrontierTrainerFemale(trainerId + BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID); + j = IsFrontierTrainerFemale(trainerId + TRAINER_RECORD_MIXING_APPRENTICE); SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j); } } @@ -2513,27 +2515,27 @@ static void ValidateApprenticesChecksums(void) void GetBattleTowerTrainerLanguage(u8 *dst, u16 trainerId) { - if (trainerId == BATTLE_TOWER_EREADER_TRAINER_ID) + if (trainerId == TRAINER_EREADER) { *dst = gGameLanguage; } - else if (trainerId < BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_FRIEND) { *dst = gGameLanguage; } - else if (trainerId < BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID) + else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) *dst = sub_81864B4(); else - *dst = gSaveBlock2Ptr->frontier.towerRecords[trainerId - BATTLE_TOWER_RECORD_MIXING_TRAINER_BASE_ID].language; + *dst = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].language; } else { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) *dst = sub_81864C0(); else - *dst = gSaveBlock2Ptr->apprentices[trainerId - BATTLE_TOWER_RECORD_APPRENTICE_BASE_ID].language; + *dst = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].language; } } diff --git a/sym_ewram.txt b/sym_ewram.txt index 415d3882f..aeeb4148f 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -470,13 +470,7 @@ gUnknown_0203ABB5: @ 203ABB5 .include "src/learn_move.o" .include "src/decoration_inventory.o" .include "src/roamer.o" - -gFacilityTrainers: @ 203BC88 - .space 0x4 - -gFacilityTrainerMons: @ 203BC8C - .space 0x4 - + .include "src/battle_tower.o" .include "src/use_pokeblock.o" .include "src/player_pc.o" .include "src/intro.o" From 0e6fbbfe091a260f627427ce4f204c192c9dbcc3 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 27 Oct 2018 00:04:18 +0200 Subject: [PATCH 8/8] Make battle tower compile --- data/battle_scripts_1.s | 16 ++++++++-------- src/battle_dome.c | 10 ++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index d8f681686..edf49eda5 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -1601,12 +1601,12 @@ BattleScript_EffectPerishSong:: waitanimation printstring STRINGID_FAINTINTHREE waitmessage 0x40 - setbyte sBANK, 0x0 + setbyte sBATTLER, 0x0 BattleScript_PerishSongLoop:: jumpifability BS_SCRIPTING, ABILITY_SOUNDPROOF, BattleScript_PerishSongNotAffected BattleScript_PerishSongLoopIncrement:: - addbyte sBANK, 0x1 - jumpifbytenotequal sBANK, gBattlersCount, BattleScript_PerishSongLoop + addbyte sBATTLER, 0x1 + jumpifbytenotequal sBATTLER, gBattlersCount, BattleScript_PerishSongLoop goto BattleScript_MoveEnd BattleScript_PerishSongNotAffected:: @@ -2493,7 +2493,7 @@ BattleScript_EffectYawn:: waitmessage 0x40 goto BattleScript_MoveEnd BattleScript_PrintBankAbilityMadeIneffective:: - copybyte sBANK, sBANK_WITH_ABILITY + copybyte sBATTLER, sBATTLER_WITH_ABILITY BattleScript_PrintAbilityMadeIneffective:: pause 0x20 printstring STRINGID_PKMNSXMADEITINEFFECTIVE @@ -3523,7 +3523,7 @@ BattleScript_RapidSpinAway:: BattleScript_WrapFree:: printstring STRINGID_PKMNGOTFREE waitmessage 0x40 - copybyte gBattlerTarget, sBANK + copybyte gBattlerTarget, sBATTLER return BattleScript_LeechSeedFree:: @@ -4030,11 +4030,11 @@ BattleScript_ShedSkinActivates:: end3 BattleScript_WeatherFormChanges:: - setbyte sBANK, 0x0 + setbyte sBATTLER, 0x0 BattleScript_WeatherFormChangesLoop:: trycastformdatachange - addbyte sBANK, 0x1 - jumpifbytenotequal sBANK, gBattlersCount, BattleScript_WeatherFormChangesLoop + addbyte sBATTLER, 0x1 + jumpifbytenotequal sBATTLER, gBattlersCount, BattleScript_WeatherFormChangesLoop return BattleScript_CastformChange:: diff --git a/src/battle_dome.c b/src/battle_dome.c index 8c2fa12fd..00bf9646b 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -57,18 +57,12 @@ struct UnkStruct_860DD10 extern void sub_81B8558(void); extern u32 sub_81A39C4(void); -extern u16 sub_8162548(u8, u8); -extern u16 RandomizeFacilityTrainerMonId(u16); -extern u8 SetFacilityPtrsGetLevel(void); extern u16 sub_81A5060(u8 monId, u8 moveSlotId); extern u8 sub_81A50F0(u8, u8); extern u8 sub_81A50B0(u8); -extern void SetBattleFacilityTrainerGfxId(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 void ReducePlayerPartyToThree(void); extern u8 gUnknown_0203CEF8[]; @@ -5561,7 +5555,7 @@ static u16 GetWinningMove(s32 winnerTournamentId, s32 loserTournamentId, u8 roun u16 bestScore = 0; u16 bestId = 0; s32 movePower = 0; - SetFacilityPtrsGetLevel(); // Unused return variable. + SetFacilityPtrsGetLevel(); // Calc move points of all 4 moves for all 3 pokemon hitting all 3 target mons. for (i = 0; i < 3; i++) @@ -6425,7 +6419,7 @@ static void DecideRoundWinners(u8 roundId) static void CopyDomeTrainerName(u8 *dst, u16 trainerId) { s32 i = 0; - SetFacilityPtrsGetLevel(); // Unused return value. + SetFacilityPtrsGetLevel(); if (trainerId == TRAINER_FRONTIER_BRAIN) {