From 78244fc4c9770c759a9fd43e194e366f7b69e6c2 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 26 Jul 2024 11:30:38 +0200 Subject: [PATCH] sub_80615E8 --- asm/code_805D8C8.s | 1006 ------------------------------ include/structs/dungeon_entity.h | 2 +- include/structs/str_dungeon.h | 3 +- src/code_805D8C8_1.c | 403 +++++++++++- 4 files changed, 405 insertions(+), 1009 deletions(-) diff --git a/asm/code_805D8C8.s b/asm/code_805D8C8.s index 79c36a159..ddf073bfd 100644 --- a/asm/code_805D8C8.s +++ b/asm/code_805D8C8.s @@ -7,1012 +7,6 @@ - thumb_func_start DrawFieldTeamMenu -DrawFieldTeamMenu: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - mov r9, r0 - mov r8, r1 - lsls r2, 24 - lsrs r2, 24 - str r2, [sp, 0x8] - movs r7, 0 - movs r1, 0 - mov r2, r8 - ldr r0, [r2, 0x4] - cmp r0, 0x6 - bne _08061154 - movs r1, 0x1 -_08061154: - mov r10, r1 - bl GetLeader - adds r1, r0, 0 - add r0, sp, 0x4 - bl sub_8069D18 - movs r6, 0 -_08061164: - ldr r0, _08061318 - ldr r0, [r0] - lsls r1, r6, 2 - ldr r3, _0806131C - adds r0, r3 - adds r0, r1 - ldr r4, [r0] - adds r0, r4, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _080611AC - lsls r1, r7, 2 - mov r0, r9 - adds r0, 0x4 - adds r0, r1 - str r6, [r0] - ldr r0, [r4, 0x70] - mov r1, r9 - adds r1, 0x14 - adds r1, r7 - ldr r5, _08061320 - adds r0, r5 - ldrb r0, [r0] - strb r0, [r1] - ldr r1, [sp, 0x4] - ldr r0, [r4, 0x4] - cmp r1, r0 - bne _080611AA - ldr r1, _08061324 - ldr r0, [r1] - cmp r0, 0 - bge _080611AA - str r7, [r1] -_080611AA: - adds r7, 0x1 -_080611AC: - adds r6, 0x1 - cmp r6, 0x3 - ble _08061164 - ldr r0, _08061324 - ldr r1, [r0] - adds r5, r0, 0 - cmp r1, r7 - blt _080611C0 - subs r0, r7, 0x1 - str r0, [r5] -_080611C0: - ldr r0, [r5] - cmp r0, 0 - bge _080611CA - movs r0, 0 - str r0, [r5] -_080611CA: - adds r6, r7, 0 - mov r0, r10 - negs r3, r0 - cmp r7, 0x3 - bgt _080611F4 - movs r1, 0x1 - negs r1, r1 - mov r12, r1 - mov r2, r9 - adds r2, 0x14 - movs r4, 0 - lsls r0, r7, 2 - adds r1, r0, 0x4 - add r1, r9 -_080611E6: - mov r0, r12 - stm r1!, {r0} - adds r0, r2, r6 - strb r4, [r0] - adds r6, 0x1 - cmp r6, 0x3 - ble _080611E6 -_080611F4: - ldr r1, _08061328 - movs r4, 0 - movs r0, 0x1 - strb r0, [r1] - strb r4, [r1, 0x1] - strb r4, [r1, 0x3] - ldr r0, _0806132C - ldr r1, [r5] - strh r1, [r0, 0x18] - strh r7, [r0, 0x1A] - strh r7, [r0, 0x1C] - strh r4, [r0, 0x1E] - strh r4, [r0, 0x20] - strh r4, [r0, 0x4] - mov r1, r10 - orrs r3, r1 - asrs r1, r3, 31 - movs r2, 0x10 - ands r1, r2 - strh r1, [r0, 0x6] - strh r4, [r0, 0xC] - strh r4, [r0, 0xE] - strh r4, [r0, 0x14] - str r4, [r0] - adds r0, 0x28 - bl sub_801317C - adds r0, r7, 0 - movs r1, 0 - bl sub_80095E4 - mov r2, r10 - cmp r2, 0 - beq _0806123A - adds r0, 0x2 -_0806123A: - mov r3, r8 - strh r0, [r3, 0x10] - strh r0, [r3, 0xE] - movs r0, 0x8 - ldr r5, _08061328 - strb r0, [r5, 0x2] - ldr r0, [sp, 0x8] - cmp r0, 0 - beq _0806125C - mov r1, r8 - adds r1, 0x18 - mov r0, r8 - adds r0, 0x48 - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} -_0806125C: - mov r0, r8 - movs r1, 0x1 - bl sub_803ECB4 - ldr r0, _0806132C - movs r1, 0 - bl sub_80137B0 - movs r0, 0 - bl sub_80073B8 - mov r0, r10 - cmp r0, 0 - beq _08061286 - ldr r2, _08061330 - str r4, [sp] - movs r0, 0xC - movs r1, 0 - movs r3, 0 - bl xxx_format_and_draw -_08061286: - movs r6, 0 - cmp r6, r7 - blt _0806128E - b _08061440 -_0806128E: - lsls r1, r6, 2 - mov r0, r9 - adds r0, 0x4 - adds r0, r1 - ldr r1, [r0] - cmp r1, 0 - bge _0806129E - b _08061438 -_0806129E: - ldr r0, _08061318 - ldr r0, [r0] - lsls r1, 2 - ldr r2, _0806131C - adds r0, r2 - adds r0, r1 - ldr r4, [r0] - adds r0, r4, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - bne _080612BA - b _08061438 -_080612BA: - ldr r5, [r4, 0x70] - mov r0, r9 - adds r0, 0x14 - adds r0, r6 - ldrb r0, [r0] - movs r2, 0x2 - cmp r0, 0 - beq _080612CC - movs r2, 0x6 -_080612CC: - ldr r4, _08061334 - adds r0, r4, 0 - adds r1, r5, 0 - bl sub_8070968 - ldr r0, _08061338 - ldr r1, [r0] - ldrb r2, [r5, 0xA] - movs r0, 0x64 - muls r0, r2 - adds r1, r0 - ldr r3, _0806133C - adds r1, r3 - movs r2, 0 - ldrsh r0, [r1, r2] - bl sub_806A538 - lsls r0, 24 - cmp r0, 0 - beq _08061388 - movs r3, 0x10 - ldrsh r2, [r5, r3] - adds r1, r2, 0 - cmp r2, 0 - bge _08061300 - adds r1, r2, 0x3 -_08061300: - movs r3, 0xE - ldrsh r0, [r5, r3] - asrs r1, 2 - cmp r0, r1 - bgt _08061344 - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _08061340 - bl strcpy - b _080613EE - .align 2, 0 -_08061318: .4byte gDungeon -_0806131C: .4byte 0x0001357c -_08061320: .4byte 0x00000157 -_08061324: .4byte gUnknown_202F260 -_08061328: .4byte gUnknown_202F270 -_0806132C: .4byte gUnknown_202EE10 -_08061330: .4byte gUnknown_8106BB0 -_08061334: .4byte gAvailablePokemonNames -_08061338: .4byte gRecruitedPokemonRef -_0806133C: .4byte 0x00008e02 -_08061340: .4byte gUnknown_8106BB4 -_08061344: - movs r0, 0xE - ldrsh r3, [r5, r0] - lsls r0, r1, 1 - cmp r3, r0 - bgt _08061360 - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _0806135C - bl strcpy - b _080613EE - .align 2, 0 -_0806135C: .4byte gUnknown_8106BB8 -_08061360: - adds r0, r1 - cmp r3, r0 - bgt _08061378 - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _08061374 - bl strcpy - b _080613EE - .align 2, 0 -_08061374: .4byte gUnknown_8106BBC -_08061378: - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _08061384 - bl strcpy - b _080613EE - .align 2, 0 -_08061384: .4byte gUnknown_8106BC0 -_08061388: - movs r1, 0x10 - ldrsh r2, [r5, r1] - adds r1, r2, 0 - cmp r2, 0 - bge _08061394 - adds r1, r2, 0x3 -_08061394: - movs r3, 0xE - ldrsh r0, [r5, r3] - asrs r1, 2 - cmp r0, r1 - bgt _080613B0 - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _080613AC - bl strcpy - b _080613EE - .align 2, 0 -_080613AC: .4byte gUnknown_8106BC4 -_080613B0: - movs r0, 0xE - ldrsh r3, [r5, r0] - lsls r0, r1, 1 - cmp r3, r0 - bgt _080613CC - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _080613C8 - bl strcpy - b _080613EE - .align 2, 0 -_080613C8: .4byte gUnknown_8106BC8 -_080613CC: - adds r0, r1 - cmp r3, r0 - bgt _080613E4 - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _080613E0 - bl strcpy - b _080613EE - .align 2, 0 -_080613E0: .4byte gUnknown_8106BCC -_080613E4: - adds r0, r4, 0 - adds r0, 0x50 - ldr r1, _0806141C - bl strcpy -_080613EE: - ldr r0, _08061420 - movs r2, 0xE - ldrsh r1, [r5, r2] - str r1, [r0] - movs r3, 0x10 - ldrsh r1, [r5, r3] - str r1, [r0, 0x4] - ldr r0, _08061424 - adds r1, r6, 0 - bl sub_8013800 - adds r1, r0, 0 - ldrb r0, [r5, 0x7] - cmp r0, 0 - beq _0806142C - movs r0, 0 - str r0, [sp] - movs r0, 0x9 - ldr r2, _08061428 - movs r3, 0 - bl xxx_format_and_draw - b _08061438 - .align 2, 0 -_0806141C: .4byte gUnknown_8106BD0 -_08061420: .4byte gFormatData_202DE30 -_08061424: .4byte gUnknown_202EE10 -_08061428: .4byte gUnknown_8106BD4 -_0806142C: - str r0, [sp] - movs r0, 0x9 - ldr r2, _08061458 - movs r3, 0 - bl xxx_format_and_draw -_08061438: - adds r6, 0x1 - cmp r6, r7 - bge _08061440 - b _0806128E -_08061440: - movs r0, 0 - bl sub_80073E0 - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08061458: .4byte gUnknown_8106BE0 - thumb_func_end DrawFieldTeamMenu - - thumb_func_start sub_806145C -sub_806145C: - push {r4-r6,lr} - ldr r2, _08061560 - movs r1, 0 - str r1, [r2] - ldr r5, _08061564 - ldr r2, [r5] - ldr r1, _08061568 - movs r3, 0x18 - ldrsh r1, [r1, r3] - lsls r1, 2 - adds r0, 0x4 - adds r0, r1 - ldr r0, [r0] - lsls r0, 2 - ldr r1, _0806156C - adds r2, r1 - adds r2, r0 - ldr r6, [r2] - ldr r4, [r6, 0x70] - movs r0, 0x1B - movs r1, 0 - bl sub_8044F5C - movs r0, 0x19 - movs r1, 0 - bl sub_8044F5C - ldrb r0, [r4, 0x7] - cmp r0, 0 - bne _080614C8 - ldr r2, [r5] - ldr r3, _08061570 - adds r0, r2, r3 - ldrb r0, [r0] - cmp r0, 0 - bne _080614C0 - adds r0, r4, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x41 - bne _080614B8 - ldr r1, _08061574 - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0 - beq _080614C0 -_080614B8: - movs r0, 0x34 - movs r1, 0 - bl sub_8044F5C -_080614C0: - movs r0, 0x1C - movs r1, 0 - bl sub_8044F5C -_080614C8: - movs r0, 0x30 - movs r1, 0 - bl sub_8044F5C - ldrb r0, [r4, 0x7] - cmp r0, 0 - bne _0806154C - movs r0, 0x1A - movs r1, 0 - bl sub_8044F5C - ldrb r0, [r4, 0x7] - cmp r0, 0 - bne _0806154C - ldr r0, _08061564 - ldr r1, [r0] - ldr r2, _08061574 - adds r0, r1, r2 - ldrb r0, [r0] - cmp r0, 0 - beq _0806154C - ldr r3, _08061578 - adds r0, r1, r3 - ldrb r0, [r0] - bl CanLeaderSwitch - lsls r0, 24 - cmp r0, 0 - beq _0806154C - movs r0, 0x3B - movs r1, 0 - bl sub_8044F5C - movs r5, 0x1 - ldrb r0, [r4, 0xA] - cmp r0, 0x3 - bhi _08061530 - ldr r2, _0806157C - ldrb r1, [r4, 0xA] - movs r0, 0x64 - muls r1, r0 - ldr r0, _08061580 - adds r1, r0 - ldr r0, [r2] - adds r0, r1 - movs r1, 0xA - ldrsh r0, [r0, r1] - bl sub_806A538 - lsls r0, 24 - cmp r0, 0 - beq _08061532 -_08061530: - movs r5, 0 -_08061532: - adds r0, r6, 0 - movs r1, 0 - bl CannotMove - lsls r0, 24 - cmp r0, 0 - beq _08061542 - movs r5, 0 -_08061542: - cmp r5, 0 - bne _0806154C - movs r0, 0x3B - bl sub_8044FF0 -_0806154C: - adds r0, r4, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x4A - beq _0806155A - cmp r0, 0x47 - bne _08061584 -_0806155A: - movs r0, 0x1 - b _08061586 - .align 2, 0 -_08061560: .4byte gUnknown_202EE6C -_08061564: .4byte gDungeon -_08061568: .4byte gUnknown_202EE10 -_0806156C: .4byte 0x0001357c -_08061570: .4byte 0x0000065d -_08061574: .4byte 0x0000065c -_08061578: .4byte 0x00000644 -_0806157C: .4byte gRecruitedPokemonRef -_08061580: .4byte 0x00008df8 -_08061584: - movs r0, 0 -_08061586: - cmp r0, 0 - beq _080615A8 - movs r0, 0x19 - bl sub_8044FF0 - movs r0, 0x3B - bl sub_8044FF0 - movs r0, 0x1A - bl sub_8044FF0 - movs r0, 0x30 - bl sub_8044FF0 - movs r0, 0x34 - bl sub_8044FF0 -_080615A8: - bl sub_8045064 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_806145C - - thumb_func_start sub_80615B4 -sub_80615B4: - push {r4,r5,lr} - adds r5, r0, 0 - adds r4, r1, 0 - ldr r1, _080615E0 - ldr r0, _080615E4 - movs r2, 0x18 - ldrsh r0, [r0, r2] - lsls r0, 2 - adds r0, r1 - ldrh r1, [r0] - adds r0, r5, 0 - bl SetMonsterActionFields - ldm r4!, {r0} - lsls r0, 2 - adds r4, r0 - ldr r0, [r4] - strb r0, [r5, 0x4] - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_080615E0: .4byte gUnknown_202EE44 -_080615E4: .4byte gUnknown_202EE10 - thumb_func_end sub_80615B4 - - thumb_func_start sub_80615E8 -sub_80615E8: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x7C - adds r5, r0, 0 - mov r4, sp - mov r0, sp - movs r1, 0 - movs r2, 0x60 - bl memset - movs r0, 0x6 - str r0, [sp, 0x4] - movs r1, 0x2 - strh r1, [r4, 0x8] - strh r1, [r4, 0xA] - movs r2, 0x12 - strh r2, [r4, 0xC] - movs r0, 0xE - strh r0, [r4, 0xE] - strh r2, [r4, 0x10] - strh r1, [r4, 0x12] - ldr r0, _08061720 - str r0, [sp, 0x14] - movs r0, 0x3 - str r0, [sp, 0x1C] - str r0, [sp, 0x34] - str r0, [sp, 0x4C] - ldr r0, _08061724 - ldr r1, [r0] - ldrb r0, [r5, 0x4] - lsls r0, 2 - ldr r2, _08061728 - adds r1, r2 - adds r1, r0 - ldr r1, [r1] - str r1, [sp, 0x74] - ldr r0, [r1, 0x70] - mov r8, r0 - movs r1, 0 - str r1, [sp, 0x70] - movs r2, 0 - str r2, [sp, 0x6C] - add r0, sp, 0x60 - mov r10, r0 -_08061646: - movs r1, 0x1 - str r1, [sp, 0x78] - movs r7, 0 - ldr r0, _08061720 - strb r1, [r0] - strb r7, [r0, 0x1] - movs r1, 0xA - strb r1, [r0, 0x2] - strb r7, [r0, 0x3] - mov r0, sp - movs r1, 0x1 - bl sub_803ECB4 - ldr r0, [sp, 0x6C] - mov r1, r10 - mov r2, r8 - movs r3, 0 - bl sub_806195C - movs r2, 0 - mov r1, r10 - ldrb r0, [r1] - cmp r0, 0xB - beq _08061684 -_08061676: - adds r2, 0x1 - cmp r2, 0x7 - bgt _08061684 - adds r0, r1, r2 - ldrb r0, [r0] - cmp r0, 0xB - bne _08061676 -_08061684: - ldr r4, _0806172C - movs r1, 0 - strh r2, [r4, 0x1A] - movs r0, 0x8 - strh r0, [r4, 0x1C] - strh r1, [r4, 0x1E] - strh r1, [r4, 0x20] - strh r1, [r4, 0x4] - movs r0, 0x10 - strh r0, [r4, 0x6] - strh r1, [r4, 0xC] - strh r1, [r4, 0xE] - strh r1, [r4, 0x14] - str r1, [r4] - adds r0, r4, 0 - adds r0, 0x28 - bl sub_801317C - adds r0, r4, 0 - movs r1, 0 - bl sub_80137B0 - add r2, sp, 0x70 - ldrh r2, [r2] - strh r2, [r4, 0x18] - mov r9, r4 - mov r6, r10 -_080616BA: - mov r0, r9 - bl AddMenuCursorSprite - ldrb r0, [r6, 0x8] - cmp r0, 0xB - beq _080616CA - bl sub_80623B0 -_080616CA: - ldr r0, [sp, 0x6C] - cmp r0, 0 - beq _080616D4 - bl sub_8062230 -_080616D4: - movs r0, 0x3D - bl sub_803E46C - ldr r0, _08061730 - ldrh r1, [r0, 0x4] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _08061740 - movs r0, 0x1 - bl sub_8083CE0 - mov r1, r9 - movs r2, 0x18 - ldrsh r0, [r1, r2] - cmp r0, 0x7 - bne _08061738 - ldrb r0, [r6, 0x8] - cmp r0, 0xB - beq _0806171A - ldr r5, [sp, 0x6C] - adds r5, 0x1 - ldr r6, _08061734 - movs r4, 0x5 -_08061704: - ldr r1, [r6] - movs r0, 0 - bl _call_via_r1 - movs r0, 0x3D - bl sub_803E46C - subs r4, 0x1 - cmp r4, 0 - bge _08061704 - str r5, [sp, 0x6C] -_0806171A: - movs r0, 0x7 - str r0, [sp, 0x70] - b _08061926 - .align 2, 0 -_08061720: .4byte gUnknown_202F270 -_08061724: .4byte gDungeon -_08061728: .4byte 0x0001357c -_0806172C: .4byte gUnknown_202EE10 -_08061730: .4byte gRealInputs -_08061734: .4byte gUnknown_203B080 -_08061738: - mov r0, r9 - movs r1, 0 - bl sub_80136E0 -_08061740: - ldr r0, _08061788 - ldrh r1, [r0, 0x4] - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _0806179C - movs r0, 0x1 - bl sub_8083CE0 - ldr r1, _0806178C - movs r2, 0x18 - ldrsh r0, [r1, r2] - cmp r0, 0 - bne _08061794 - ldr r0, [sp, 0x6C] - cmp r0, 0 - beq _08061780 - adds r5, r0, 0 - subs r5, 0x1 - ldr r6, _08061790 - movs r4, 0x5 -_0806176A: - ldr r1, [r6] - movs r0, 0 - bl _call_via_r1 - movs r0, 0x3D - bl sub_803E46C - subs r4, 0x1 - cmp r4, 0 - bge _0806176A - str r5, [sp, 0x6C] -_08061780: - movs r1, 0 - str r1, [sp, 0x70] - b _08061926 - .align 2, 0 -_08061788: .4byte gRealInputs -_0806178C: .4byte gUnknown_202EE10 -_08061790: .4byte gUnknown_203B084 -_08061794: - adds r0, r1, 0 - movs r1, 0 - bl sub_8013744 -_0806179C: - ldr r4, _080617C8 - ldrh r1, [r4, 0x2] - movs r0, 0x8 - ands r0, r1 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, 0 - beq _080617DE - mov r2, r9 - movs r1, 0x18 - ldrsh r0, [r2, r1] - mov r2, r10 - adds r1, r2, r0 - ldrb r4, [r1] - str r0, [sp, 0x70] - bl sub_8083D44 - adds r0, r4, 0 - bl sub_8062748 -_080617C4: - movs r7, 0 - b _08061926 - .align 2, 0 -_080617C8: .4byte gRealInputs -_080617CC: - bl sub_8083D08 - mov r0, r9 - movs r1, 0x18 - ldrsh r4, [r0, r1] - cmp r4, 0 - beq _080617DC - b _08061900 -_080617DC: - b _080618C4 -_080617DE: - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _080617F4 - ldr r2, _080618BC - adds r0, r2, 0 - adds r0, 0x29 - ldrb r0, [r0] - cmp r0, 0 - bne _080617F4 - b _0806190C -_080617F4: - mov r2, r9 - movs r0, 0x18 - ldrsh r1, [r2, r0] - mov r2, r10 - adds r0, r2, r1 - ldrb r7, [r0] - str r1, [sp, 0x70] - bl sub_8062D68 - bl sub_8083D08 - ldr r0, _080618C0 - str r5, [r0] - movs r0, 0x2F - movs r1, 0 - bl sub_8044F5C - movs r0, 0xC - movs r1, 0 - bl sub_8044F5C - ldr r0, [sp, 0x74] - movs r1, 0x1 - bl CannotMove - lsls r0, 24 - cmp r0, 0 - beq _08061832 - movs r0, 0x2F - bl sub_8044FF0 -_08061832: - mov r0, sp - movs r1, 0x16 - bl sub_805FC30 - ldr r5, _080618BC - adds r6, r4, 0 - adds r4, r5, 0 - adds r4, 0x2A -_08061842: - adds r0, r5, 0 - bl AddMenuCursorSprite - movs r0, 0x3D - bl sub_803E46C - ldrh r1, [r6, 0x4] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _08061866 - movs r0, 0x1 - bl sub_8083CE0 - adds r0, r5, 0 - movs r1, 0x1 - bl sub_80136E0 -_08061866: - ldrh r1, [r6, 0x4] - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _0806187E - movs r0, 0x1 - bl sub_8083CE0 - adds r0, r5, 0 - movs r1, 0x1 - bl sub_8013744 -_0806187E: - ldrh r1, [r6, 0x2] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _08061892 - adds r0, r5, 0 - adds r0, 0x29 - ldrb r0, [r0] - cmp r0, 0 - beq _080618A4 -_08061892: - movs r1, 0x18 - ldrsh r0, [r5, r1] - bl sub_8044F3C - lsls r0, 24 - cmp r0, 0 - bne _080617CC - bl sub_8083D30 -_080618A4: - ldrh r1, [r6, 0x2] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _080618B4 - ldrb r0, [r4] - cmp r0, 0 - beq _08061842 -_080618B4: - bl sub_8083D30 - b _080617C4 - .align 2, 0 -_080618BC: .4byte gUnknown_202EE10 -_080618C0: .4byte gUnknown_202EE6C -_080618C4: - ldr r0, _080618FC - bl PlaySoundEffect - mov r0, r8 - adds r0, 0x94 - strb r7, [r0] - mov r1, r8 - adds r1, 0x78 - movs r0, 0x6 - strb r0, [r1] - mov r0, r8 - adds r0, 0x80 - str r4, [r0] - adds r0, 0x4 - str r4, [r0] - subs r0, 0x8 - strh r4, [r0] - mov r2, r8 - ldrb r0, [r2, 0x7] - cmp r0, 0 - beq _080618F0 - b _080617C4 -_080618F0: - ldr r0, [sp, 0x74] - movs r1, 0x1 - bl MoveIfPossible - b _080617C4 - .align 2, 0 -_080618FC: .4byte 0x00000133 -_08061900: - adds r0, r7, 0 - bl sub_8062748 - movs r0, 0 - str r0, [sp, 0x78] - b _080617C4 -_0806190C: - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _08061920 - adds r0, r2, 0 - adds r0, 0x2A - ldrb r0, [r0] - cmp r0, 0 - bne _08061920 - b _080616BA -_08061920: - bl sub_8083D30 - movs r7, 0x1 -_08061926: - ldr r1, [sp, 0x78] - cmp r1, 0 - beq _08061932 - ldr r0, _08061958 - bl AddMenuCursorSprite -_08061932: - movs r0, 0x3D - bl sub_803E46C - cmp r7, 0 - bne _0806193E - b _08061646 -_0806193E: - movs r0, 0 - movs r1, 0 - bl sub_803EAF0 - add sp, 0x7C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08061958: .4byte gUnknown_202EE10 - thumb_func_end sub_80615E8 - thumb_func_start sub_806195C sub_806195C: push {r4-r7,lr} diff --git a/include/structs/dungeon_entity.h b/include/structs/dungeon_entity.h index adff0adf3..c9b508785 100644 --- a/include/structs/dungeon_entity.h +++ b/include/structs/dungeon_entity.h @@ -61,7 +61,7 @@ typedef struct AITarget /* 0x3 */ bool8 aiTurningAround; /* 0x4 */ u16 aiTargetSpawnGenID; /* 0x8 */ struct Entity *aiTarget; - /* 0xC */ u8 fillC[4]; + /* 0xC */ u32 unkC; /* 0x10 */ Position aiTargetPos; } AITarget; diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index f8b04bfd7..7ad24599a 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -158,7 +158,8 @@ typedef struct Dungeon u8 fill655[0x65B - 0x655]; u8 unk65B; u8 unk65C; - u8 fill65D[0x660 - 0x65D]; + u8 unk65D; + u8 fill65e[0x660 - 0x65e]; /* 0x660 */ s16 fractionalTurn; // Handles turn order when Pokémon have different movement speeds. s16 unk662; s16 unk664; diff --git a/src/code_805D8C8_1.c b/src/code_805D8C8_1.c index cc2ccabd4..efe1c914e 100644 --- a/src/code_805D8C8_1.c +++ b/src/code_805D8C8_1.c @@ -11,6 +11,7 @@ #include "dungeon_util.h" #include "pokemon.h" #include "dungeon_music.h" +#include "dungeon_ai_movement.h" #include "code_8045A00.h" #include "code_80130A8.h" #include "code_803E46C.h" @@ -2802,7 +2803,7 @@ extern void sub_8083CE0(u8 param_1); extern u8 gAvailablePokemonNames[]; extern u8 gUnknown_202749A[]; -extern u32 gUnknown_202F260; +extern s32 gUnknown_202F260; extern MenuInputStruct gUnknown_202EE10; void sub_805F02C(void) @@ -4386,3 +4387,403 @@ bool8 sub_8060E38(Entity *a0) sub_803EAF0(0, NULL); return ret; } + +bool32 sub_8069D18(Position *a0, Entity *a1); + +extern const u8 gUnknown_8106BB0[]; +extern const u8 gUnknown_8106BB4[]; +extern const u8 gUnknown_8106BB8[]; +extern const u8 gUnknown_8106BBC[]; +extern const u8 gUnknown_8106BC0[]; +extern const u8 gUnknown_8106BC4[]; +extern const u8 gUnknown_8106BC8[]; +extern const u8 gUnknown_8106BCC[]; +extern const u8 gUnknown_8106BD0[]; +extern const u8 gUnknown_8106BD4[]; +extern const u8 gUnknown_8106BE0[]; + +extern void sub_8070968(u8 *buffer, EntityInfo *entityInfo, s32 colorNum); + +void DrawFieldTeamMenu(struct UnkFieldTeamMenuStruct *a0, UnkTextStruct3 *a1, bool8 a2) +{ + s32 r0; + Position pos; + s32 i; + + s32 count = 0; + bool8 r10 = (a1->a0[0].unk4 == 6); + + sub_8069D18(&pos, GetLeader()); + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + EntityInfo *monInfo; + Entity *teamMon = gDungeon->teamPokemon[i]; + if (EntityExists(teamMon)) { + a0->unk4[count] = i; + monInfo = teamMon->info; + a0->unk14[count] = monInfo->unk157; + if (pos.x == teamMon->pos.x && pos.y == teamMon->pos.y && gUnknown_202F260 < 0) { + gUnknown_202F260 = count; + } + count++; + } + } + + if (gUnknown_202F260 >= count) { + gUnknown_202F260 = count - 1; + } + if (gUnknown_202F260 < 0) { + gUnknown_202F260 = 0; + } + + for (i = count; i < MAX_TEAM_MEMBERS; i++) { + a0->unk4[i] = -1; + a0->unk14[i] = 0; + } + + gUnknown_202F270.f0 = 1; + gUnknown_202F270.f1 = 0; + gUnknown_202F270.f3 = 0; + gUnknown_202EE10.menuIndex = gUnknown_202F260; + gUnknown_202EE10.unk1A = count; + gUnknown_202EE10.unk1C = count; + gUnknown_202EE10.unk1E = 0; + gUnknown_202EE10.unk20 = 0; + gUnknown_202EE10.unk4 = 0; + gUnknown_202EE10.unk6 = (r10 != FALSE) * 16; + gUnknown_202EE10.unkC = 0; + gUnknown_202EE10.unkE = 0; + gUnknown_202EE10.unk14.x = 0; + gUnknown_202EE10.unk0 = 0; + sub_801317C(&gUnknown_202EE10.unk28); + r0 = sub_80095E4(count, 0); + if (r10) { + r0 += 2; + } + a1->a0[0].unk10 = r0; + a1->a0[0].unkE = r0; + gUnknown_202F270.f2 = 8; + if (a2) { + a1->a0[1] = a1->a0[3]; + } + + sub_803ECB4(a1, 1); + sub_80137B0(&gUnknown_202EE10, 0); + sub_80073B8(0); + if (r10) { + xxx_format_and_draw(0xC, 0, gUnknown_8106BB0, 0, 0); + } + + // Print hp/max hp + for (i = 0; i < count; i++) { + s32 y; + s32 id = a0->unk4[i]; + if (id >= 0) { + Entity *teamMon = gDungeon->teamPokemon[id]; + if (EntityExists(teamMon)) + { + EntityInfo *monInfo = teamMon->info; + s32 color = (a0->unk14[i] != 0) ? 6 : 2; + + sub_8070968(gAvailablePokemonNames, monInfo, color); + if (sub_806A538(gRecruitedPokemonRef->pokemon2[monInfo->teamIndex].unkA)) { + if (monInfo->HP <= monInfo->maxHPStat / 4) { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BB4); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 2) { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BB8); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 3) { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BBC); + } + else { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BC0); + } + } + else { + if (monInfo->HP <= monInfo->maxHPStat / 4) { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BC4); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 2) { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BC8); + } + else if (monInfo->HP <= (monInfo->maxHPStat / 4) * 3) { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BCC); + } + else { + strcpy(gAvailablePokemonNames + 0x50, gUnknown_8106BD0); + } + } + + gFormatData_202DE30[0] = monInfo->HP; + gFormatData_202DE30[1] = monInfo->maxHPStat; + y = sub_8013800(&gUnknown_202EE10, i); + if (monInfo->isTeamLeader) { + xxx_format_and_draw(9, y, gUnknown_8106BD4, 0, 0); + } + else { + xxx_format_and_draw(9, y, gUnknown_8106BE0, 0, 0); + } + } + } + } + + sub_80073E0(0); +} + +extern bool8 CanLeaderSwitch(u8 dungeon); + +void sub_806145C(struct UnkFieldTeamMenuStruct *a0) +{ + Entity *teamMon; + EntityInfo *monInfo; + + gUnknown_202EE6C = 0; + teamMon = gDungeon->teamPokemon[a0->unk4[gUnknown_202EE10.menuIndex]]; + monInfo = teamMon->info; + sub_8044F5C(0x1B, 0); + sub_8044F5C(0x19, 0); + if (!monInfo->isTeamLeader) { + if (!gDungeon->unk65D && (monInfo->joinedAt.joinedAt != DUNGEON_JOIN_LOCATION_PARTNER || gDungeon->unk65C)) { + sub_8044F5C(0x34, 0); + } + sub_8044F5C(0x1C, 0); + } + sub_8044F5C(0x30, 0); + if (!monInfo->isTeamLeader) { + sub_8044F5C(0x1A, 0); + // Why checking teamLeader again? + if (!monInfo->isTeamLeader && gDungeon->unk65C && CanLeaderSwitch(gDungeon->dungeonLocation.id)) { + bool32 r5; + + sub_8044F5C(0x3B, 0); + r5 = TRUE; + if (monInfo->teamIndex >= MAX_TEAM_MEMBERS) { + r5 = FALSE; + } + else { + PokemonStruct2 *mon = &gRecruitedPokemonRef->pokemon2[monInfo->teamIndex]; + if (sub_806A538(mon->unkA)) { + r5 = FALSE; + } + } + + if (CannotMove(teamMon, FALSE)) { + r5 = FALSE; + } + if (!r5) { + sub_8044FF0(0x3B); + } + } + } + + if (IsClientOrTeamBase(monInfo->joinedAt.joinedAt)) { + sub_8044FF0(0x19); + sub_8044FF0(0x3B); + sub_8044FF0(0x1A); + sub_8044FF0(0x30); + sub_8044FF0(0x34); + } + + sub_8045064(); +} + +void sub_80615B4(ActionContainer *a0, struct UnkFieldTeamMenuStruct *a1) +{ + SetMonsterActionFields(a0, gUnknown_202EE44[gUnknown_202EE10.menuIndex].unk0); + a0->unk4[0].actionUseIndex = a1->unk4[a1->unk0]; +} + +void sub_806195C(s32 a0, void *a1, EntityInfo *a3, s32 a4); +void sub_80623B0(void); +void sub_8062D68(void); +void sub_8062230(void); +void sub_8062748(u8 a0); + +extern void (*gUnknown_203B080)(s32 a0); +extern void (*gUnknown_203B084)(s32 a0); + +static inline void SetTxtStruct(UnkTextStruct3 *sp) +{ + memset(sp, 0, sizeof(*sp)); + sp->a0[0].unk4 = 6; + sp->a0[0].unk8.unk0.separate.unk0 = 2; + sp->a0[0].unk8.unk0.separate.unk2 = 2; + sp->a0[0].unkC = 0x12; + sp->a0[0].unkE = 0xE; + sp->a0[0].unk10 = 0x12; + sp->a0[0].unk12 = 2; + sp->a0[0].unk14 = &gUnknown_202F270; + sp->a0[1].unk4 = 3; + sp->a0[2].unk4 = 3; + sp->a0[3].unk4 = 3; +} + +void sub_80615E8(ActionContainer *a0) +{ + UnkTextStruct3 sp; + EntityInfo *monInfo; + u8 var_3C[9]; + s32 var_30; + s32 var_2C; + Entity *teamMon; + + SetTxtStruct(&sp); + teamMon = gDungeon->teamPokemon[a0->unk4[0].actionUseIndex]; + monInfo = teamMon->info; + var_2C = 0; + var_30 = 0; + while (1) { + s32 i; + bool32 addCursor = 1; + bool32 loopBreak = FALSE; + + gUnknown_202F270.f0 = 1; + gUnknown_202F270.f1 = 0; + gUnknown_202F270.f2 = 10; + gUnknown_202F270.f3 = 0; + sub_803ECB4(&sp, 1); + sub_806195C(var_30, var_3C, monInfo, 0); + for (i = 0; i < 8; i++) { + if (var_3C[i] == 11) + break; + } + gUnknown_202EE10.unk1A = i; + gUnknown_202EE10.unk1C = 8; + gUnknown_202EE10.unk1E = 0; + gUnknown_202EE10.unk20 = 0; + gUnknown_202EE10.unk4 = 0; + gUnknown_202EE10.unk6 = 16; + gUnknown_202EE10.unkC = 0; + gUnknown_202EE10.unkE = 0; + gUnknown_202EE10.unk14.x = 0; + gUnknown_202EE10.unk0 = 0; + sub_801317C(&gUnknown_202EE10.unk28); + sub_80137B0(&gUnknown_202EE10, 0); + gUnknown_202EE10.menuIndex = var_2C; + while (1) { + s32 i; + + AddMenuCursorSprite(&gUnknown_202EE10); + if (var_3C[8] != 11) { + sub_80623B0(); + } + if (var_30 != 0) { + sub_8062230(); + } + sub_803E46C(0x3D); + if (gRealInputs.repeated & DPAD_DOWN) { + sub_8083CE0(1); + if (gUnknown_202EE10.menuIndex == 7) { + if (var_3C[8] != 11) { + for (i = 0; i < 6; i++) { + gUnknown_203B080(0); + sub_803E46C(0x3D); + } + var_30++; + } + var_2C = 7; + break; + } + sub_80136E0(&gUnknown_202EE10, 0); + } + if (gRealInputs.repeated & DPAD_UP) { + sub_8083CE0(1); + if (gUnknown_202EE10.menuIndex == 0) { + if (var_30 != 0) { + for (i = 0; i < 6; i++) { + gUnknown_203B084(0); + sub_803E46C(0x3D); + } + var_30--; + } + var_2C = 0; + break; + } + sub_8013744(&gUnknown_202EE10, 0); + } + if (gRealInputs.pressed & START_BUTTON) { + s32 var = var_3C[gUnknown_202EE10.menuIndex]; + var_2C = gUnknown_202EE10.menuIndex; + sub_8083D44(); + sub_8062748(var); + loopBreak = FALSE; + break; + } + if ((gRealInputs.pressed & A_BUTTON) || gUnknown_202EE10.unk28.a_button) { + bool32 changed; + + u8 var = var_3C[gUnknown_202EE10.menuIndex]; + var_2C = gUnknown_202EE10.menuIndex; + sub_8062D68(); + sub_8083D08(); + gUnknown_202EE6C = 0; + sub_8044F5C(0x2F, 0); + sub_8044F5C(0xC, 0); + if (CannotMove(teamMon, TRUE)) { + sub_8044FF0(0x2F); + } + sub_805FC30(&sp, 0x16); + while (1) { + changed = FALSE; + AddMenuCursorSprite(&gUnknown_202EE10); + sub_803E46C(0x3D); + if (gRealInputs.repeated & DPAD_DOWN) { + sub_8083CE0(1); + sub_80136E0(&gUnknown_202EE10, 1); + } + if (gRealInputs.repeated & DPAD_UP) { + sub_8083CE0(1); + sub_8013744(&gUnknown_202EE10, 1); + } + if ((gRealInputs.pressed & A_BUTTON) || gUnknown_202EE10.unk28.a_button) { + if (sub_8044F3C(gUnknown_202EE10.menuIndex)) { + changed = TRUE; + break; + } + sub_8083D30(); + } + if ((gRealInputs.pressed & B_BUTTON) || gUnknown_202EE10.unk28.b_button) { + sub_8083D30(); + changed = FALSE; + break; + } + } + if (changed) { + sub_8083D08(); + if (gUnknown_202EE10.menuIndex == 0) { + PlaySoundEffect(0x133); + monInfo->tactic = var; + monInfo->aiTarget.aiObjective = 6; + monInfo->aiTarget.aiTarget = NULL; + monInfo->aiTarget.unkC = 0; + monInfo->aiTarget.aiTargetSpawnGenID = 0; + if (!monInfo->isTeamLeader) { + MoveIfPossible(teamMon, TRUE); + } + } + else { + sub_8062748(var); + addCursor = FALSE; + } + } + loopBreak = FALSE; + break; + } + if ((gRealInputs.pressed & B_BUTTON) || gUnknown_202EE10.unk28.b_button) { + sub_8083D30(); + loopBreak = TRUE; + break; + } + } + + if (addCursor) { + AddMenuCursorSprite(&gUnknown_202EE10); + } + sub_803E46C(0x3D); + if (loopBreak) + break; + } + sub_803EAF0(0, NULL); +} + +//