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; }