From 3b3cffac444a653e71c83e0621d7f0c52e8f4c3a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 12 Nov 2018 14:07:31 +0100 Subject: [PATCH] Decompile battle pike --- asm/battle_frontier_2.s | 1032 --------------------------------------- include/global.h | 8 +- src/battle_pike.c | 390 +++++++++++++-- 3 files changed, 365 insertions(+), 1065 deletions(-) diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 52017a182..f4dc876ed 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -6,1040 +6,8 @@ .text - thumb_func_start InBattlePike -InBattlePike: @ 81A80A8 - push {lr} - movs r2, 0 - ldr r0, =gMapHeader - ldrh r1, [r0, 0x12] - ldr r3, =0xfffffea1 - adds r0, r1, r3 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x1 - bls _081A80CA - movs r0, 0xB3 - lsls r0, 1 - cmp r1, r0 - beq _081A80CA - adds r0, 0x1 - cmp r1, r0 - bne _081A80CC -_081A80CA: - movs r2, 0x1 -_081A80CC: - adds r0, r2, 0 - pop {r1} - bx r1 - .pool - thumb_func_end InBattlePike - thumb_func_start sub_81A80DC -sub_81A80DC: @ 81A80DC - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r4, =gSpecialVar_Result - movs r0, 0 - strh r0, [r4] - movs r0, 0x1 - bl sub_81A8590 - lsls r0, 24 - cmp r0, 0 - beq _081A8138 - movs r0, 0x1 - strh r0, [r4] - bl Random - ldr r5, =gSaveBlock2Ptr - ldr r4, [r5] - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x6 - bl __umodsi3 - movs r3, 0xE1 - lsls r3, 4 - adds r4, r3 - movs r1, 0x7 - ands r1, r0 - ldrb r2, [r4] - movs r0, 0x8 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r4] - ldr r2, [r5] - adds r2, r3 - ldrb r1, [r2] - movs r0, 0x79 - negs r0, r0 - ands r0, r1 - movs r1, 0x40 - b _081A8248 - .pool -_081A8138: - bl Random - ldr r7, =gSaveBlock2Ptr - ldr r4, [r7] - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - bl __umodsi3 - movs r3, 0xE1 - lsls r3, 4 - adds r4, r3 - movs r1, 0x7 - ands r1, r0 - ldrb r2, [r4] - movs r0, 0x8 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r4] - ldr r0, [r7] - adds r0, r3 - ldrb r1, [r0] - movs r0, 0x80 - ands r0, r1 - movs r6, 0x8 - cmp r0, 0 - beq _081A8172 - movs r6, 0x6 -_081A8172: - adds r0, r6, 0 - bl AllocZeroed - adds r5, r0, 0 - movs r2, 0 - movs r3, 0 - cmp r2, r6 - bcs _081A81BE - adds r4, r7, 0 -_081A8184: - ldr r0, [r4] - movs r1, 0xE1 - lsls r1, 4 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _081A81B0 - cmp r2, 0x1 - beq _081A81B4 - cmp r2, 0x4 - beq _081A81B4 - adds r1, r3, 0 - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - adds r1, r5, r1 - strb r2, [r1] - b _081A81B4 - .pool -_081A81B0: - adds r0, r5, r2 - strb r2, [r0] -_081A81B4: - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, r6 - bcc _081A8184 -_081A81BE: - bl Random - ldr r7, =gSaveBlock2Ptr - ldr r4, [r7] - lsls r0, 16 - lsrs r0, 16 - adds r1, r6, 0 - bl __modsi3 - adds r0, r5, r0 - ldrb r0, [r0] - movs r6, 0xE1 - lsls r6, 4 - adds r4, r6 - movs r1, 0xF - ands r1, r0 - lsls r1, 3 - ldrb r2, [r4] - movs r0, 0x79 - negs r0, r0 - mov r8, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r4] - adds r0, r5, 0 - bl Free - ldr r0, [r7] - adds r0, r6 - ldrb r1, [r0] - movs r0, 0x78 - ands r0, r1 - cmp r0, 0x18 - bne _081A821C - bl AtLeastOneHealthyMon - lsls r0, 24 - cmp r0, 0 - bne _081A821C - ldr r2, [r7] - adds r2, r6 - ldrb r1, [r2] - mov r0, r8 - ands r0, r1 - movs r1, 0x10 - orrs r0, r1 - strb r0, [r2] -_081A821C: - ldr r5, =gSaveBlock2Ptr - ldr r0, [r5] - movs r4, 0xE1 - lsls r4, 4 - adds r0, r4 - ldrb r1, [r0] - movs r0, 0x78 - ands r0, r1 - cmp r0, 0x38 - bne _081A824C - bl sub_81A8554 - lsls r0, 24 - cmp r0, 0 - bne _081A824C - ldr r2, [r5] - adds r2, r4 - ldrb r1, [r2] - movs r0, 0x79 - negs r0, r0 - ands r0, r1 - movs r1, 0x10 -_081A8248: - orrs r0, r1 - strb r0, [r2] -_081A824C: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A80DC - thumb_func_start sub_81A825C -sub_81A825C: @ 81A825C - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r2, 0xE1 - lsls r2, 4 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 29 - lsrs r0, 29 - strh r0, [r1] - bx lr - .pool - thumb_func_end sub_81A825C - - thumb_func_start sub_81A827C -sub_81A827C: @ 81A827C - ldr r2, =gSpecialVar_Result - ldr r1, =gUnknown_0861266C - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r3, 0xE1 - lsls r3, 4 - adds r0, r3 - ldrb r0, [r0] - lsls r0, 25 - lsrs r0, 28 - adds r0, r1 - ldrb r0, [r0] - strh r0, [r2] - bx lr - .pool - thumb_func_end sub_81A827C - - thumb_func_start sub_81A82A4 -sub_81A82A4: @ 81A82A4 - push {r4-r7,lr} - lsls r0, 24 - movs r7, 0x6 - cmp r0, 0 - bne _081A82B0 - movs r7, 0x1 -_081A82B0: - ldr r4, =gSaveBlock2Ptr - ldr r1, [r4] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 29 - ldr r2, =0x00000e04 - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0xE - bl __udivsi3 - lsls r0, 16 - lsrs r6, r0, 16 - adds r5, r4, 0 -_081A82D2: - lsls r0, r6, 24 - lsrs r0, 24 - adds r1, r7, 0 - bl sub_8162548 - lsls r0, 16 - lsrs r4, r0, 16 - movs r3, 0 - ldr r1, [r5] - ldr r2, =0x00000cb2 - adds r0, r1, r2 - ldrh r0, [r0] - subs r2, r0, 0x1 - cmp r3, r2 - bge _081A831A - ldr r0, =0x00000cb4 - adds r1, r0 - b _081A8314 - .pool -_081A830C: - adds r1, 0x2 - adds r3, 0x1 - cmp r3, r2 - bge _081A831A -_081A8314: - ldrh r0, [r1] - cmp r0, r4 - bne _081A830C -_081A831A: - ldr r0, [r5] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - subs r0, 0x1 - cmp r3, r0 - bne _081A82D2 - ldr r5, =gTrainerBattleOpponent_A - strh r4, [r5] - ldr r1, =gFacilityTrainers - ldr r0, =gBattleFrontierTrainers - str r0, [r1] - ldrh r0, [r5] - movs r1, 0 - bl SetBattleFacilityTrainerGfxId - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0x00000cb2 - adds r2, r1, r0 - ldrh r0, [r2] - cmp r0, 0xD - bhi _081A8356 - subs r0, 0x1 - lsls r0, 1 - ldr r2, =0x00000cb4 - adds r1, r2 - adds r1, r0 - ldrh r0, [r5] - strh r0, [r1] -_081A8356: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A82A4 - - thumb_func_start sub_81A8374 -sub_81A8374: @ 81A8374 - push {r4-r7,lr} - ldr r4, =gSaveBlock2Ptr - ldr r1, [r4] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 29 - ldr r2, =0x00000e04 - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0xE - bl __udivsi3 - lsls r0, 16 - lsrs r5, r0, 16 - ldr r1, =gFacilityTrainers - ldr r0, =gBattleFrontierTrainers - str r0, [r1] - lsls r7, r5, 24 - adds r6, r4, 0 -_081A83A0: - lsls r0, r5, 24 - lsrs r0, 24 - movs r1, 0x1 - bl sub_8162548 - lsls r0, 16 - lsrs r4, r0, 16 - movs r3, 0 - ldr r1, [r6] - ldr r2, =0x00000cb2 - adds r0, r1, r2 - ldrh r0, [r0] - subs r2, r0, 0x1 - cmp r3, r2 - bge _081A83EE - ldr r0, =0x00000cb4 - adds r1, r0 - b _081A83E8 - .pool -_081A83E0: - adds r1, 0x2 - adds r3, 0x1 - cmp r3, r2 - bge _081A83EE -_081A83E8: - ldrh r0, [r1] - cmp r0, r4 - bne _081A83E0 -_081A83EE: - ldr r0, [r6] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - subs r0, 0x1 - cmp r3, r0 - bne _081A83A0 - ldr r5, =gTrainerBattleOpponent_A - strh r4, [r5] - ldrh r0, [r5] - movs r1, 0 - bl SetBattleFacilityTrainerGfxId - ldr r3, =gSaveBlock2Ptr - ldr r1, [r3] - ldr r0, =0x00000cb2 - adds r2, r1, r0 - ldrh r0, [r2] - cmp r0, 0xE - bhi _081A8424 - subs r0, 0x1 - lsls r0, 1 - ldr r2, =0x00000cb4 - adds r1, r2 - adds r1, r0 - ldrh r0, [r5] - strh r0, [r1] -_081A8424: - adds r5, r3, 0 -_081A8426: - lsrs r0, r7, 24 - movs r1, 0x1 - bl sub_8162548 - 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 _081A8466 - adds r2, 0x2 - adds r0, r1, r2 - ldrh r0, [r0] - cmp r0, r4 - beq _081A8466 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - subs r2, 0x2 - adds r0, r1, r2 - ldrh r2, [r0] - ldr r0, =0x00000cb4 - adds r1, r0 -_081A8458: - adds r1, 0x2 - adds r3, 0x1 - cmp r3, r2 - bge _081A8466 - ldrh r0, [r1] - cmp r0, r4 - bne _081A8458 -_081A8466: - ldr r0, [r5] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - cmp r3, r0 - bne _081A8426 - ldr r5, =gTrainerBattleOpponent_B - strh r4, [r5] - ldrh r0, [r5] - movs r1, 0x1 - bl SetBattleFacilityTrainerGfxId - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0x00000cb2 - adds r2, r1, r0 - ldrh r0, [r2] - cmp r0, 0xD - bhi _081A849A - subs r0, 0x2 - lsls r0, 1 - ldr r2, =0x00000cb4 - adds r1, r2 - adds r1, r0 - ldrh r0, [r5] - strh r0, [r1] -_081A849A: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8374 - - thumb_func_start sub_81A84B4 -sub_81A84B4: @ 81A84B4 - push {r4,r5,lr} - movs r2, 0 - ldr r5, =gSaveBlock2Ptr - ldr r4, =0x00000cb4 - ldr r0, =0x0000ffff - adds r3, r0, 0 -_081A84C0: - ldr r1, [r5] - lsls r0, r2, 1 - adds r1, r4 - adds r1, r0 - ldrh r0, [r1] - orrs r0, r3 - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0xD - bls _081A84C0 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A84B4 - - thumb_func_start sub_81A84EC -sub_81A84EC: @ 81A84EC - push {lr} - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0 - bne _081A8524 - ldr r3, =gTrainerBattleOpponent_A - ldrh r1, [r3] - ldr r0, =0x0000012b - cmp r1, r0 - bhi _081A8542 - ldr r2, =gFacilityTrainers - movs r0, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0xC - bl FrontierSpeechToString - b _081A8542 - .pool -_081A8524: - cmp r0, 0x1 - bne _081A8542 - ldr r3, =gTrainerBattleOpponent_B - ldrh r1, [r3] - ldr r0, =0x0000012b - cmp r1, r0 - bhi _081A8542 - ldr r2, =gFacilityTrainers - movs r0, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0xC - bl FrontierSpeechToString -_081A8542: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A84EC - - thumb_func_start sub_81A8554 -sub_81A8554: @ 81A8554 - push {r4-r6,lr} - ldr r5, =gPlayerParty - movs r6, 0 - movs r4, 0 -_081A855C: - adds r0, r5, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - bne _081A856E - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 -_081A856E: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - adds r5, 0x64 - cmp r4, 0x2 - bls _081A855C - cmp r6, 0x1 - bhi _081A8588 - movs r0, 0x1 - b _081A858A - .pool -_081A8588: - movs r0, 0 -_081A858A: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_81A8554 - - thumb_func_start sub_81A8590 -sub_81A8590: @ 81A8590 - push {r4-r6,lr} - lsls r0, 24 - movs r6, 0 - ldr r1, =gSaveBlock2Ptr - ldr r2, [r1] - ldr r3, =0x00000ca9 - adds r1, r2, r3 - ldrb r1, [r1] - lsls r1, 30 - lsrs r1, 29 - ldr r3, =0x00000e04 - adds r2, r3 - adds r2, r1 - lsrs r4, r0, 24 - ldrh r2, [r2] - adds r0, r4, r2 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x5 - bl GetPlayerSymbolCountForFacility - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0 - blt _081A85F0 - cmp r2, 0x1 - bgt _081A85F0 - ldr r1, =gUnknown_086125DC - adds r0, r2, 0 - adds r0, 0x14 - adds r0, r1 - ldrb r0, [r0] - ldrb r1, [r1, 0x17] - subs r0, r1 - cmp r4, r0 - bne _081A8634 - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - b _081A8634 - .pool -_081A85F0: - ldr r5, =gUnknown_086125DC - movs r0, 0x5 - lsls r3, r0, 2 - adds r0, r3, r5 - ldrb r1, [r0] - adds r0, r5, 0x3 - adds r0, r3, r0 - ldrb r2, [r0] - subs r1, r2 - cmp r4, r1 - bne _081A8610 - movs r6, 0x3 - b _081A8634 - .pool -_081A8610: - adds r0, r5, 0x1 - adds r0, r3, r0 - ldrb r1, [r0] - subs r0, r1, r2 - cmp r4, r0 - beq _081A8632 - cmp r4, r1 - bls _081A8634 - subs r0, r4, r1 - adds r0, r2 - adds r1, r5, 0x2 - adds r1, r3, r1 - ldrb r1, [r1] - bl __modsi3 - cmp r0, 0 - bne _081A8634 -_081A8632: - movs r6, 0x4 -_081A8634: - adds r0, r6, 0 - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_81A8590 - - thumb_func_start sub_81A863C -sub_81A863C: @ 81A863C - push {r4,lr} - ldr r4, =gSpecialVar_Result - movs r0, 0 - bl sub_81A8590 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A863C - - thumb_func_start sub_81A8658 -sub_81A8658: @ 81A8658 - push {r4,lr} - ldr r3, =gUnknown_08612675 - ldr r2, =gSpecialVar_0x8007 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r1, 0xE1 - lsls r1, 4 - adds r0, r1 - ldrb r1, [r0] - lsls r1, 29 - lsrs r1, 29 - lsls r0, r1, 1 - adds r0, r1 - ldrh r2, [r2] - adds r0, r2 - adds r0, r3 - ldrb r4, [r0] - adds r0, r4, 0 - bl TryHealMons - ldr r0, =gSpecialVar_Result - strh r4, [r0] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8658 - - thumb_func_start sub_81A869C -sub_81A869C: @ 81A869C - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldr r0, =gSpecialVar_0x8005 - ldrb r1, [r0] - movs r0, 0xE1 - lsls r0, 4 - adds r2, r0 - lsls r1, 7 - ldrb r3, [r2] - movs r0, 0x7F - ands r0, r3 - orrs r0, r1 - strb r0, [r2] - bx lr - .pool - thumb_func_end sub_81A869C - - thumb_func_start sub_81A86C0 -sub_81A86C0: @ 81A86C0 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - strh r0, [r1] - movs r0, 0 - mov r10, r0 -_081A86D4: - movs r0, 0 - mov r9, r0 - movs r0, 0x64 - mov r1, r10 - muls r1, r0 - ldr r0, =gPlayerParty - adds r7, r1, r0 - adds r0, r7, 0 - movs r1, 0x39 - bl GetMonData - lsls r0, 16 - lsrs r4, r0, 16 - adds r0, r7, 0 - movs r1, 0x3A - bl GetMonData - lsls r0, 16 - lsrs r5, r0, 16 - cmp r4, r5 - bcc _081A8762 - adds r0, r7, 0 - movs r1, 0x37 - bl GetMonData - bl pokemon_ailments_get_primary - lsls r0, 24 - cmp r0, 0 - bne _081A8762 - adds r0, r7, 0 - movs r1, 0x15 - bl GetMonData - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - movs r6, 0 - b _081A8732 - .pool -_081A872C: - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 -_081A8732: - cmp r6, 0x3 - bhi _081A8766 - adds r1, r6, 0 - adds r1, 0xD - adds r0, r7, 0 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - mov r1, r8 - adds r2, r6, 0 - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r5, r0, 24 - adds r1, r6, 0 - adds r1, 0x11 - adds r0, r7, 0 - bl GetMonData - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, r5 - bcs _081A872C -_081A8762: - movs r0, 0x1 - mov r9, r0 -_081A8766: - mov r0, r9 - cmp r0, 0x1 - bne _081A8778 - ldr r1, =gSpecialVar_Result - movs r0, 0 - strh r0, [r1] - b _081A8786 - .pool -_081A8778: - mov r0, r10 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 - cmp r0, 0x2 - bls _081A86D4 -_081A8786: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81A86C0 - - thumb_func_start sub_81A8794 -sub_81A8794: @ 81A8794 - push {r4-r7,lr} - movs r5, 0 - ldr r7, =gSaveBlock1Ptr - ldr r6, =gSaveBlock2Ptr -_081A879C: - ldr r0, [r6] - lsls r4, r5, 1 - ldr r1, =0x00000caa - adds r0, r1 - adds r0, r4 - ldrh r1, [r0] - movs r0, 0x64 - muls r1, r0 - movs r2, 0xEA - lsls r2, 1 - adds r1, r2 - ldr r0, [r7] - adds r0, r1 - movs r1, 0xC - bl GetMonData - ldr r1, [r6] - ldr r2, =0x00000e12 - adds r1, r2 - adds r1, r4 - strh r0, [r1] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x2 - bls _081A879C - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8794 - - thumb_func_start sub_81A87E8 -sub_81A87E8: @ 81A87E8 - push {r4,lr} - movs r4, 0 -_081A87EC: - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - lsls r3, r4, 1 - ldr r1, =0x00000caa - adds r0, r2, r1 - adds r0, r3 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - 100 - adds r0, r1 - ldr r1, =0x00000e12 - adds r3, r1 - adds r2, r3 - movs r1, 0xC - bl SetMonData - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x2 - bls _081A87EC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A87E8 - - thumb_func_start sub_81A8830 -sub_81A8830: @ 81A8830 - push {r4-r6,lr} - ldr r3, =gSaveBlock2Ptr - ldr r1, [r3] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r5, r0, 30 - ldr r0, =0x00000ca8 - adds r1, r0 - movs r4, 0 - strb r4, [r1] - ldr r1, [r3] - ldr r6, =0x00000cb2 - adds r0, r1, r6 - strh r4, [r0] - adds r1, r2 - ldrb r2, [r1] - movs r0, 0x5 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - ldr r3, [r3] - ldr r0, =0x00000cdc - adds r2, r3, r0 - ldr r1, =gUnknown_08612690 - lsls r0, r5, 2 - adds r0, r1 - ldr r1, [r2] - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - bne _081A887C - lsls r1, r5, 1 - ldr r2, =0x00000e04 - adds r0, r3, r2 - adds r0, r1 - strh r4, [r0] -_081A887C: - ldr r0, =gTrainerBattleOpponent_A - strh r4, [r0] - ldr r1, =gBattleOutcome - movs r0, 0 - strb r0, [r1] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8830 - - thumb_func_start sub_81A88B0 -sub_81A88B0: @ 81A88B0 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r4, =gPlayerParty - adds r0, r4, 0 - movs r1, 0x6 - bl GetMonData - cmp r0, 0 - bne _081A8904 - adds r0, r4, 0 - bl GetMonAbility - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x33 - beq _081A88D6 - cmp r0, 0x16 - bne _081A8904 -_081A88D6: - adds r0, r4, 0 - movs r1, 0x38 - bl GetMonData - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x5 - bls _081A8904 - subs r0, 0x5 - cmp r5, r0 - bgt _081A8904 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - bne _081A8904 - movs r0, 0 - b _081A8906 - .pool -_081A8904: - movs r0, 0x1 -_081A8906: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_81A88B0 - - thumb_func_start sub_81A890C -sub_81A890C: @ 81A890C - push {lr} - lsls r0, 16 - lsrs r2, r0, 16 - ldr r0, =0x0000017b - cmp r2, r0 - bne _081A8920 - movs r1, 0 - b _081A892A - .pool -_081A8920: - ldr r0, =0x00000149 - movs r1, 0x2 - cmp r2, r0 - bne _081A892A - movs r1, 0x1 -_081A892A: - adds r0, r1, 0 - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A890C thumb_func_start sub_81A8934 @ void sub_81A8934(u8) diff --git a/include/global.h b/include/global.h index fd8284094..748021556 100644 --- a/include/global.h +++ b/include/global.h @@ -438,10 +438,10 @@ struct BattleFrontier /*0xE04*/ u16 pikeWinStreaks[2]; /*0xE08*/ u16 pikeRecordStreaks[2]; /*0xE0C*/ u16 pikeTotalStreaks[2]; - /*0xE10*/ u16 field_E10_1:3; - /*0xE10*/ u16 field_E10_2:4; - /*0xE10*/ u16 field_E10_3:1; - /*0xE10*/ u8 field_E10[9]; + /*0xE10*/ u8 field_E10_1:3; + /*0xE10*/ u8 field_E10_2:4; + /*0xE10*/ u8 field_E10_3:1; + /*0xE12*/ u16 field_E12[4]; /*0xE1A*/ u16 pyramidWinStreaks[2]; /*0xE1E*/ u16 pyramidRecordStreaks[2]; /*0xE1E*/ u16 field_E1F[5]; diff --git a/src/battle_pike.c b/src/battle_pike.c index 91e02a1bf..566fd4bf7 100644 --- a/src/battle_pike.c +++ b/src/battle_pike.c @@ -11,10 +11,13 @@ #include "malloc.h" #include "palette.h" #include "script.h" +#include "battle_setup.h" #include "constants/event_objects.h" #include "constants/battle_frontier.h" #include "constants/abilities.h" #include "constants/rgb.h" +#include "constants/trainers.h" +#include "constants/species.h" #define PIKE_ROOM_SINGLE_BATTLE 0 #define PIKE_ROOM_HEAL_FULL 1 @@ -53,6 +56,10 @@ extern const struct PikeWildMon *const *const gUnknown_08612314[2]; extern const u16 gUnknown_086123E4[][6]; extern const u8 gUnknown_0861266C[]; extern bool8 (* const gUnknown_08612688[])(struct Task *); +extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; +extern const u8 gUnknown_086125DC[][4]; +extern const u8 gUnknown_08612675[][3]; +extern const u32 gUnknown_08612690[]; // IWRAM bss IWRAM_DATA u8 sRoomType; @@ -63,16 +70,17 @@ IWRAM_DATA u8 gUnknown_03001294; // This file's functions. u8 GetNextRoomType(void); -void sub_81A82A4(u8); +void PrepareOneTrainer(bool8 difficult); u16 sub_81A7B58(void); -void sub_81A8374(void); +void PrepareTwoTrainers(void); void sub_81A5030(u8); void TryHealMons(u8 healCount); void sub_81A7EE4(u8 taskId); -bool8 sub_81A8554(void); +bool8 AtLeastTwoAliveMons(void); bool8 sub_81A7974(void); u8 sub_81A890C(u16 species); -bool8 sub_81A88B0(u8 monLevel); +bool8 CanEncounterWildMon(u8 monLevel); +u8 sub_81A8590(u8); u8 GetBattlePikeWildMonHeaderId(void); bool32 TryGenerateBattlePikeWildMon(bool8 checkKeenEyeIntimidate); @@ -106,7 +114,7 @@ void sub_81A7070(void) switch (sRoomType) { case PIKE_ROOM_SINGLE_BATTLE: - sub_81A82A4(0); + PrepareOneTrainer(FALSE); setPerson1 = FALSE; break; case PIKE_ROOM_HEAL_FULL: @@ -130,13 +138,13 @@ void sub_81A7070(void) setPerson1 = FALSE; break; case PIKE_ROOM_HARD_BATTLE: - sub_81A82A4(1); + PrepareOneTrainer(TRUE); person2 = EVENT_OBJ_GFX_LINK_RECEPTIONIST; setPerson1 = FALSE; setPerson2 = TRUE; break; case PIKE_ROOM_DOUBLE_BATTLE: - sub_81A8374(); + PrepareTwoTrainers(); setPerson1 = FALSE; break; case PIKE_ROOM_BRAIN: @@ -559,13 +567,13 @@ u8 GetNextRoomType(void) u8 var; u8 count; u8 *allocated; - u8 r3; + u8 id; - if (gSaveBlock2Ptr->frontier.field_E10_2 == 8) + if (gSaveBlock2Ptr->frontier.field_E10_2 == PIKE_ROOM_BRAIN) return gSaveBlock2Ptr->frontier.field_E10_2; if (gSpecialVar_0x8007 == gSaveBlock2Ptr->frontier.field_E10_1) { - if (gSaveBlock2Ptr->frontier.field_E10_2 == 3) + if (gSaveBlock2Ptr->frontier.field_E10_2 == PIKE_ROOM_STATUS) TryInflictRandomStatus(); return gSaveBlock2Ptr->frontier.field_E10_2; } @@ -584,7 +592,7 @@ u8 GetNextRoomType(void) } } - if (sp[7] != 1 && !sub_81A8554()) + if (sp[7] != 1 && !AtLeastTwoAliveMons()) { sp[7] = 1; count--; @@ -609,11 +617,11 @@ u8 GetNextRoomType(void) } allocated = AllocZeroed(count); - r3 = 0; + id = 0; for (i = 0; i < 8; i++) { if (sp[i] == 0) - allocated[r3++] = i; + allocated[id++] = i; } ret = allocated[Random() % count]; @@ -665,7 +673,7 @@ bool32 TryGenerateBattlePikeWildMon(bool8 checkKeenEyeIntimidate) monLevel = 50 - wildMons[headerId][pikeMonId].unk2; } - if (checkKeenEyeIntimidate == TRUE && !sub_81A88B0(monLevel)) + if (checkKeenEyeIntimidate == TRUE && !CanEncounterWildMon(monLevel)) return FALSE; SetMonData(&gEnemyParty[0], @@ -818,25 +826,22 @@ void TryHealMons(u8 healCount) { canBeHealed = TRUE; } + else if (pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) != 0) + { + canBeHealed = TRUE; + } else { - if (pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) != 0) + u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES); + for (j = 0; j < 4; j++) { - canBeHealed = TRUE; - } - else - { - u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES); - for (j = 0; j < 4; j++) + u16 move = GetMonData(mon, MON_DATA_MOVE1 + j); + max = CalculatePPWithBonus(move, ppBonuses, j); + curr = GetMonData(mon, MON_DATA_PP1 + j); + if (curr < max) { - u16 move = GetMonData(mon, MON_DATA_MOVE1 + j); - max = CalculatePPWithBonus(move, ppBonuses, j); - curr = GetMonData(mon, MON_DATA_PP1 + j); - if (curr < max) - { - canBeHealed = TRUE; - break; - } + canBeHealed = TRUE; + break; } } } @@ -854,3 +859,330 @@ void sub_81A8090(void) { gSpecialVar_Result = InBattlePike(); } + +bool8 InBattlePike(void) +{ + return (gMapHeader.mapLayoutId == 351 || gMapHeader.mapLayoutId == 352 + || gMapHeader.mapLayoutId == 358 || gMapHeader.mapLayoutId == 359); +} + +void sub_81A80DC(void) +{ + u8 i, count, id; + u8 *allocated; + + gSpecialVar_Result = 0; + if (sub_81A8590(1)) + { + gSpecialVar_Result = 1; + gSaveBlock2Ptr->frontier.field_E10_1 = Random() % 6; + gSaveBlock2Ptr->frontier.field_E10_2 = PIKE_ROOM_BRAIN; + } + else + { + gSaveBlock2Ptr->frontier.field_E10_1 = Random() % 3; + if (gSaveBlock2Ptr->frontier.field_E10_3) + count = 6; + else + count = 8; + + allocated = AllocZeroed(count); + for (i = 0, id = 0; i < count; i++) + { + if (gSaveBlock2Ptr->frontier.field_E10_3) + { + if (i != PIKE_ROOM_HEAL_FULL && i != PIKE_ROOM_HEAL_PART) + allocated[id++] = i; + } + else + { + allocated[i] = i; + } + } + gSaveBlock2Ptr->frontier.field_E10_2 = allocated[Random() % count]; + free(allocated); + if (gSaveBlock2Ptr->frontier.field_E10_2 == PIKE_ROOM_STATUS && !AtLeastOneHealthyMon()) + gSaveBlock2Ptr->frontier.field_E10_2 = PIKE_ROOM_NPC; + if (gSaveBlock2Ptr->frontier.field_E10_2 == PIKE_ROOM_DOUBLE_BATTLE && !AtLeastTwoAliveMons()) + gSaveBlock2Ptr->frontier.field_E10_2 = PIKE_ROOM_NPC; + } +} + +void sub_81A825C(void) +{ + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_E10_1; +} + +void sub_81A827C(void) +{ + gSpecialVar_Result = gUnknown_0861266C[gSaveBlock2Ptr->frontier.field_E10_2]; +} + +void PrepareOneTrainer(bool8 difficult) +{ + s32 i; + u8 lvlMode; + u8 battleNum; + u16 challengeNum; + u16 trainerId; + + if (!difficult) + battleNum = 1; + else + battleNum = 6; + + lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / 14; + do + { + trainerId = sub_8162548(challengeNum, battleNum); + for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1); + + gTrainerBattleOpponent_A = trainerId; + gFacilityTrainers = gBattleFrontierTrainers; + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 14) + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = gTrainerBattleOpponent_A; +} + +void PrepareTwoTrainers(void) +{ + s32 i; + u16 trainerId; + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u16 challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / 14; + + gFacilityTrainers = gBattleFrontierTrainers; + do + { + trainerId = sub_8162548(challengeNum, 1); + for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1); + + gTrainerBattleOpponent_A = trainerId; + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 14) + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = gTrainerBattleOpponent_A; + + do + { + trainerId = sub_8162548(challengeNum, 1); + for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); + + gTrainerBattleOpponent_B = trainerId; + SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 14) + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 2] = gTrainerBattleOpponent_B; +} + +void sub_81A84B4(void) +{ + u8 i; + + for (i = 0; i < 14; i++) + gSaveBlock2Ptr->frontier.field_CB4[i] |= 0xFFFF; +} + +void sub_81A84EC(void) +{ + if (gSpecialVar_0x8005 == 0) + { + if (gTrainerBattleOpponent_A < TRAINER_RECORD_MIXING_FRIEND) + FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); + } + else if (gSpecialVar_0x8005 == 1) + { + if (gTrainerBattleOpponent_B < TRAINER_RECORD_MIXING_FRIEND) + FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_B].speechBefore); + } +} + +bool8 AtLeastTwoAliveMons(void) +{ + struct Pokemon *mon; + u8 i, countDead; + + mon = &gPlayerParty[0]; + countDead = 0; + for (i = 0; i < 3; i++, mon++) + { + if (GetMonData(mon, MON_DATA_HP) == 0) + countDead++; + } + + if (countDead >= 2) + return FALSE; + else + return TRUE; +} + +u8 sub_81A8590(u8 arg0) +{ + u8 symbolsCount; + + u8 var = 5; + u8 ret = 0; + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u16 wins = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode]; + wins += arg0; + symbolsCount = GetPlayerSymbolCountForFacility(FRONTIER_FACILITY_PIKE); + + switch (symbolsCount) + { + case 0: + case 1: + if (wins == gUnknown_086125DC[var][symbolsCount] - gUnknown_086125DC[var][3]) + ret = symbolsCount + 1; + break; + case 2: + default: + if (wins == gUnknown_086125DC[var][0] - gUnknown_086125DC[var][3]) + ret = 3; + else if (wins == gUnknown_086125DC[var][1] - gUnknown_086125DC[var][3] + || (wins > gUnknown_086125DC[var][1] + && (wins - gUnknown_086125DC[var][1] + gUnknown_086125DC[var][3]) % gUnknown_086125DC[var][2] == 0)) + ret = 4; + break; + } + + return ret; +} + +void sub_81A863C(void) +{ + gSpecialVar_Result = sub_81A8590(0); +} + +void sub_81A8658(void) +{ + u8 toHealCount = gUnknown_08612675[gSaveBlock2Ptr->frontier.field_E10_1][gSpecialVar_0x8007]; + + TryHealMons(toHealCount); + gSpecialVar_Result = toHealCount; +} + +void sub_81A869C(void) +{ + gSaveBlock2Ptr->frontier.field_E10_3 = gSpecialVar_0x8005; +} + +void sub_81A86C0(void) +{ + u8 i, j; + + gSpecialVar_Result = TRUE; + for (i = 0; i < 3; i++) + { + bool32 canBeHealed = FALSE; + struct Pokemon *mon = &gPlayerParty[i]; + u16 curr = GetMonData(mon, MON_DATA_HP); + u16 max = GetMonData(mon, MON_DATA_MAX_HP); + if (curr >= max && pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) == 0) + { + u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES); + for (j = 0; j < 4; j++) + { + u16 move = GetMonData(mon, MON_DATA_MOVE1 + j); + max = CalculatePPWithBonus(move, ppBonuses, j); + curr = GetMonData(mon, MON_DATA_PP1 + j); + if (curr < max) + { + canBeHealed = TRUE; + break; + } + } + } + else + { + canBeHealed = TRUE; + } + + if (canBeHealed == TRUE) + { + gSpecialVar_Result = FALSE; + break; + } + } +} + +void sub_81A8794(void) +{ + u8 i; + + for (i = 0; i < 3; i++) + { + s32 heldItem = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], + MON_DATA_HELD_ITEM); + gSaveBlock2Ptr->frontier.field_E12[i] = heldItem; + } +} + +void sub_81A87E8(void) +{ + u8 i; + + for (i = 0; i < 3; i++) + { + SetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], + MON_DATA_HELD_ITEM, + &gSaveBlock2Ptr->frontier.field_E12[i]); + } +} + +void sub_81A8830(void) +{ + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + gSaveBlock2Ptr->frontier.field_CA8 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; + gSaveBlock2Ptr->frontier.field_CA9_a = 0; + if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_08612690[lvlMode])) + gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] = 0; + + gTrainerBattleOpponent_A = 0; + gBattleOutcome = 0; +} + +bool8 CanEncounterWildMon(u8 enemyMonLevel) +{ + if (!GetMonData(&gPlayerParty[0], MON_DATA_SANITY_BIT3)) + { + u8 monAbility = GetMonAbility(&gPlayerParty[0]); + if (monAbility == ABILITY_KEEN_EYE || monAbility == ABILITY_INTIMIDATE) + { + u8 playerMonLevel = GetMonData(&gPlayerParty[0], MON_DATA_LEVEL); + if (playerMonLevel > 5 && enemyMonLevel <= playerMonLevel - 5 && Random() % 2 == 0) + return FALSE; + } + } + + return TRUE; +} + +u8 sub_81A890C(u16 species) +{ + u8 ret; + + if (species == SPECIES_SEVIPER) + ret = 0; + else if (species == SPECIES_MILOTIC) + ret = 1; + else + ret = 2; + + return ret; +}