From 4fb463377c0d4e46deda797af2eb0f661d26465b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 12 Nov 2018 00:46:02 +0100 Subject: [PATCH] Start battle pike --- asm/battle_frontier_2.s | 2053 +------------------------------------- include/battle_factory.h | 2 +- include/fieldmap.h | 1 + include/global.h | 5 +- ld_script.txt | 1 + src/battle_factory.c | 12 +- src/battle_pike.c | 856 ++++++++++++++++ sym_bss.txt | 21 +- 8 files changed, 874 insertions(+), 2077 deletions(-) create mode 100644 src/battle_pike.c diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 15d319d99..52017a182 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -6,2055 +6,6 @@ .text - - - thumb_func_start sub_81A703C -sub_81A703C: @ 81A703C - push {lr} - ldr r1, =gUnknown_086125F8 - ldr r0, =gSpecialVar_0x8004 - ldrh r0, [r0] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl _call_via_r0 - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A703C - - thumb_func_start sub_81A705C -sub_81A705C: @ 81A705C - push {lr} - bl sub_81A79EC - ldr r1, =gUnknown_0300128C - strb r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A705C - - thumb_func_start sub_81A7070 -sub_81A7070: @ 81A7070 - push {r4-r7,lr} - ldr r0, =0x00004010 - movs r1, 0x1C - bl VarSet - ldr r0, =0x00004011 - movs r1, 0xE2 - bl VarSet - movs r4, 0x1 - movs r6, 0 - movs r5, 0 - movs r7, 0 - ldr r0, =gUnknown_0300128C - ldrb r0, [r0] - cmp r0, 0x8 - bhi _081A7132 - lsls r0, 2 - ldr r1, =_081A70AC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A70AC: - .4byte _081A70D0 - .4byte _081A70DA - .4byte _081A70DE - .4byte _081A70E8 - .4byte _081A70FC - .4byte _081A70D6 - .4byte _081A7100 - .4byte _081A7108 - .4byte _081A710E -_081A70D0: - movs r0, 0 - bl sub_81A82A4 -_081A70D6: - movs r4, 0 - b _081A711A -_081A70DA: - movs r5, 0x1C - b _081A711A -_081A70DE: - bl sub_81A7B58 - lsls r0, 24 - lsrs r5, r0, 24 - b _081A711A -_081A70E8: - movs r5, 0x30 - ldr r0, =gUnknown_0300128D - ldrb r0, [r0] - movs r7, 0xE1 - cmp r0, 0x1 - bne _081A7118 - movs r7, 0xE2 - b _081A7118 - .pool -_081A70FC: - movs r5, 0x30 - b _081A711A -_081A7100: - movs r0, 0x1 - bl sub_81A82A4 - b _081A7114 -_081A7108: - bl sub_81A8374 - b _081A70D6 -_081A710E: - movs r0, 0x5 - bl SetFrontierBrainEventObjGfx -_081A7114: - movs r7, 0x1C - movs r4, 0 -_081A7118: - movs r6, 0x1 -_081A711A: - cmp r4, 0x1 - bne _081A7126 - ldr r0, =0x00004010 - adds r1, r5, 0 - bl VarSet -_081A7126: - cmp r6, 0x1 - bne _081A7132 - ldr r0, =0x00004011 - adds r1, r7, 0 - bl VarSet -_081A7132: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7070 - - thumb_func_start sub_81A7140 -sub_81A7140: @ 81A7140 - push {lr} - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r2, r0, 30 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - adds r3, r1, 0 - cmp r0, 0x4 - bhi _081A723A - lsls r0, 2 - ldr r1, =_081A7174 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A7174: - .4byte _081A7188 - .4byte _081A71A0 - .4byte _081A71C4 - .4byte _081A71E8 - .4byte _081A720C -_081A7188: - ldr r0, =gSpecialVar_Result - ldr r1, [r3] - ldr r3, =0x00000e02 - adds r1, r3 - ldrh r1, [r1] - strh r1, [r0] - b _081A723A - .pool -_081A71A0: - ldr r2, =gSpecialVar_Result - ldr r1, [r3] - ldr r3, =0x00000ca9 - adds r0, r1, r3 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 29 - ldr r3, =0x00000e04 - adds r1, r3 - adds r1, r0 - ldrh r0, [r1] - b _081A7238 - .pool -_081A71C4: - ldr r2, =gSpecialVar_Result - ldr r1, [r3] - ldr r3, =0x00000ca9 - adds r0, r1, r3 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 29 - ldr r3, =0x00000e08 - adds r1, r3 - adds r1, r0 - ldrh r0, [r1] - b _081A7238 - .pool -_081A71E8: - ldr r2, =gSpecialVar_Result - ldr r1, [r3] - ldr r3, =0x00000ca9 - adds r0, r1, r3 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 29 - ldr r3, =0x00000e0c - adds r1, r3 - adds r1, r0 - ldrh r0, [r1] - b _081A7238 - .pool -_081A720C: - cmp r2, 0 - beq _081A7228 - ldr r2, =gSpecialVar_Result - ldr r0, [r3] - ldr r1, =0x00000cdc - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 4 - b _081A7236 - .pool -_081A7228: - ldr r2, =gSpecialVar_Result - ldr r0, [r3] - ldr r3, =0x00000cdc - adds r0, r3 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 3 -_081A7236: - ands r0, r1 -_081A7238: - strh r0, [r2] -_081A723A: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7140 - - thumb_func_start sub_81A7248 -sub_81A7248: @ 81A7248 - push {r4,r5,lr} - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r3, r0, 30 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - adds r2, r1, 0 - cmp r0, 0x4 - bls _081A7264 - b _081A73AA -_081A7264: - lsls r0, 2 - ldr r1, =_081A7280 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A7280: - .4byte _081A7294 - .4byte _081A72AC - .4byte _081A72D8 - .4byte _081A7314 - .4byte _081A7344 -_081A7294: - ldr r0, [r2] - ldr r1, =gSpecialVar_0x8006 - ldrh r1, [r1] - ldr r5, =0x00000e02 - adds r0, r5 - strh r1, [r0] - b _081A73AA - .pool -_081A72AC: - ldr r0, =gSpecialVar_0x8006 - ldrh r3, [r0] - ldr r0, =0x0000270f - cmp r3, r0 - bls _081A72B8 - b _081A73AA -_081A72B8: - ldr r0, [r2] - ldr r2, =0x00000ca9 - adds r1, r0, r2 - ldrb r1, [r1] - lsls r1, 30 - lsrs r1, 29 - ldr r5, =0x00000e04 - b _081A732C - .pool -_081A72D8: - ldr r0, =gSpecialVar_0x8006 - ldrh r4, [r0] - adds r3, r4, 0 - ldr r0, =0x0000270f - cmp r3, r0 - bhi _081A73AA - ldr r1, [r2] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r2, r0, 30 - lsrs r0, r2, 29 - ldr r5, =0x00000e08 - adds r1, r5 - adds r0, r1, r0 - ldrh r0, [r0] - cmp r0, r3 - bcs _081A73AA - lsrs r0, r2, 29 - adds r0, r1, r0 - strh r4, [r0] - b _081A73AA - .pool -_081A7314: - ldr r0, =gSpecialVar_0x8006 - ldrh r3, [r0] - ldr r0, =0x0000270f - cmp r3, r0 - bhi _081A73AA - ldr r0, [r2] - ldr r2, =0x00000ca9 - adds r1, r0, r2 - ldrb r1, [r1] - lsls r1, 30 - lsrs r1, 29 - ldr r5, =0x00000e0c -_081A732C: - adds r0, r5 - adds r0, r1 - strh r3, [r0] - b _081A73AA - .pool -_081A7344: - cmp r3, 0 - beq _081A737C - ldr r0, =gSpecialVar_0x8006 - ldrh r0, [r0] - cmp r0, 0 - beq _081A7368 - ldr r0, [r2] - ldr r1, =0x00000cdc - adds r0, r1 - ldr r1, [r0] - movs r2, 0x80 - lsls r2, 4 - orrs r1, r2 - b _081A73A8 - .pool -_081A7368: - ldr r0, [r2] - ldr r2, =0x00000cdc - adds r0, r2 - ldr r1, [r0] - ldr r2, =0xfffff7ff - b _081A73A6 - .pool -_081A737C: - ldr r0, =gSpecialVar_0x8006 - ldrh r0, [r0] - cmp r0, 0 - beq _081A739C - ldr r0, [r2] - ldr r5, =0x00000cdc - adds r0, r5 - ldr r1, [r0] - movs r2, 0x80 - lsls r2, 3 - orrs r1, r2 - b _081A73A8 - .pool -_081A739C: - ldr r0, [r2] - ldr r1, =0x00000cdc - adds r0, r1 - ldr r1, [r0] - ldr r2, =0xfffffbff -_081A73A6: - ands r1, r2 -_081A73A8: - str r1, [r0] -_081A73AA: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7248 - - thumb_func_start sub_81A73B8 -sub_81A73B8: @ 81A73B8 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - cmp r0, 0xE - bls _081A73DC - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - b _081A73E0 - .pool -_081A73DC: - ldr r1, =gSpecialVar_Result - movs r0, 0 -_081A73E0: - strh r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A73B8 - - thumb_func_start sub_81A73EC -sub_81A73EC: @ 81A73EC - ldr r0, =gSpecialVar_Result - ldr r1, =gUnknown_0300128C - ldrb r1, [r1] - strh r1, [r0] - bx lr - .pool - thumb_func_end sub_81A73EC - - thumb_func_start sub_81A7400 -sub_81A7400: @ 81A7400 - ldr r1, =gUnknown_0300128E - movs r0, 0x1 - strb r0, [r1] - bx lr - .pool - thumb_func_end sub_81A7400 - - thumb_func_start sub_81A740C -sub_81A740C: @ 81A740C - ldr r1, =gUnknown_0300128E - movs r0, 0 - strb r0, [r1] - bx lr - .pool - thumb_func_end sub_81A740C - - thumb_func_start sub_81A7418 -sub_81A7418: @ 81A7418 - push {r4,lr} - 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 save_serialize_map - movs r0, 0x1 - bl TrySavingData - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7418 - - thumb_func_start nullsub_76 -nullsub_76: @ 81A7460 - bx lr - thumb_func_end nullsub_76 - - thumb_func_start nullsub_124 -nullsub_124: @ 81A7464 - bx lr - thumb_func_end nullsub_124 - - thumb_func_start sub_81A7468 -sub_81A7468: @ 81A7468 - push {lr} - ldr r0, =gUnknown_03001290 - ldr r0, [r0] - cmp r0, 0x20 - beq _081A748E - cmp r0, 0x20 - bhi _081A7484 - cmp r0, 0x7 - beq _081A74BC - cmp r0, 0x10 - beq _081A7498 - b _081A74C2 - .pool -_081A7484: - cmp r0, 0x40 - beq _081A74B0 - cmp r0, 0x80 - beq _081A74A4 - b _081A74C2 -_081A748E: - ldr r1, =gSpecialVar_Result - movs r0, 0 - b _081A74C0 - .pool -_081A7498: - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - b _081A74C0 - .pool -_081A74A4: - ldr r1, =gSpecialVar_Result - movs r0, 0x2 - b _081A74C0 - .pool -_081A74B0: - ldr r1, =gSpecialVar_Result - movs r0, 0x3 - b _081A74C0 - .pool -_081A74BC: - ldr r1, =gSpecialVar_Result - movs r0, 0x4 -_081A74C0: - strh r0, [r1] -_081A74C2: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7468 - - thumb_func_start sub_81A74CC -sub_81A74CC: @ 81A74CC - ldr r0, =gSpecialVar_Result - ldr r1, =gUnknown_0300128D - ldrb r1, [r1] - strh r1, [r0] - bx lr - .pool - thumb_func_end sub_81A74CC - - thumb_func_start sub_81A74E0 -sub_81A74E0: @ 81A74E0 - push {r4,lr} - bl Random - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - movs r0, 0x1 - ands r4, r0 - adds r4, 0x1 - adds r0, r4, 0 - bl sub_81A7F38 - ldr r0, =gSpecialVar_Result - strh r4, [r0] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A74E0 - - thumb_func_start sub_81A7508 -sub_81A7508: @ 81A7508 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - cmp r0, 0x4 - bhi _081A7538 - ldr r1, =gUnknown_0861231C - ldr r0, =gUnknown_03001294 - ldrb r0, [r0] - lsls r0, 3 - adds r0, r1 - ldrb r1, [r0, 0x2] - b _081A7560 - .pool -_081A7538: - cmp r0, 0xA - bhi _081A7554 - ldr r1, =gUnknown_0861231C - ldr r0, =gUnknown_03001294 - ldrb r0, [r0] - lsls r0, 3 - adds r0, r1 - ldrb r1, [r0, 0x3] - b _081A7560 - .pool -_081A7554: - ldr r1, =gUnknown_0861231C - ldr r0, =gUnknown_03001294 - ldrb r0, [r0] - lsls r0, 3 - adds r0, r1 - ldrb r1, [r0, 0x4] -_081A7560: - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - ldr r1, =gUnknown_086123E4 - adds r0, r1 - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7508 - - thumb_func_start sub_81A7580 -sub_81A7580: @ 81A7580 - push {lr} - ldr r0, =sub_81A7EE4 - movs r1, 0x2 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7580 - - thumb_func_start sub_81A7594 -sub_81A7594: @ 81A7594 - push {r4-r6,lr} - sub sp, 0x4 - adds r5, r0, 0 - movs r4, 0 - movs r1, 0 -_081A759E: - mov r2, sp - adds r0, r2, r4 - strb r1, [r0] - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x3 - bls _081A759E - adds r0, r5, 0 - movs r1, 0x3A - bl GetMonData - lsls r2, r0, 16 - mov r1, sp - strb r0, [r1] - mov r0, sp - lsrs r2, 24 - strb r2, [r0, 0x1] - adds r0, r5, 0 - movs r1, 0x39 - mov r2, sp - bl SetMonData - adds r0, r5, 0 - movs r1, 0x15 - bl GetMonData - lsls r0, 24 - lsrs r6, r0, 24 - movs r4, 0 -_081A75DA: - adds r1, r4, 0 - adds r1, 0xD - adds r0, r5, 0 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - adds r1, r6, 0 - adds r2, r4, 0 - bl CalculatePPWithBonus - mov r1, sp - strb r0, [r1] - adds r1, r4, 0 - adds r1, 0x11 - adds r0, r5, 0 - mov r2, sp - bl SetMonData - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x3 - bls _081A75DA - mov r0, sp - movs r1, 0 - strb r1, [r0] - strb r1, [r0, 0x1] - strb r1, [r0, 0x2] - strb r1, [r0, 0x3] - adds r0, r5, 0 - movs r1, 0x37 - mov r2, sp - bl SetMonData - add sp, 0x4 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_81A7594 - - thumb_func_start sub_81A7628 -sub_81A7628: @ 81A7628 - push {r4,lr} - adds r4, r1, 0 - bl GetMonAbility - lsls r0, 24 - lsrs r0, 24 - movs r1, 0 - cmp r4, 0x20 - beq _081A7652 - cmp r4, 0x20 - bhi _081A7648 - cmp r4, 0x7 - beq _081A7664 - cmp r4, 0x10 - beq _081A7658 - b _081A7674 -_081A7648: - cmp r4, 0x40 - beq _081A765E - cmp r4, 0x80 - beq _081A766E - b _081A7674 -_081A7652: - cmp r0, 0x28 - bne _081A7674 - b _081A7672 -_081A7658: - cmp r0, 0x29 - bne _081A7674 - b _081A7672 -_081A765E: - cmp r0, 0x7 - bne _081A7674 - b _081A7672 -_081A7664: - cmp r0, 0xF - beq _081A7672 - cmp r0, 0x48 - bne _081A7674 - b _081A7672 -_081A766E: - cmp r0, 0x11 - bne _081A7674 -_081A7672: - movs r1, 0x1 -_081A7674: - adds r0, r1, 0 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81A7628 - - thumb_func_start sub_81A767C -sub_81A767C: @ 81A767C - push {lr} - lsls r0, 16 - lsrs r2, r0, 16 - movs r3, 0 - cmp r1, 0x20 - beq _081A76C4 - cmp r1, 0x20 - bhi _081A7696 - cmp r1, 0x7 - beq _081A771C - cmp r1, 0x10 - beq _081A7704 - b _081A771C -_081A7696: - cmp r1, 0x40 - beq _081A76E0 - cmp r1, 0x80 - bne _081A771C - ldr r1, =gBaseStats - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r1 - ldrb r2, [r0, 0x6] - cmp r2, 0x8 - beq _081A771A - cmp r2, 0x3 - beq _081A771A - ldrb r0, [r0, 0x7] - cmp r0, 0x8 - beq _081A771A - cmp r0, 0x3 - bne _081A771C - b _081A771A - .pool -_081A76C4: - ldr r0, =gBaseStats - lsls r1, r2, 3 - subs r1, r2 - lsls r1, 2 - adds r1, r0 - ldrb r0, [r1, 0x6] - cmp r0, 0xF - beq _081A771A - ldrb r0, [r1, 0x7] - cmp r0, 0xF - bne _081A771C - b _081A771A - .pool -_081A76E0: - ldr r1, =gBaseStats - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r1 - ldrb r2, [r0, 0x6] - cmp r2, 0x4 - beq _081A771A - cmp r2, 0xD - beq _081A771A - ldrb r0, [r0, 0x7] - cmp r0, 0x4 - beq _081A771A - cmp r0, 0xD - bne _081A771C - b _081A771A - .pool -_081A7704: - ldr r0, =gBaseStats - lsls r1, r2, 3 - subs r1, r2 - lsls r1, 2 - adds r1, r0 - ldrb r0, [r1, 0x6] - cmp r0, 0xA - beq _081A771A - ldrb r0, [r1, 0x7] - cmp r0, 0xA - bne _081A771C -_081A771A: - movs r3, 0x1 -_081A771C: - adds r0, r3, 0 - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A767C - - thumb_func_start sub_81A7728 -sub_81A7728: @ 81A7728 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - movs r6, 0 -_081A7736: - mov r1, sp - adds r0, r1, r6 - strb r6, [r0] - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - cmp r6, 0x2 - bls _081A7736 - movs r4, 0 - mov r8, r4 -_081A774A: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 24 - lsrs r6, r0, 24 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 24 - lsrs r0, 24 - mov r1, sp - adds r2, r1, r6 - ldrb r3, [r2] - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - mov r0, r8 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - cmp r0, 0x9 - bls _081A774A - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r4, =0x00000cb2 - adds r0, r4 - ldrh r0, [r0] - movs r1, 0x1 - mov r10, r1 - cmp r0, 0x4 - bls _081A77A8 - movs r4, 0x3 - mov r10, r4 - cmp r0, 0x9 - bhi _081A77A8 - movs r0, 0x2 - mov r10, r0 -_081A77A8: - movs r1, 0 - str r1, [sp, 0x4] - ldr r7, =gUnknown_03001290 -_081A77AE: - movs r4, 0 - mov r9, r4 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x64 - bl __umodsi3 - lsls r0, 24 - lsrs r0, 24 - adds r1, r0, 0 - cmp r0, 0x22 - bhi _081A77DC - movs r0, 0x80 - b _081A77FC - .pool -_081A77DC: - cmp r0, 0x3B - bhi _081A77E4 - movs r0, 0x20 - b _081A77FC -_081A77E4: - cmp r0, 0x4F - bhi _081A77EC - movs r0, 0x40 - b _081A77FC -_081A77EC: - cmp r1, 0x59 - bhi _081A77FA - movs r0, 0x7 - b _081A77FC -_081A77F4: - movs r0, 0x1 - mov r9, r0 - b _081A786E -_081A77FA: - movs r0, 0x10 -_081A77FC: - str r0, [r7] - ldr r0, =gUnknown_03001290 - ldr r0, [r0] - ldr r1, [sp, 0x4] - cmp r1, r0 - beq _081A7874 - str r0, [sp, 0x4] - movs r4, 0 - mov r8, r4 - movs r6, 0 -_081A7810: - mov r1, sp - adds r0, r1, r6 - ldrb r1, [r0] - movs r0, 0x64 - muls r1, r0 - ldr r0, =gPlayerParty - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0x37 - bl GetMonData - bl pokemon_ailments_get_primary - lsls r0, 24 - cmp r0, 0 - bne _081A7860 - adds r0, r5, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _081A7860 - mov r0, r8 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - lsls r0, 16 - lsrs r4, r0, 16 - ldr r1, [r7] - adds r0, r4, 0 - bl sub_81A767C - lsls r0, 24 - cmp r0, 0 - beq _081A77F4 -_081A7860: - cmp r8, r10 - beq _081A786E - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - cmp r6, 0x2 - bls _081A7810 -_081A786E: - mov r4, r8 - cmp r4, 0 - beq _081A78CC -_081A7874: - mov r0, r9 - cmp r0, 0 - beq _081A77AE - ldr r0, =gUnknown_03001290 - ldr r0, [r0] - cmp r0, 0x20 - beq _081A7898 - cmp r0, 0x20 - bhi _081A78D0 - cmp r0, 0x7 - beq _081A78D0 - cmp r0, 0x10 - beq _081A78A4 - b _081A78D0 - .pool -_081A7898: - ldr r1, =gUnknown_0300128D - movs r0, 0x1 - b _081A78D4 - .pool -_081A78A4: - bl Random - lsls r0, 16 - lsrs r1, r0, 16 - movs r2, 0x1 - ands r1, r2 - cmp r1, 0 - beq _081A78C0 - ldr r0, =gUnknown_0300128D - strb r2, [r0] - b _081A78D6 - .pool -_081A78C0: - ldr r0, =gUnknown_0300128D - strb r1, [r0] - b _081A78D6 - .pool -_081A78CC: - movs r0, 0 - b _081A7956 -_081A78D0: - ldr r1, =gUnknown_0300128D - movs r0, 0 -_081A78D4: - strb r0, [r1] -_081A78D6: - movs r1, 0 - mov r8, r1 - movs r6, 0 -_081A78DC: - mov r4, sp - adds r0, r4, r6 - ldrb r1, [r0] - movs r0, 0x64 - muls r1, r0 - ldr r0, =gPlayerParty - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0x37 - bl GetMonData - bl pokemon_ailments_get_primary - lsls r0, 24 - cmp r0, 0 - bne _081A7946 - adds r0, r5, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _081A7946 - mov r0, r8 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - lsls r0, 16 - lsrs r4, r0, 16 - ldr r7, =gUnknown_03001290 - ldr r1, [r7] - adds r0, r5, 0 - bl sub_81A7628 - lsls r0, 24 - cmp r0, 0 - bne _081A7946 - ldr r1, [r7] - adds r0, r4, 0 - bl sub_81A767C - lsls r0, 24 - cmp r0, 0 - bne _081A7946 - adds r0, r5, 0 - movs r1, 0x37 - adds r2, r7, 0 - bl SetMonData -_081A7946: - cmp r8, r10 - beq _081A7954 - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - cmp r6, 0x2 - bls _081A78DC -_081A7954: - movs r0, 0x1 -_081A7956: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A7728 - - thumb_func_start sub_81A7974 -sub_81A7974: @ 81A7974 - push {r4-r7,lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - movs r7, 0x1 - cmp r0, 0x4 - bls _081A798E - movs r7, 0x3 - cmp r0, 0x9 - bhi _081A798E - movs r7, 0x2 -_081A798E: - movs r6, 0 - movs r5, 0 - b _081A79A2 - .pool -_081A799C: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 -_081A79A2: - cmp r5, 0x2 - bhi _081A79D8 - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0x37 - bl GetMonData - bl pokemon_ailments_get_primary - lsls r0, 24 - cmp r0, 0 - bne _081A79D4 - adds r0, r4, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _081A79D4 - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 -_081A79D4: - cmp r6, r7 - bne _081A799C -_081A79D8: - cmp r6, 0 - beq _081A79E4 - movs r0, 0x1 - b _081A79E6 - .pool -_081A79E4: - movs r0, 0 -_081A79E6: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81A7974 - - thumb_func_start sub_81A79EC -sub_81A79EC: @ 81A79EC - push {r4-r6,lr} - sub sp, 0x8 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - movs r4, 0xE1 - lsls r4, 4 - adds r0, r4 - ldrb r2, [r0] - movs r3, 0x78 - ands r3, r2 - adds r5, r1, 0 - cmp r3, 0x40 - bne _081A7A10 - lsls r0, r2, 25 - lsrs r0, 28 - b _081A7B48 - .pool -_081A7A10: - ldr r0, =gSpecialVar_0x8007 - lsls r1, r2, 29 - ldrh r0, [r0] - lsrs r1, 29 - cmp r0, r1 - bne _081A7A34 - cmp r3, 0x18 - bne _081A7A24 - bl sub_81A7728 -_081A7A24: - ldr r0, [r5] - adds r0, r4 - ldrb r0, [r0] - lsls r0, 25 - lsrs r0, 28 - b _081A7B48 - .pool -_081A7A34: - movs r2, 0 - ldr r3, =gUnknown_0861266C - movs r1, 0 -_081A7A3A: - mov r4, sp - adds r0, r4, r2 - strb r1, [r0] - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0x7 - bls _081A7A3A - movs r4, 0x8 - ldr r0, [r5] - movs r6, 0xE1 - lsls r6, 4 - adds r0, r6 - ldrb r0, [r0] - lsls r0, 25 - lsrs r0, 28 - adds r0, r3 - ldrb r1, [r0] - movs r2, 0 - adds r5, r3, 0 - movs r3, 0x1 -_081A7A64: - adds r0, r2, r5 - ldrb r0, [r0] - cmp r0, r1 - bne _081A7A78 - mov r6, sp - adds r0, r6, r2 - strb r3, [r0] - subs r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 -_081A7A78: - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0x7 - bls _081A7A64 - mov r0, sp - ldrb r0, [r0, 0x7] - cmp r0, 0x1 - beq _081A7AA0 - bl sub_81A8554 - lsls r0, 24 - cmp r0, 0 - bne _081A7AA0 - mov r1, sp - movs r0, 0x1 - strb r0, [r1, 0x7] - subs r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 -_081A7AA0: - mov r0, sp - ldrb r0, [r0, 0x3] - cmp r0, 0x1 - beq _081A7ABE - bl sub_81A7974 - lsls r0, 24 - cmp r0, 0 - bne _081A7ABE - mov r1, sp - movs r0, 0x1 - strb r0, [r1, 0x3] - subs r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 -_081A7ABE: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - movs r1, 0xE1 - lsls r1, 4 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _081A7AFA - mov r0, sp - ldrb r0, [r0, 0x1] - cmp r0, 0x1 - beq _081A7AE6 - mov r1, sp - movs r0, 0x1 - strb r0, [r1, 0x1] - subs r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 -_081A7AE6: - mov r0, sp - ldrb r0, [r0, 0x4] - cmp r0, 0x1 - beq _081A7AFA - mov r1, sp - movs r0, 0x1 - strb r0, [r1, 0x4] - subs r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 -_081A7AFA: - adds r0, r4, 0 - bl AllocZeroed - adds r5, r0, 0 - movs r3, 0 - movs r2, 0 -_081A7B06: - mov r6, sp - adds r0, r6, r2 - ldrb r0, [r0] - cmp r0, 0 - bne _081A7B1C - adds r1, r3, 0 - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - adds r1, r5, r1 - strb r2, [r1] -_081A7B1C: - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0x7 - bls _081A7B06 - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r4, 0 - bl __modsi3 - adds r0, r5, r0 - ldrb r4, [r0] - adds r0, r5, 0 - bl Free - cmp r4, 0x3 - bne _081A7B46 - bl sub_81A7728 -_081A7B46: - adds r0, r4, 0 -_081A7B48: - add sp, 0x8 - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A79EC - - thumb_func_start sub_81A7B58 -sub_81A7B58: @ 81A7B58 - push {r4,lr} - ldr r4, =gUnknown_03001294 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x19 - bl __umodsi3 - strb r0, [r4] - ldr r1, =gUnknown_0861231C - ldrb r0, [r4] - lsls r0, 3 - adds r0, r1 - ldrh r0, [r0] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A7B58 - - thumb_func_start sub_81A7B84 -sub_81A7B84: @ 81A7B84 - ldr r0, =gUnknown_0300128E - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_81A7B84 - - thumb_func_start TryGenerateBattlePikeWildMon -TryGenerateBattlePikeWildMon: @ 81A7B90 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - bl GetBattlePikeWildMonHeaderId - lsls r0, 24 - lsrs r6, r0, 24 - ldr r7, =gSaveBlock2Ptr - ldr r0, [r7] - ldr r4, =0x00000ca9 - adds r0, r4 - ldrb r0, [r0] - lsls r0, 30 - ldr r1, =gUnknown_08612314 - lsrs r0, 28 - adds r0, r1 - ldr r0, [r0] - str r0, [sp, 0x4] - ldr r0, =gEnemyParty - movs r1, 0xB - movs r2, 0 - bl GetMonData - adds r5, r0, 0 - lsls r0, r5, 16 - lsrs r0, 16 - bl sub_81A890C - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, [r7] - adds r0, r4 - ldrb r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - beq _081A7C1C - bl GetHighestLevelInPlayerParty - adds r7, r0, 0 - cmp r7, 0x3B - ble _081A7C08 - lsls r0, r6, 2 - ldr r1, [sp, 0x4] - adds r0, r1 - ldr r1, [r0] - lsls r0, r5, 1 - adds r0, r5 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0, 0x2] - subs r7, r0 - cmp r7, 0x3B - bgt _081A7C32 -_081A7C08: - movs r7, 0x3C - b _081A7C32 - .pool -_081A7C1C: - lsls r0, r6, 2 - ldr r2, [sp, 0x4] - adds r0, r2 - ldr r1, [r0] - lsls r0, r5, 1 - adds r0, r5 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x2] - movs r0, 0x32 - subs r7, r0, r1 -_081A7C32: - mov r0, r8 - cmp r0, 0x1 - bne _081A7C4A - lsls r0, r7, 24 - lsrs r0, 24 - bl sub_81A88B0 - lsls r0, 24 - cmp r0, 0 - bne _081A7C4A - movs r0, 0 - b _081A7CE2 -_081A7C4A: - ldr r0, =gEnemyParty - ldr r1, =gBaseStats - mov r8, r1 - lsls r6, 2 - mov r9, r6 - ldr r2, [sp, 0x4] - add r2, r9 - mov r10, r2 - ldr r1, [r2] - lsls r6, r5, 1 - adds r4, r6, r5 - lsls r4, 2 - adds r1, r4, r1 - ldrh r2, [r1] - lsls r1, r2, 3 - subs r1, r2 - lsls r1, 2 - add r1, r8 - ldrb r2, [r1, 0x13] - movs r1, 0xCA - lsls r1, 1 - muls r2, r1 - lsls r1, r7, 2 - ldr r3, =gExperienceTables - adds r1, r3 - adds r2, r1 - movs r1, 0x19 - bl SetMonData - mov r1, r10 - ldr r0, [r1] - adds r4, r0 - ldrh r1, [r4] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - add r0, r8 - ldrb r0, [r0, 0x17] - mov r7, r9 - cmp r0, 0 - beq _081A7CA8 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1 - ands r0, r1 -_081A7CA8: - str r0, [sp] - ldr r0, =gEnemyParty - movs r1, 0x2E - mov r2, sp - bl SetMonData - movs r4, 0 - adds r0, r6, r5 - lsls r6, r0, 2 -_081A7CBA: - ldr r2, [sp, 0x4] - adds r0, r7, r2 - ldr r0, [r0] - adds r0, r6, r0 - lsls r1, r4, 1 - adds r0, 0x4 - adds r0, r1 - ldrh r1, [r0] - lsls r2, r4, 24 - lsrs r2, 24 - ldr r0, =gEnemyParty - bl SetMonMoveSlot - adds r4, 0x1 - cmp r4, 0x3 - ble _081A7CBA - ldr r0, =gEnemyParty - bl CalculateMonStats - movs r0, 0x1 -_081A7CE2: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end TryGenerateBattlePikeWildMon - - thumb_func_start GetBattlePikeWildMonHeaderId -GetBattlePikeWildMonHeaderId: @ 81A7D00 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - 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 r1, [r1] - adds r2, r1, 0 - movs r0, 0x8C - lsls r0, 1 - cmp r1, r0 - bhi _081A7D34 - movs r1, 0 - b _081A7D4C - .pool -_081A7D34: - movs r0, 0x8C - lsls r0, 2 - cmp r1, r0 - bhi _081A7D40 - movs r1, 0x1 - b _081A7D4C -_081A7D40: - movs r0, 0xD2 - lsls r0, 2 - movs r1, 0x3 - cmp r2, r0 - bhi _081A7D4C - movs r1, 0x2 -_081A7D4C: - adds r0, r1, 0 - pop {r1} - bx r1 - thumb_func_end GetBattlePikeWildMonHeaderId - - thumb_func_start sub_81A7D54 -sub_81A7D54: @ 81A7D54 - push {r4,r5,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r5, =gUnknown_08612688 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r4, r1, r2 -_081A7D66: - movs r1, 0x8 - ldrsh r0, [r4, r1] - lsls r0, 2 - adds r0, r5 - ldr r1, [r0] - adds r0, r4, 0 - bl _call_via_r1 - lsls r0, 24 - cmp r0, 0 - bne _081A7D66 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7D54 - - thumb_func_start sub_81A7D8C -sub_81A7D8C: @ 81A7D8C - push {r4,lr} - adds r4, r0, 0 - ldrh r1, [r4, 0x14] - movs r2, 0x14 - ldrsh r0, [r4, r2] - cmp r0, 0 - beq _081A7DA4 - subs r0, r1, 0x1 - strh r0, [r4, 0x14] - lsls r0, 16 - cmp r0, 0 - bne _081A7DC8 -_081A7DA4: - ldrh r0, [r4, 0xA] - strh r0, [r4, 0x14] - ldrh r0, [r4, 0x10] - ldrh r1, [r4, 0x16] - adds r0, r1 - strh r0, [r4, 0x16] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x10 - ble _081A7DBC - movs r0, 0x10 - strh r0, [r4, 0x16] -_081A7DBC: - movs r0, 0x1 - negs r0, r0 - ldrb r1, [r4, 0x16] - ldr r2, =0x00002d6b - bl BlendPalettes -_081A7DC8: - movs r2, 0x16 - ldrsh r0, [r4, r2] - cmp r0, 0xF - ble _081A7DDA - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] - ldrh r0, [r4, 0xC] - strh r0, [r4, 0x14] -_081A7DDA: - movs r0, 0 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A7D8C - - thumb_func_start sub_81A7DE8 -sub_81A7DE8: @ 81A7DE8 - push {r4,lr} - adds r4, r0, 0 - ldrh r1, [r4, 0x14] - movs r2, 0x14 - ldrsh r0, [r4, r2] - cmp r0, 0 - beq _081A7E00 - subs r0, r1, 0x1 - strh r0, [r4, 0x14] - lsls r0, 16 - cmp r0, 0 - bne _081A7E22 -_081A7E00: - ldrh r0, [r4, 0xC] - strh r0, [r4, 0x14] - ldrh r0, [r4, 0x16] - ldrh r1, [r4, 0x12] - subs r0, r1 - strh r0, [r4, 0x16] - lsls r0, 16 - cmp r0, 0 - bge _081A7E16 - movs r0, 0 - strh r0, [r4, 0x16] -_081A7E16: - movs r0, 0x1 - negs r0, r0 - ldrb r1, [r4, 0x16] - ldr r2, =0x00002d6b - bl BlendPalettes -_081A7E22: - movs r0, 0x16 - ldrsh r1, [r4, r0] - cmp r1, 0 - bne _081A7E56 - ldrh r0, [r4, 0xE] - subs r0, 0x1 - strh r0, [r4, 0xE] - lsls r0, 16 - cmp r0, 0 - bne _081A7E50 - ldr r0, =sub_81A7D54 - bl FindTaskIdByFunc - lsls r0, 24 - lsrs r0, 24 - bl DestroyTask - b _081A7E56 - .pool -_081A7E50: - ldrh r0, [r4, 0xA] - strh r0, [r4, 0x14] - strh r1, [r4, 0x8] -_081A7E56: - movs r0, 0 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81A7DE8 - - thumb_func_start sub_81A7E60 -sub_81A7E60: @ 81A7E60 - push {r4-r6,lr} - mov r6, r8 - push {r6} - sub sp, 0x4 - mov r8, r0 - adds r4, r1, 0 - adds r5, r2, 0 - adds r6, r3, 0 - ldr r3, [sp, 0x18] - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 16 - lsrs r5, 16 - lsls r6, 16 - lsrs r6, 16 - lsls r3, 16 - lsrs r3, 16 - ldr r0, =sub_81A7D54 - movs r1, 0x3 - str r3, [sp] - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r1, r2 - mov r0, r8 - strh r0, [r1, 0xA] - strh r4, [r1, 0xC] - strh r5, [r1, 0xE] - strh r6, [r1, 0x10] - ldr r3, [sp] - strh r3, [r1, 0x12] - strh r0, [r1, 0x14] - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7E60 - - thumb_func_start sub_81A7EC4 -sub_81A7EC4: @ 81A7EC4 - push {lr} - ldr r0, =sub_81A7D54 - bl FindTaskIdByFunc - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _081A7EDC - movs r0, 0 - b _081A7EDE - .pool -_081A7EDC: - movs r0, 0x1 -_081A7EDE: - pop {r1} - bx r1 - thumb_func_end sub_81A7EC4 - - thumb_func_start sub_81A7EE4 -sub_81A7EE4: @ 81A7EE4 - push {r4,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - adds r4, r0, 0 - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r1, r0, r1 - ldrh r2, [r1, 0x8] - movs r3, 0x8 - ldrsh r0, [r1, r3] - cmp r0, 0 - bne _081A7F1C - adds r0, r2, 0x1 - strh r0, [r1, 0x8] - movs r0, 0x2 - str r0, [sp] - movs r0, 0 - movs r1, 0 - movs r2, 0x3 - movs r3, 0x2 - bl sub_81A7E60 - b _081A7F30 - .pool -_081A7F1C: - bl sub_81A7EC4 - lsls r0, 24 - cmp r0, 0 - beq _081A7F30 - bl EnableBothScriptContexts - adds r0, r4, 0 - bl DestroyTask -_081A7F30: - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_81A7EE4 - - thumb_func_start sub_81A7F38 -sub_81A7F38: @ 81A7F38 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4] - cmp r0, 0 - bne _081A7F50 - b _081A807A -_081A7F50: - movs r0, 0 - mov r8, r0 -_081A7F54: - mov r0, sp - add r0, r8 - mov r1, r8 - strb r1, [r0] - mov r0, r8 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - cmp r0, 0x2 - bls _081A7F54 - movs r5, 0 -_081A7F6C: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 24 - lsrs r4, r0, 24 - mov r2, sp - add r2, r8 - ldrb r3, [r2] - mov r0, sp - adds r1, r0, r4 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x9 - bls _081A7F6C - movs r1, 0 - mov r8, r1 -_081A7FB0: - movs r0, 0 - mov r10, r0 - mov r4, sp - add r4, r8 - ldrb r1, [r4] - movs r0, 0x64 - muls r1, r0 - ldr r0, =gPlayerParty - adds r7, r1, r0 - adds r0, r7, 0 - movs r1, 0x39 - bl GetMonData - lsls r0, 16 - lsrs r5, r0, 16 - adds r0, r7, 0 - movs r1, 0x3A - bl GetMonData - lsls r0, 16 - lsrs r6, r0, 16 - str r4, [sp, 0x8] - cmp r5, r6 - bcc _081A8044 - adds r0, r7, 0 - movs r1, 0x37 - bl GetMonData - bl pokemon_ailments_get_primary - lsls r0, 24 - cmp r0, 0 - beq _081A7FFC - movs r0, 0x1 - mov r10, r0 - b _081A8048 - .pool -_081A7FFC: - adds r0, r7, 0 - movs r1, 0x15 - bl GetMonData - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - movs r4, 0 - b _081A8014 -_081A800E: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 -_081A8014: - cmp r4, 0x3 - bhi _081A8048 - adds r1, r4, 0 - adds r1, 0xD - adds r0, r7, 0 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - mov r1, r9 - adds r2, r4, 0 - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r6, r0, 24 - adds r1, r4, 0 - adds r1, 0x11 - adds r0, r7, 0 - bl GetMonData - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, r6 - bcs _081A800E -_081A8044: - movs r1, 0x1 - mov r10, r1 -_081A8048: - mov r0, r10 - cmp r0, 0x1 - bne _081A806C - ldr r0, [sp, 0x8] - ldrb r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - bl sub_81A7594 - ldr r0, [sp, 0x4] - subs r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4] - cmp r0, 0 - beq _081A807A -_081A806C: - mov r0, r8 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - cmp r0, 0x2 - bls _081A7FB0 -_081A807A: - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A7F38 - - thumb_func_start sub_81A8090 -sub_81A8090: @ 81A8090 - push {r4,lr} - ldr r4, =gSpecialVar_Result - bl InBattlePike - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8090 - thumb_func_start InBattlePike InBattlePike: @ 81A80A8 push {lr} @@ -2225,7 +176,7 @@ _081A81BE: ands r0, r1 cmp r0, 0x18 bne _081A821C - bl sub_81A7974 + bl AtLeastOneHealthyMon lsls r0, 24 cmp r0, 0 bne _081A821C @@ -2764,7 +715,7 @@ sub_81A8658: @ 81A8658 adds r0, r3 ldrb r4, [r0] adds r0, r4, 0 - bl sub_81A7F38 + bl TryHealMons ldr r0, =gSpecialVar_Result strh r4, [r0] pop {r4} diff --git a/include/battle_factory.h b/include/battle_factory.h index b2d3fc10f..2db041b06 100644 --- a/include/battle_factory.h +++ b/include/battle_factory.h @@ -9,4 +9,4 @@ u8 sub_81A6F70(u8 battleMode, u8 lvlMode); u32 GetAiScriptsInBattleFactory(void); void SetMonMoveAvoidReturn(struct Pokemon *mon, u16 moveArg, u8 moveSlot); -#endif //GUARD_BATTLE_FACTORY_H +#endif // GUARD_BATTLE_FACTORY_H diff --git a/include/fieldmap.h b/include/fieldmap.h index 8287229ed..a50c79b43 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -35,6 +35,7 @@ bool8 sub_8088BF0(u16*, u16, u8); struct MapConnection *sub_8088950(u8 direction, int x, int y); bool8 sub_80889A8(u8 direction, int x, int y, struct MapConnection *connection); bool8 sub_8088A0C(int x, int src_width, int dest_width, int offset); +void save_serialize_map(void); void SpriteCB_PokeballGlow(struct Sprite *); void SpriteCB_PokecenterMonitor(struct Sprite *); diff --git a/include/global.h b/include/global.h index c2b139e7a..fd8284094 100644 --- a/include/global.h +++ b/include/global.h @@ -438,7 +438,10 @@ struct BattleFrontier /*0xE04*/ u16 pikeWinStreaks[2]; /*0xE08*/ u16 pikeRecordStreaks[2]; /*0xE0C*/ u16 pikeTotalStreaks[2]; - /*0xE10*/ u16 field_E10[5]; + /*0xE10*/ u16 field_E10_1:3; + /*0xE10*/ u16 field_E10_2:4; + /*0xE10*/ u16 field_E10_3:1; + /*0xE10*/ u8 field_E10[9]; /*0xE1A*/ u16 pyramidWinStreaks[2]; /*0xE1E*/ u16 pyramidRecordStreaks[2]; /*0xE1E*/ u16 field_E1F[5]; diff --git a/ld_script.txt b/ld_script.txt index 029dbb0b5..c29dbaaa8 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -267,6 +267,7 @@ SECTIONS { src/frontier_util.o(.text); src/battle_arena.o(.text); src/battle_factory.o(.text); + src/battle_pike.o(.text); asm/battle_frontier_2.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); diff --git a/src/battle_factory.c b/src/battle_factory.c index 703887ae5..37abf6add 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -13,7 +13,6 @@ #include "constants/trainers.h" #include "constants/moves.h" -extern u8 gUnknown_03001288; extern u16 gUnknown_03006298[]; extern const struct FacilityMon gBattleFrontierMons[]; @@ -21,6 +20,9 @@ extern const struct FacilityMon gSlateportBattleTentMons[]; extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; extern const u16 gBattleFrontierHeldItems[]; +// IWRAM bss +static IWRAM_DATA bool8 gUnknown_03001288; + // This file's functions. static void sub_81A5E94(void); static void sub_81A5FA8(void); @@ -200,7 +202,7 @@ static void sub_81A5E94(void) gSaveBlock2Ptr->frontier.factoryRentsCount[battleMode][lvlMode] = 0; } - gUnknown_03001288 = 0; + gUnknown_03001288 = FALSE; for (i = 0; i < 6; i++) gSaveBlock2Ptr->frontier.field_E70[i].monId |= 0xFFFF; for (i = 0; i < 3; i++) @@ -246,10 +248,10 @@ static void sub_81A6054(void) gSaveBlock2Ptr->frontier.field_CDC &= gUnknown_08612174[battleMode][lvlMode]; break; case 3: - if (gUnknown_03001288 == 1) + if (gUnknown_03001288 == TRUE) { gSaveBlock2Ptr->frontier.factoryRentsCount[battleMode][lvlMode] = gSpecialVar_0x8006; - gUnknown_03001288 = 0; + gUnknown_03001288 = FALSE; } break; } @@ -286,7 +288,7 @@ static void sub_81A6198(void) static void sub_81A61A4(void) { - gUnknown_03001288 = 1; + gUnknown_03001288 = TRUE; } static void sub_81A61B0(void) diff --git a/src/battle_pike.c b/src/battle_pike.c new file mode 100644 index 000000000..91e02a1bf --- /dev/null +++ b/src/battle_pike.c @@ -0,0 +1,856 @@ +#include "global.h" +#include "event_data.h" +#include "frontier_util.h" +#include "fieldmap.h" +#include "save.h" +#include "battle.h" +#include "random.h" +#include "task.h" +#include "battle_tower.h" +#include "party_menu.h" +#include "malloc.h" +#include "palette.h" +#include "script.h" +#include "constants/event_objects.h" +#include "constants/battle_frontier.h" +#include "constants/abilities.h" +#include "constants/rgb.h" + +#define PIKE_ROOM_SINGLE_BATTLE 0 +#define PIKE_ROOM_HEAL_FULL 1 +#define PIKE_ROOM_NPC 2 +#define PIKE_ROOM_STATUS 3 +#define PIKE_ROOM_HEAL_PART 4 +#define PIKE_ROOM_WILD_MONS 5 +#define PIKE_ROOM_HARD_BATTLE 6 +#define PIKE_ROOM_DOUBLE_BATTLE 7 +#define PIKE_ROOM_BRAIN 8 + +// For the room with a status effect. +#define PIKE_STATUS_KIRLIA 0 +#define PIKE_STATUS_DUSCLOPS 1 + +struct Unk0861231C +{ + u16 unk0; + u8 unk2; + u8 unk3; + u8 unk4; + u8 unk5; +}; + +struct PikeWildMon +{ + u16 species; + u8 unk2; + u16 moves[4]; +}; + +extern void (* const gUnknown_086125F8[])(void); + +extern const struct Unk0861231C gUnknown_0861231C[]; +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 *); + +// IWRAM bss +IWRAM_DATA u8 sRoomType; +IWRAM_DATA u8 sStatusMon; +IWRAM_DATA bool8 gUnknown_0300128E; +IWRAM_DATA u32 sStatusFlags; +IWRAM_DATA u8 gUnknown_03001294; + +// This file's functions. +u8 GetNextRoomType(void); +void sub_81A82A4(u8); +u16 sub_81A7B58(void); +void sub_81A8374(void); +void sub_81A5030(u8); +void TryHealMons(u8 healCount); +void sub_81A7EE4(u8 taskId); +bool8 sub_81A8554(void); +bool8 sub_81A7974(void); +u8 sub_81A890C(u16 species); +bool8 sub_81A88B0(u8 monLevel); + +u8 GetBattlePikeWildMonHeaderId(void); +bool32 TryGenerateBattlePikeWildMon(bool8 checkKeenEyeIntimidate); +bool8 InBattlePike(void); + +// code +void sub_81A703C(void) +{ + gUnknown_086125F8[gSpecialVar_0x8004](); +} + +void sub_81A705C(void) +{ + u8 roomType = GetNextRoomType(); + sRoomType = roomType; +} + +void sub_81A7070(void) +{ + bool32 setPerson1, setPerson2; + u32 person1; + u16 person2; + + VarSet(VAR_OBJ_GFX_ID_0, EVENT_OBJ_GFX_LINK_RECEPTIONIST); + VarSet(VAR_OBJ_GFX_ID_1, EVENT_OBJ_GFX_DUSCLOPS); + setPerson1 = TRUE; + setPerson2 = FALSE; + person1 = 0; + person2 = 0; + + switch (sRoomType) + { + case PIKE_ROOM_SINGLE_BATTLE: + sub_81A82A4(0); + setPerson1 = FALSE; + break; + case PIKE_ROOM_HEAL_FULL: + person1 = EVENT_OBJ_GFX_LINK_RECEPTIONIST; + break; + case PIKE_ROOM_NPC: + person1 = (u8)(sub_81A7B58()); + break; + case PIKE_ROOM_STATUS: + person1 = EVENT_OBJ_GFX_GENTLEMAN; + if (sStatusMon == PIKE_STATUS_DUSCLOPS) + person2 = EVENT_OBJ_GFX_DUSCLOPS; + else + person2 = EVENT_OBJ_GFX_KIRLIA; + setPerson2 = TRUE; + break; + case PIKE_ROOM_HEAL_PART: + person1 = EVENT_OBJ_GFX_GENTLEMAN; + break; + case PIKE_ROOM_WILD_MONS: + setPerson1 = FALSE; + break; + case PIKE_ROOM_HARD_BATTLE: + sub_81A82A4(1); + person2 = EVENT_OBJ_GFX_LINK_RECEPTIONIST; + setPerson1 = FALSE; + setPerson2 = TRUE; + break; + case PIKE_ROOM_DOUBLE_BATTLE: + sub_81A8374(); + setPerson1 = FALSE; + break; + case PIKE_ROOM_BRAIN: + SetFrontierBrainEventObjGfx(FRONTIER_FACILITY_PIKE); + person2 = EVENT_OBJ_GFX_LINK_RECEPTIONIST; + setPerson1 = FALSE; + setPerson2 = TRUE; + break; + default: + return; + } + + if (setPerson1 == TRUE) + VarSet(VAR_OBJ_GFX_ID_0, person1); + if (setPerson2 == TRUE) + VarSet(VAR_OBJ_GFX_ID_1, person2); +} + +void sub_81A7140(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + switch (gSpecialVar_0x8005) + { + case 0: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_E02; + break; + case 1: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pikeWinStreaks[gSaveBlock2Ptr->frontier.lvlMode]; + break; + case 2: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pikeRecordStreaks[gSaveBlock2Ptr->frontier.lvlMode]; + break; + case 3: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pikeTotalStreaks[gSaveBlock2Ptr->frontier.lvlMode]; + break; + case 4: + if (lvlMode != FRONTIER_LVL_50) + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x800; + else + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x400; + break; + } +} + +void sub_81A7248(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + switch (gSpecialVar_0x8005) + { + case 0: + gSaveBlock2Ptr->frontier.field_E02 = gSpecialVar_0x8006; + break; + case 1: + if (gSpecialVar_0x8006 <= 9999) + gSaveBlock2Ptr->frontier.pikeWinStreaks[gSaveBlock2Ptr->frontier.lvlMode] = gSpecialVar_0x8006; + break; + case 2: + if (gSpecialVar_0x8006 <= 9999 && gSaveBlock2Ptr->frontier.pikeRecordStreaks[gSaveBlock2Ptr->frontier.lvlMode] < gSpecialVar_0x8006) + gSaveBlock2Ptr->frontier.pikeRecordStreaks[gSaveBlock2Ptr->frontier.lvlMode] = gSpecialVar_0x8006; + break; + case 3: + if (gSpecialVar_0x8006 <= 9999) + gSaveBlock2Ptr->frontier.pikeTotalStreaks[gSaveBlock2Ptr->frontier.lvlMode] = gSpecialVar_0x8006; + break; + case 4: + if (lvlMode != FRONTIER_LVL_50) + { + if (gSpecialVar_0x8006) + gSaveBlock2Ptr->frontier.field_CDC |= 0x800; + else + gSaveBlock2Ptr->frontier.field_CDC &= ~(0x800); + } + else + { + if (gSpecialVar_0x8006) + gSaveBlock2Ptr->frontier.field_CDC |= 0x400; + else + gSaveBlock2Ptr->frontier.field_CDC &= ~(0x400); + } + break; + } +} + +void sub_81A73B8(void) +{ + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum >= 15) + gSpecialVar_Result = TRUE; + else + gSpecialVar_Result = FALSE; +} + +void sub_81A73EC(void) +{ + gSpecialVar_Result = sRoomType; +} + +void sub_81A7400(void) +{ + gUnknown_0300128E = TRUE; +} + +void sub_81A740C(void) +{ + gUnknown_0300128E = FALSE; +} + +void sub_81A7418(void) +{ + gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; + VarSet(VAR_TEMP_0, 0); + gSaveBlock2Ptr->frontier.field_CA9_a = 1; + save_serialize_map(); + TrySavingData(SAVE_LINK); +} + +void nullsub_76(void) +{ + +} + +void nullsub_124(void) +{ + +} + +void sub_81A7468(void) +{ + switch (sStatusFlags) + { + case STATUS1_FREEZE: + gSpecialVar_Result = 0; + break; + case STATUS1_BURN: + gSpecialVar_Result = 1; + break; + case STATUS1_TOXIC_POISON: + gSpecialVar_Result = 2; + break; + case STATUS1_PARALYSIS: + gSpecialVar_Result = 3; + break; + case STATUS1_SLEEP: + gSpecialVar_Result = 4; + break; + } +} + +void sub_81A74CC(void) +{ + gSpecialVar_Result = sStatusMon; +} + +void sub_81A74E0(void) +{ + u16 toHeal = (Random() % 2) + 1; + TryHealMons(toHeal); + gSpecialVar_Result = toHeal; +} + +void sub_81A7508(void) +{ + s32 id; + + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 4) + id = gUnknown_0861231C[gUnknown_03001294].unk2; + else if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 10) + id = gUnknown_0861231C[gUnknown_03001294].unk3; + else + id = gUnknown_0861231C[gUnknown_03001294].unk4; + + FrontierSpeechToString(gUnknown_086123E4[id]); +} + +void sub_81A7580(void) +{ + CreateTask(sub_81A7EE4, 2); +} + +void HealMon(struct Pokemon *mon) +{ + u8 i; + u16 hp; + u8 ppBonuses; + u8 data[4]; + + for (i = 0; i < 4; i++) + data[i] = 0; + + hp = GetMonData(mon, MON_DATA_MAX_HP); + data[0] = hp; + data[1] = hp >> 8; + SetMonData(mon, MON_DATA_HP, data); + + ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES); + for (i = 0; i < 4; i++) + { + u16 move = GetMonData(mon, MON_DATA_MOVE1 + i); + data[0] = CalculatePPWithBonus(move, ppBonuses, i); + SetMonData(mon, MON_DATA_PP1 + i, data); + } + + data[0] = 0; + data[1] = 0; + data[2] = 0; + data[3] = 0; + SetMonData(mon, MON_DATA_STATUS, data); +} + +bool8 DoesAbilityPreventStatus(struct Pokemon *mon, u32 status) +{ + u8 ability = GetMonAbility(mon); + bool8 ret = FALSE; + + switch (status) + { + case STATUS1_FREEZE: + if (ability == ABILITY_MAGMA_ARMOR) + ret = TRUE; + break; + case STATUS1_BURN: + if (ability == ABILITY_WATER_VEIL) + ret = TRUE; + break; + case STATUS1_PARALYSIS: + if (ability == ABILITY_LIMBER) + ret = TRUE; + break; + case STATUS1_SLEEP: + if (ability == ABILITY_INSOMNIA || ability == ABILITY_VITAL_SPIRIT) + ret = TRUE; + break; + case STATUS1_TOXIC_POISON: + if (ability == ABILITY_IMMUNITY) + ret = TRUE; + break; + } + return ret; +} + +bool8 DoesTypePreventStatus(u16 species, u32 status) +{ + bool8 ret = FALSE; + + switch (status) + { + case STATUS1_TOXIC_POISON: + if (gBaseStats[species].type1 == TYPE_STEEL || gBaseStats[species].type1 == TYPE_POISON + || gBaseStats[species].type2 == TYPE_STEEL || gBaseStats[species].type2 == TYPE_POISON) + ret = TRUE; + break; + case STATUS1_FREEZE: + if (gBaseStats[species].type1 == TYPE_ICE || gBaseStats[species].type2 == TYPE_ICE) + ret = TRUE; + break; + case STATUS1_PARALYSIS: + if (gBaseStats[species].type1 == TYPE_GROUND || gBaseStats[species].type1 == TYPE_ELECTRIC + || gBaseStats[species].type2 == TYPE_GROUND || gBaseStats[species].type2 == TYPE_ELECTRIC) + ret = TRUE; + break; + case STATUS1_BURN: + if (gBaseStats[species].type1 == TYPE_FIRE || gBaseStats[species].type2 == TYPE_FIRE) + ret = TRUE; + break; + case STATUS1_SLEEP: + break; + } + return ret; +} + +bool8 TryInflictRandomStatus(void) +{ + u8 j, i; + u8 count; + u8 indices[3]; + u32 status; + u16 species; + bool8 statusChosen; + struct Pokemon *mon; + + for (i = 0; i < 3; i++) + indices[i] = i; + for (j = 0; j < 10; j++) + { + u8 temp, id; + + i = Random() % 3; + id = Random() % 3; + SWAP(indices[i], indices[id], temp); + } + + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 4) + count = 1; + else if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 9) + count = 2; + else + count = 3; + + status = 0; + do + { + u8 rand; + + statusChosen = FALSE; + rand = Random() % 100; + + if (rand < 35) + sStatusFlags = STATUS1_TOXIC_POISON; + else if (rand < 60) + sStatusFlags = STATUS1_FREEZE; + else if (rand < 80) + sStatusFlags = STATUS1_PARALYSIS; + else if (rand < 90) + sStatusFlags = STATUS1_SLEEP; + else + sStatusFlags = STATUS1_BURN; + + if (status != sStatusFlags) + { + status = sStatusFlags; + j = 0; + for (i = 0; i < 3; i++) + { + mon = &gPlayerParty[indices[i]]; + if (pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) == 0 + && GetMonData(mon, MON_DATA_HP) != 0) + { + j++; + species = GetMonData(mon, MON_DATA_SPECIES); + if (!DoesTypePreventStatus(species, sStatusFlags)) + { + statusChosen = TRUE; + break; + } + } + if (j == count) + break; + } + if (j == 0) + return FALSE; + } + } while (!statusChosen); + + switch (sStatusFlags) + { + case STATUS1_FREEZE: + sStatusMon = PIKE_STATUS_DUSCLOPS; + break; + case STATUS1_BURN: + if (Random() % 2 != 0) + sStatusMon = PIKE_STATUS_DUSCLOPS; + else + sStatusMon = PIKE_STATUS_KIRLIA; + break; + case STATUS1_PARALYSIS: + case STATUS1_SLEEP: + case STATUS1_TOXIC_POISON: + default: + sStatusMon = PIKE_STATUS_KIRLIA; + break; + } + + j = 0; + for (i = 0; i < 3; i++) + { + mon = &gPlayerParty[indices[i]]; + if (pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) == 0 + && GetMonData(mon, MON_DATA_HP) != 0) + { + j++; + species = GetMonData(mon, MON_DATA_SPECIES); + if (!DoesAbilityPreventStatus(mon, sStatusFlags) && !DoesTypePreventStatus(species, sStatusFlags)) + SetMonData(mon, MON_DATA_STATUS, &sStatusFlags); + } + if (j == count) + break; + } + + return TRUE; +} + +bool8 AtLeastOneHealthyMon(void) +{ + u8 i; + u8 healthyMonsCount; + u8 count; + + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 4) + count = 1; + else if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 9) + count = 2; + else + count = 3; + + healthyMonsCount = 0; + for (i = 0; i < 3; i++) + { + struct Pokemon *mon = &gPlayerParty[i]; + if (pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) == 0 + && GetMonData(mon, MON_DATA_HP) != 0) + { + healthyMonsCount++; + } + if (healthyMonsCount == count) + break; + } + + if (healthyMonsCount == 0) + return FALSE; + else + return TRUE; +} + +u8 GetNextRoomType(void) +{ + u8 sp[8]; + u8 i; + u8 ret; + u8 var; + u8 count; + u8 *allocated; + u8 r3; + + if (gSaveBlock2Ptr->frontier.field_E10_2 == 8) + return gSaveBlock2Ptr->frontier.field_E10_2; + if (gSpecialVar_0x8007 == gSaveBlock2Ptr->frontier.field_E10_1) + { + if (gSaveBlock2Ptr->frontier.field_E10_2 == 3) + TryInflictRandomStatus(); + return gSaveBlock2Ptr->frontier.field_E10_2; + } + + for (i = 0; i < 8; i++) + sp[i] = 0; + + count = 8; + var = gUnknown_0861266C[gSaveBlock2Ptr->frontier.field_E10_2]; + for (i = 0; i < 8; i++) + { + if (gUnknown_0861266C[i] == var) + { + sp[i] = 1; + count--; + } + } + + if (sp[7] != 1 && !sub_81A8554()) + { + sp[7] = 1; + count--; + } + if (sp[3] != 1 && !AtLeastOneHealthyMon()) + { + sp[3] = 1; + count--; + } + if (gSaveBlock2Ptr->frontier.field_E10_3) + { + if (sp[1] != 1) + { + sp[1] = 1; + count--; + } + if (sp[4] != 1) + { + sp[4] = 1; + count--; + } + } + + allocated = AllocZeroed(count); + r3 = 0; + for (i = 0; i < 8; i++) + { + if (sp[i] == 0) + allocated[r3++] = i; + } + + ret = allocated[Random() % count]; + free(allocated); + if (ret == PIKE_ROOM_STATUS) + TryInflictRandomStatus(); + + return ret; +} + +u16 sub_81A7B58(void) +{ + gUnknown_03001294 = Random() % 25; + return gUnknown_0861231C[gUnknown_03001294].unk0; +} + +u8 sub_81A7B84(void) +{ + return gUnknown_0300128E; +} + +bool32 TryGenerateBattlePikeWildMon(bool8 checkKeenEyeIntimidate) +{ + s32 i; + s32 monLevel; + u8 headerId = GetBattlePikeWildMonHeaderId(); + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + const struct PikeWildMon *const *const wildMons = gUnknown_08612314[lvlMode]; + u32 abilityBit; + s32 pikeMonId = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL); + pikeMonId = sub_81A890C(pikeMonId); + + if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50) + { + monLevel = GetHighestLevelInPlayerParty(); + if (monLevel < 60) + { + monLevel = 60; + } + else + { + monLevel -= wildMons[headerId][pikeMonId].unk2; + if (monLevel < 60) + monLevel = 60; + } + } + else + { + monLevel = 50 - wildMons[headerId][pikeMonId].unk2; + } + + if (checkKeenEyeIntimidate == TRUE && !sub_81A88B0(monLevel)) + return FALSE; + + SetMonData(&gEnemyParty[0], + MON_DATA_EXP, + &gExperienceTables[gBaseStats[wildMons[headerId][pikeMonId].species].growthRate][monLevel]); + + if (gBaseStats[wildMons[headerId][pikeMonId].species].ability2) + abilityBit = Random() % 2; + else + abilityBit = 0; + SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &abilityBit); + for (i = 0; i < 4; i++) + SetMonMoveSlot(&gEnemyParty[0], wildMons[headerId][pikeMonId].moves[i], i); + + CalculateMonStats(&gEnemyParty[0]); + return TRUE; +} + +u8 GetBattlePikeWildMonHeaderId(void) +{ + u8 headerId; + u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u16 winStreak = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode]; + + if (winStreak <= 280) + headerId = 0; + else if (winStreak <= 560) + headerId = 1; + else if (winStreak <= 840) + headerId = 2; + else + headerId = 3; + + return headerId; +} + +void sub_81A7D54(u8 taskId) +{ + while (gUnknown_08612688[gTasks[taskId].data[0]](&gTasks[taskId])); +} + +bool8 sub_81A7D8C(struct Task *task) +{ + if (task->data[6] == 0 || --task->data[6] == 0) + { + task->data[6] = task->data[1]; + task->data[7] += task->data[4]; + if (task->data[7] > 16) + task->data[7] = 16; + BlendPalettes(0xFFFFFFFF, task->data[7], RGB(11, 11, 11)); + } + + if (task->data[7] >= 16) + { + task->data[0]++; + task->data[6] = task->data[2]; + } + return FALSE; +} + +bool8 sub_81A7DE8(struct Task *task) +{ + if (task->data[6] == 0 || --task->data[6] == 0) + { + task->data[6] = task->data[2]; + task->data[7] -= task->data[5]; + if (task->data[7] < 0) + task->data[7] = 0; + BlendPalettes(0xFFFFFFFF, task->data[7], RGB(11, 11, 11)); + } + + if (task->data[7] == 0) + { + if (--task->data[3] == 0) + { + DestroyTask(FindTaskIdByFunc(sub_81A7D54)); + } + else + { + task->data[6] = task->data[1]; + task->data[0] = 0; + } + } + return FALSE; +} + +void sub_81A7E60(s16 a0, s16 a1, s16 a2, s16 a3, s16 a4) +{ + u8 taskId = CreateTask(sub_81A7D54, 3); + + gTasks[taskId].data[1] = a0; + gTasks[taskId].data[2] = a1; + gTasks[taskId].data[3] = a2; + gTasks[taskId].data[4] = a3; + gTasks[taskId].data[5] = a4; + gTasks[taskId].data[6] = a0; +} + +bool8 sub_81A7EC4(void) +{ + if (FindTaskIdByFunc(sub_81A7D54) == 0xFF) + return TRUE; + else + return FALSE; +} + +void sub_81A7EE4(u8 taskId) +{ + if (gTasks[taskId].data[0] == 0) + { + gTasks[taskId].data[0]++; + sub_81A7E60(0, 0, 3, 2, 2); + } + else + { + if (sub_81A7EC4()) + { + EnableBothScriptContexts(); + DestroyTask(taskId); + } + } +} + +void TryHealMons(u8 healCount) +{ + u8 j, i, k; + u8 indices[3]; + + if (healCount == 0) + return; + + for (i = 0; i < 3; i++) + indices[i] = i; + for (k = 0; k < 10; k++) + { + u8 temp; + + i = Random() % 3; + j = Random() % 3; + SWAP(indices[i], indices[j], temp); + } + + for (i = 0; i < 3; i++) + { + bool32 canBeHealed = FALSE; + struct Pokemon *mon = &gPlayerParty[indices[i]]; + u16 curr = GetMonData(mon, MON_DATA_HP); + u16 max = GetMonData(mon, MON_DATA_MAX_HP); + if (curr < max) + { + canBeHealed = TRUE; + } + else + { + if (pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) != 0) + { + 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) + { + canBeHealed = TRUE; + break; + } + } + } + } + + if (canBeHealed == TRUE) + { + HealMon(&gPlayerParty[indices[i]]); + if (--healCount == 0) + break; + } + } +} + +void sub_81A8090(void) +{ + gSpecialVar_Result = InBattlePike(); +} diff --git a/sym_bss.txt b/sym_bss.txt index a56ec7555..0b0d31b69 100644 --- a/sym_bss.txt +++ b/sym_bss.txt @@ -71,25 +71,8 @@ gUnknown_03001204: @ 3001204 .include "src/pokemon_animation.o" .include "src/recorded_battle.o" .include "src/battle_factory_screen.o" - -gUnknown_03001288: @ 3001288 - .space 0x4 - -gUnknown_0300128C: @ 300128C - .space 0x1 - -gUnknown_0300128D: @ 300128D - .space 0x1 - -gUnknown_0300128E: @ 300128E - .space 0x2 - -gUnknown_03001290: @ 3001290 - .space 0x4 - -gUnknown_03001294: @ 3001294 - .space 0x4 - + .include "src/battle_factory.o" + .include "src/battle_pike.o" .include "src/battle_tent.o" .include "src/multiboot.o"