From 4e3772328815e4b01042239c1079395018fb8f81 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 18 Nov 2018 17:52:22 +0100 Subject: [PATCH] Document Battle Pyramid --- asm/battle_pyramid.s | 1238 ----------------- data/battle_frontier_3.s | 39 - data/event_scripts.s | 4 +- .../scripts.inc | 26 +- .../scripts.inc | 34 +- .../scripts.inc | 6 +- .../scripts.inc | 2 +- data/specials.inc | 2 +- include/battle_pyramid.h | 24 + include/global.h | 3 +- ld_script.txt | 2 +- src/battle_main.c | 7 +- src/battle_pyramid.c | 619 ++++++++- src/battle_script_commands.c | 4 +- src/battle_setup.c | 14 +- src/item.c | 2 +- src/overworld.c | 2 +- src/pokemon.c | 3 +- src/trainer_see.c | 3 +- src/wild_encounter.c | 4 +- 20 files changed, 626 insertions(+), 1412 deletions(-) delete mode 100644 asm/battle_pyramid.s create mode 100644 include/battle_pyramid.h diff --git a/asm/battle_pyramid.s b/asm/battle_pyramid.s deleted file mode 100644 index eb63d0838..000000000 --- a/asm/battle_pyramid.s +++ /dev/null @@ -1,1238 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - - - thumb_func_start sub_81AA1D8 -sub_81AA1D8: @ 81AA1D8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - movs r5, 0 - mov r6, sp - adds r6, 0x1 - add r0, sp, 0x4 - mov r8, r0 - ldr r4, =gSaveBlock2Ptr - ldr r3, =0x00000cb4 - ldr r0, =0x0000ffff - adds r2, r0, 0 -_081AA1F2: - ldr r0, [r4] - lsls r1, r5, 1 - adds r0, r3 - adds r0, r1 - ldrh r1, [r0] - orrs r1, r2 - strh r1, [r0] - adds r5, 0x1 - cmp r5, 0x7 - ble _081AA1F2 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r7, r0, 24 - mov r0, sp - adds r1, r6, 0 - bl sub_81AA33C - movs r0, 0 - str r0, [sp, 0x4] - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r0, 0xC7 - lsls r0, 4 - adds r1, r0 - ldr r2, =0x05000180 - mov r0, r8 - bl CpuSet - movs r5, 0 -_081AA22E: - cmp r5, 0 - bne _081AA254 - ldr r1, =gUnknown_08613650 - lsls r0, r7, 4 - adds r0, r1 - ldrb r0, [r0, 0x3] - b _081AA25C - .pool -_081AA254: - ldr r1, =gUnknown_08613650 - lsls r0, r7, 4 - adds r0, r1 - ldrb r0, [r0, 0x2] -_081AA25C: - cmp r0, 0x4 - bhi _081AA2E4 - lsls r0, 2 - ldr r1, =_081AA274 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081AA274: - .4byte _081AA288 - .4byte _081AA292 - .4byte _081AA2A2 - .4byte _081AA2B0 - .4byte _081AA2CC -_081AA288: - lsls r0, r5, 24 - lsrs r0, 24 - bl sub_81AA398 - b _081AA2E4 -_081AA292: - lsls r0, r5, 24 - lsrs r4, r0, 24 - mov r0, sp - ldrb r1, [r0] - adds r0, r4, 0 - bl sub_81AA4D8 - b _081AA2BE -_081AA2A2: - lsls r0, r5, 24 - lsrs r4, r0, 24 - ldrb r1, [r6] - adds r0, r4, 0 - bl sub_81AA4D8 - b _081AA2BE -_081AA2B0: - lsls r0, r5, 24 - lsrs r4, r0, 24 - mov r0, sp - ldrb r1, [r0] - adds r0, r4, 0 - bl sub_81AA648 -_081AA2BE: - lsls r0, 24 - cmp r0, 0 - beq _081AA2E4 - adds r0, r4, 0 - bl sub_81AA398 - b _081AA2E4 -_081AA2CC: - lsls r0, r5, 24 - lsrs r4, r0, 24 - ldrb r1, [r6] - adds r0, r4, 0 - bl sub_81AA648 - lsls r0, 24 - cmp r0, 0 - beq _081AA2E4 - adds r0, r4, 0 - bl sub_81AA398 -_081AA2E4: - adds r5, 0x1 - cmp r5, 0x1 - ble _081AA22E - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA1D8 - - thumb_func_start sub_81AA2F8 -sub_81AA2F8: @ 81AA2F8 - push {r4,r5,lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r5, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F - ldr r4, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A - movs r2, 0xC8 - lsls r2, 4 - adds r1, r0, r2 - movs r3, 0xC7 - lsls r3, 4 - adds r2, r0, r3 - movs r3, 0x3F -_081AA310: - ldrb r0, [r2, 0x1] - cmp r0, 0x3B - beq _081AA328 - str r5, [r1] - b _081AA32A - .pool -_081AA328: - str r4, [r1] -_081AA32A: - adds r1, 0x18 - adds r2, 0x18 - subs r3, 0x1 - cmp r3, 0 - bge _081AA310 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_81AA2F8 - - thumb_func_start sub_81AA33C -sub_81AA33C: @ 81AA33C - push {r4-r7,lr} - adds r4, r0, 0 - adds r6, r1, 0 - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - ldr r2, =0x00000e28 - adds r0, r1, r2 - ldrh r2, [r0] - movs r3, 0xF - ands r2, r3 - strb r2, [r4] - ldr r7, =0x00000e22 - adds r1, r7 - ldrh r0, [r1] - ands r0, r3 - strb r0, [r6] - cmp r2, r0 - bne _081AA386 - ldr r1, [r5] - ldr r2, =0x00000e28 - adds r0, r1, r2 - ldrh r2, [r0] - adds r3, r2, 0x1 - adds r0, r3, 0 - asrs r0, 4 - lsls r0, 4 - subs r0, r3, r0 - strb r0, [r4] - adds r0, r1, r7 - ldrh r1, [r0] - adds r2, r1, 0 - adds r2, 0xF - adds r0, r2, 0 - asrs r0, 4 - lsls r0, 4 - subs r0, r2, r0 - strb r0, [r6] -_081AA386: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AA33C - - thumb_func_start sub_81AA398 -sub_81AA398: @ 81AA398 - 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] - movs r5, 0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r6, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x8] - bl sub_81AA96C - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e26 - adds r0, r1 - ldrh r4, [r0] - movs r0, 0xF - ands r4, r0 - ldr r0, [sp] - cmp r0, 0 - bne _081AA3F0 - ldr r1, =gUnknown_08613650 - lsls r0, r6, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - mov r10, r0 - movs r1, 0 - str r1, [sp, 0x4] - b _081AA3FE - .pool -_081AA3F0: - ldr r1, =gUnknown_08613650 - lsls r0, r6, 4 - adds r0, r1 - ldrb r1, [r0] - mov r10, r1 - ldrb r0, [r0, 0x1] - str r0, [sp, 0x4] -_081AA3FE: - movs r0, 0 - mov r8, r0 - cmp r8, r10 - bge _081AA4C0 -_081AA406: - movs r1, 0x1 - add r1, r8 - mov r9, r1 - b _081AA42E - .pool -_081AA414: - lsls r2, r4, 24 - lsrs r2, 24 - ldr r3, [sp, 0x4] - add r3, r8 - lsls r3, 24 - lsrs r3, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA4B6 -_081AA42E: - ldr r0, =gBitTable - mov r12, r0 - ldr r6, =gSaveBlock2Ptr - ldr r7, =0x00000e28 - movs r3, 0x2 - lsls r0, r4, 2 - mov r1, r12 - adds r2, r0, r1 -_081AA43E: - movs r0, 0x1 - ands r0, r5 - cmp r0, 0 - beq _081AA464 - ldr r0, [r6] - adds r0, r7 - ldrh r1, [r0] - ldr r0, [r2] - ands r0, r1 - cmp r0, 0 - bne _081AA474 - b _081AA472 - .pool -_081AA464: - ldr r0, [r6] - adds r0, r7 - ldrh r1, [r0] - ldr r0, [r2] - ands r0, r1 - cmp r0, 0 - beq _081AA474 -_081AA472: - orrs r5, r3 -_081AA474: - adds r2, 0x4 - adds r4, 0x1 - cmp r4, 0xF - ble _081AA480 - mov r2, r12 - movs r4, 0 -_081AA480: - ldr r0, [r6] - ldr r1, =0x00000e26 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0xF - ands r1, r0 - cmp r4, r1 - bne _081AA4A6 - movs r1, 0x1 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - beq _081AA4A4 - movs r0, 0x6 - orrs r5, r0 - b _081AA4A6 - .pool -_081AA4A4: - orrs r5, r1 -_081AA4A6: - adds r0, r5, 0 - ands r0, r3 - cmp r0, 0 - beq _081AA43E - movs r0, 0x4 - ands r0, r5 - cmp r0, 0 - beq _081AA414 -_081AA4B6: - movs r0, 0x1 - ands r5, r0 - mov r8, r9 - cmp r8, r10 - blt _081AA406 -_081AA4C0: - ldr r0, [sp, 0x8] - bl Free - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA398 - - thumb_func_start sub_81AA4D8 -sub_81AA4D8: @ 81AA4D8 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x4] - movs r6, 0 - movs r7, 0 - movs r0, 0 - str r0, [sp, 0xC] - bl sub_81AA9E4 - lsls r0, 24 - lsrs r4, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x14] - bl sub_81AA96C - ldr r1, [sp] - cmp r1, 0 - bne _081AA524 - ldr r1, =gUnknown_08613650 - lsls r0, r4, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - str r0, [sp, 0x10] - movs r0, 0 - b _081AA530 - .pool -_081AA524: - ldr r1, =gUnknown_08613650 - lsls r0, r4, 4 - adds r0, r1 - ldrb r2, [r0] - str r2, [sp, 0x10] - ldrb r0, [r0, 0x1] -_081AA530: - movs r3, 0 - str r3, [sp, 0x8] - ldr r1, [sp, 0x10] - asrs r1, 31 - str r1, [sp, 0x18] - ldr r2, [sp, 0x10] - cmp r3, r2 - bge _081AA622 - str r0, [sp, 0x1C] - adds r3, r0, 0 - lsls r3, 24 - mov r9, r3 -_081AA548: - cmp r7, 0 - bne _081AA56E - mov r0, r9 - lsrs r3, r0, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - ldr r2, [sp, 0x4] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA568 - movs r7, 0x1 - b _081AA56E - .pool -_081AA568: - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0xC] -_081AA56E: - movs r0, 0x1 - ands r0, r7 - cmp r0, 0 - beq _081AA600 - ldr r2, =gUnknown_08613F46 - mov r8, r2 - ldr r3, [sp, 0x4] - lsls r4, r3, 2 - adds r0, r6, r4 - add r0, r8 - ldrb r2, [r0] - mov r0, r9 - lsrs r3, r0, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - bl sub_81AA760 - lsls r0, 24 - ldr r1, [sp, 0x1C] - mov r10, r1 - adds r5, r4, 0 - cmp r0, 0 - beq _081AA5E8 - ldr r4, [sp, 0xC] - adds r4, 0x1 - b _081AA5C2 - .pool -_081AA5A8: - adds r0, r6, r5 - adds r0, r2 - ldrb r2, [r0] - mov r0, r10 - lsls r3, r0, 24 - lsrs r3, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA5E0 -_081AA5C2: - adds r6, 0x1 - ldr r0, =gUnknown_08613F46 - adds r1, r6, r5 - adds r1, r0 - ldrb r1, [r1] - adds r2, r0, 0 - cmp r1, 0xFF - beq _081AA5D6 - cmp r6, 0x3 - ble _081AA5D8 -_081AA5D6: - movs r6, 0 -_081AA5D8: - adds r7, 0x2 - asrs r0, r7, 1 - cmp r0, 0x4 - bne _081AA5A8 -_081AA5E0: - str r4, [sp, 0xC] - b _081AA600 - .pool -_081AA5E8: - adds r6, 0x1 - adds r0, r6, r4 - add r0, r8 - ldrb r0, [r0] - cmp r0, 0xFF - beq _081AA5F8 - cmp r6, 0x3 - ble _081AA5FA -_081AA5F8: - movs r6, 0 -_081AA5FA: - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0xC] -_081AA600: - asrs r0, r7, 1 - cmp r0, 0x4 - beq _081AA622 - movs r0, 0x1 - ands r7, r0 - ldr r2, [sp, 0x1C] - adds r2, 0x1 - str r2, [sp, 0x1C] - movs r3, 0x80 - lsls r3, 17 - add r9, r3 - ldr r0, [sp, 0x8] - adds r0, 0x1 - str r0, [sp, 0x8] - ldr r1, [sp, 0x10] - cmp r0, r1 - blt _081AA548 -_081AA622: - movs r1, 0 - ldr r2, [sp, 0x10] - ldr r3, [sp, 0x18] - subs r0, r2, r3 - asrs r0, 1 - ldr r2, [sp, 0xC] - cmp r0, r2 - ble _081AA634 - movs r1, 0x1 -_081AA634: - adds r0, r1, 0 - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA4D8 - - thumb_func_start sub_81AA648 -sub_81AA648: @ 81AA648 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r6, r1, 24 - movs r4, 0 - movs r7, 0 - movs r0, 0 - mov r8, r0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r5, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x8] - bl sub_81AA96C - ldr r1, [sp] - cmp r1, 0 - bne _081AA694 - ldr r1, =gUnknown_08613650 - lsls r0, r5, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - mov r10, r0 - movs r0, 0 - b _081AA6A0 - .pool -_081AA694: - ldr r1, =gUnknown_08613650 - lsls r0, r5, 4 - adds r0, r1 - ldrb r2, [r0] - mov r10, r2 - ldrb r0, [r0, 0x1] -_081AA6A0: - movs r3, 0 - str r3, [sp, 0x4] - mov r1, r10 - asrs r1, 31 - str r1, [sp, 0xC] - cmp r3, r10 - bge _081AA73E - ldr r2, =gUnknown_08613F46 - mov r9, r2 - lsls r5, r6, 2 - lsls r6, r0, 24 -_081AA6B6: - adds r0, r4, r5 - add r0, r9 - ldrb r2, [r0] - lsrs r3, r6, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA714 - adds r7, 0x1 - b _081AA6EE - .pool -_081AA6D8: - adds r0, r4, r5 - adds r0, r1 - ldrb r2, [r0] - lsrs r3, r6, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA728 -_081AA6EE: - adds r4, 0x1 - adds r0, r4, r5 - add r0, r9 - ldrb r0, [r0] - ldr r1, =gUnknown_08613F46 - cmp r0, 0xFF - beq _081AA700 - cmp r4, 0x3 - ble _081AA702 -_081AA700: - movs r4, 0 -_081AA702: - movs r3, 0x1 - add r8, r3 - mov r0, r8 - cmp r0, 0x4 - bne _081AA6D8 - b _081AA728 - .pool -_081AA714: - adds r4, 0x1 - adds r0, r4, r5 - add r0, r9 - ldrb r0, [r0] - cmp r0, 0xFF - beq _081AA724 - cmp r4, 0x3 - ble _081AA726 -_081AA724: - movs r4, 0 -_081AA726: - adds r7, 0x1 -_081AA728: - mov r1, r8 - cmp r1, 0x4 - beq _081AA73E - movs r2, 0x80 - lsls r2, 17 - adds r6, r2 - ldr r3, [sp, 0x4] - adds r3, 0x1 - str r3, [sp, 0x4] - cmp r3, r10 - blt _081AA6B6 -_081AA73E: - movs r1, 0 - mov r2, r10 - ldr r3, [sp, 0xC] - subs r0, r2, r3 - asrs r0, 1 - cmp r0, r7 - ble _081AA74E - movs r1, 0x1 -_081AA74E: - adds r0, r1, 0 - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA648 - - thumb_func_start sub_81AA760 -sub_81AA760: @ 81AA760 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - mov r10, r1 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r3, 24 - lsrs r7, r3, 24 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e22 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081AA7D0 - movs r6, 0x7 -_081AA792: - movs r4, 0x7 - lsls r5, r6, 24 -_081AA796: - lsls r1, r4, 24 - lsrs r1, 24 - mov r0, r8 - str r0, [sp] - str r7, [sp, 0x4] - mov r0, r9 - lsrs r2, r5, 24 - mov r3, r10 - bl sub_81AA810 - lsls r0, 24 - cmp r0, 0 - beq _081AA7CC - subs r4, 0x1 - cmp r4, 0 - bge _081AA796 - subs r6, 0x1 - movs r1, 0x1 - negs r1, r1 - cmp r6, r1 - bgt _081AA792 - b _081AA7FC - .pool -_081AA7CC: - movs r0, 0 - b _081AA7FE -_081AA7D0: - movs r6, 0 -_081AA7D2: - movs r4, 0 - lsls r5, r6, 24 -_081AA7D6: - lsls r1, r4, 24 - lsrs r1, 24 - mov r0, r8 - str r0, [sp] - str r7, [sp, 0x4] - mov r0, r9 - lsrs r2, r5, 24 - mov r3, r10 - bl sub_81AA810 - lsls r0, 24 - cmp r0, 0 - beq _081AA7CC - adds r4, 0x1 - cmp r4, 0x7 - ble _081AA7D6 - adds r6, 0x1 - cmp r6, 0x7 - ble _081AA7D2 -_081AA7FC: - movs r0, 0x1 -_081AA7FE: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA760 - - thumb_func_start sub_81AA810 -sub_81AA810: @ 81AA810 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - ldr r4, [sp, 0x34] - ldr r5, [sp, 0x38] - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x4] - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r4, 24 - lsrs r4, 24 - mov r10, r4 - lsls r5, 24 - lsrs r6, r5, 24 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r1, r0, r1 - str r1, [sp, 0x8] - add r3, r10 - ldrb r1, [r3] - adds r1, 0x2C - movs r0, 0x19 - bl Overworld_GetMapHeaderByGroupAndId - adds r5, r0, 0 - movs r7, 0 - ldr r1, [r5, 0x4] - ldrb r2, [r1] - cmp r7, r2 - bge _081AA95A - movs r0, 0x3 - ands r0, r4 - lsls r0, 3 - str r0, [sp, 0xC] -_081AA868: - ldr r1, [r1, 0x4] - lsls r2, r7, 1 - adds r0, r2, r7 - lsls r0, 3 - adds r3, r0, r1 - movs r4, 0x4 - ldrsh r0, [r3, r4] - ldr r1, [r5, 0x4] - mov r12, r1 - mov r9, r2 - ldr r2, [sp, 0x4] - cmp r0, r2 - bne _081AA950 - movs r4, 0x6 - ldrsh r0, [r3, r4] - cmp r0, r8 - bne _081AA950 - ldr r0, [sp] - cmp r0, 0 - bne _081AA896 - ldrb r0, [r3, 0x1] - cmp r0, 0x3B - bne _081AA8A2 -_081AA896: - ldr r1, [sp] - cmp r1, 0x1 - bne _081AA950 - ldrb r0, [r3, 0x1] - cmp r0, 0x3B - bne _081AA950 -_081AA8A2: - movs r3, 0 - ldr r2, [r5, 0x4] - mov r12, r2 - cmp r3, r6 - bge _081AA8DC - ldr r4, [sp, 0x4] - ldr r0, [sp, 0xC] - adds r4, r0 - str r4, [sp, 0x10] - mov r1, r10 - lsrs r0, r1, 2 - lsls r0, 3 - mov r2, r8 - adds r1, r2, r0 - ldr r2, [sp, 0x8] - adds r2, 0x4 -_081AA8C2: - movs r4, 0 - ldrsh r0, [r2, r4] - ldr r4, [sp, 0x10] - cmp r0, r4 - bne _081AA8D4 - movs r4, 0x2 - ldrsh r0, [r2, r4] - cmp r0, r1 - beq _081AA8DC -_081AA8D4: - adds r2, 0x18 - adds r3, 0x1 - cmp r3, r6 - blt _081AA8C2 -_081AA8DC: - cmp r3, r6 - bne _081AA950 - lsls r0, r6, 1 - mov r8, r0 - adds r0, r6 - lsls r0, 3 - ldr r1, [sp, 0x8] - adds r5, r0, r1 - mov r3, r12 - ldr r2, [r3, 0x4] - mov r4, r9 - adds r1, r4, r7 - lsls r1, 3 - adds r0, r5, 0 - adds r1, r2 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - ldrh r0, [r5, 0x4] - ldr r1, [sp, 0xC] - adds r0, r1 - strh r0, [r5, 0x4] - mov r2, r10 - lsrs r0, r2, 2 - lsls r0, 3 - ldrh r3, [r5, 0x6] - adds r0, r3 - strh r0, [r5, 0x6] - adds r0, r6, 0x1 - strb r0, [r5] - ldrb r0, [r5, 0x1] - cmp r0, 0x3B - beq _081AA940 - adds r0, r6, 0 - bl sub_81A9F90 - lsls r0, 16 - lsrs r7, r0, 16 - adds r4, r7, 0 - adds r0, r4, 0 - bl GetBattleFacilityTrainerGfxId - strb r0, [r5, 0x1] - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cb4 - adds r0, r1 - add r0, r8 - strh r4, [r0] -_081AA940: - movs r0, 0 - b _081AA95C - .pool -_081AA950: - adds r7, 0x1 - mov r1, r12 - ldrb r2, [r1] - cmp r7, r2 - blt _081AA868 -_081AA95A: - movs r0, 0x1 -_081AA95C: - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA810 - - thumb_func_start sub_81AA96C -sub_81AA96C: @ 81AA96C - push {r4-r7,lr} - adds r6, r0, 0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000e22 - adds r1, r0, r2 - ldrh r4, [r1] - ldr r1, =0x00000e24 - adds r0, r1 - ldrh r0, [r0] - lsls r0, 16 - orrs r4, r0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r5, r0, 24 - movs r3, 0 - ldr r2, =gUnknown_08613650+0x5 - mov r12, r2 - movs r7, 0x7 -_081AA994: - adds r2, r6, r3 - adds r0, r4, 0 - ands r0, r7 - lsls r1, r5, 4 - adds r0, r1 - add r0, r12 - ldrb r0, [r0] - strb r0, [r2] - asrs r4, 3 - cmp r3, 0x7 - bne _081AA9C0 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000e26 - adds r0, r1, r2 - ldrh r4, [r0] - ldr r0, =0x00000e28 - adds r1, r0 - ldrh r0, [r1] - lsls r0, 16 - orrs r4, r0 - asrs r4, 8 -_081AA9C0: - adds r3, 0x1 - cmp r3, 0xF - ble _081AA994 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AA96C - - thumb_func_start sub_81AA9E4 -sub_81AA9E4: @ 81AA9E4 - push {r4,lr} - ldr r0, =gSaveBlock2Ptr - ldr r4, [r0] - ldr r1, =0x00000e28 - adds r0, r4, r1 - ldrh r0, [r0] - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r3, r0, 16 - ldr r0, =0x00000cb2 - adds r4, r0 - ldrh r0, [r4] - ldr r1, =gUnknown_08613794 - adds r0, r1 - ldrb r2, [r0] - cmp r2, 0x21 - bhi _081AAA38 - ldr r1, =gUnknown_08613750 - lsls r0, r2, 1 - adds r0, r1 -_081AAA10: - ldrb r1, [r0] - cmp r3, r1 - bge _081AAA30 - ldrb r0, [r0, 0x1] - b _081AAA3A - .pool -_081AAA30: - adds r0, 0x2 - adds r2, 0x1 - cmp r2, 0x21 - bls _081AAA10 -_081AAA38: - movs r0, 0 -_081AAA3A: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81AA9E4 - - thumb_func_start sub_81AAA40 -sub_81AAA40: @ 81AAA40 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r2, r0, r1 - movs r1, 0 - movs r3, 0xC7 - lsls r3, 4 - adds r0, r3 - b _081AAA6E - .pool -_081AAA5C: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0xF - bhi _081AAA74 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r0, r2 -_081AAA6E: - ldrb r0, [r0] - cmp r0, 0 - bne _081AAA5C -_081AAA74: - adds r0, r1, 0 - pop {r1} - bx r1 - thumb_func_end sub_81AAA40 - - thumb_func_start sub_81AAA7C -sub_81AAA7C: @ 81AAA7C - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r0, 24 - movs r3, 0 - ldr r1, =gSaveBlock2Ptr - mov r8, r1 - lsls r1, r0, 2 - adds r1, r0 - movs r0, 0 - mov r12, r0 - lsls r4, r1, 1 - ldr r7, =0x00000e2c - movs r6, 0 - ldr r5, =0x00000e54 - lsls r2, r1, 2 -_081AAA9E: - mov r1, r8 - ldr r0, [r1] - adds r1, r0, r7 - adds r1, r2 - strh r6, [r1] - adds r1, r3, r4 - adds r0, r5 - adds r0, r1 - mov r1, r12 - strb r1, [r0] - adds r2, 0x2 - adds r3, 0x1 - cmp r3, 0x9 - ble _081AAA9E - movs r0, 0x15 - movs r1, 0x1 - bl AddPyramidBagItem - movs r0, 0x22 - movs r1, 0x1 - bl AddPyramidBagItem - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AAA7C - - thumb_func_start GetBattlePyramidPickupItemId -GetBattlePyramidPickupItemId: @ 81AAAE0 - push {r4-r6,lr} - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r6, r0, 30 - lsls r0, r6, 1 - ldr r2, =0x00000e1a - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x13 - ble _081AAB0A - movs r4, 0x13 -_081AAB0A: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r2, r0, 16 - movs r1, 0 - ldr r3, =gUnknown_08613F86 - ldrb r0, [r3] - lsls r5, r4, 2 - cmp r0, r2 - bgt _081AAB36 -_081AAB28: - adds r1, 0x1 - cmp r1, 0x9 - bhi _081AAB3A - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - ble _081AAB28 -_081AAB36: - cmp r1, 0x9 - bls _081AAB3C -_081AAB3A: - movs r1, 0x9 -_081AAB3C: - cmp r6, 0 - bne _081AAB58 - ldr r2, =sPickupItemsLvl50 - b _081AAB5A - .pool -_081AAB58: - ldr r2, =sPickupItemsLvlOpen -_081AAB5A: - lsls r1, 1 - adds r0, r5, r4 - lsls r0, 2 - adds r1, r0 - adds r1, r2 - ldrh r0, [r1] - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end GetBattlePyramidPickupItemId - - .align 2, 0 @ Don't pad with nop. diff --git a/data/battle_frontier_3.s b/data/battle_frontier_3.s index bcf043576..fc5a45e37 100644 --- a/data/battle_frontier_3.s +++ b/data/battle_frontier_3.s @@ -506,42 +506,3 @@ gUnknown_08613EC0:: @ 8613EC0 .4byte gUnknown_08613E9C .4byte gUnknown_08613EA8 .4byte gUnknown_08613EB4 - -gUnknown_08613ED8:: @ 8613ED8 - .byte 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x03, 0x04 - - .align 2 -gUnknown_08613EE0:: @ 8613EE0 - .4byte sub_81A8E9C - .4byte sub_81A8F38 - .4byte sub_81A9048 - .4byte sub_81A9134 - .4byte sub_81A917C - .4byte sub_81A91FC - .4byte sub_81A9254 - .4byte sub_81A9290 - .4byte sub_81A93C8 - .4byte sub_81A9414 - .4byte sub_81A9424 - .4byte sub_81A9618 - .4byte sub_81A966C - .4byte sub_81A9684 - .4byte sub_81A975C - .4byte sub_81A97C8 - .4byte sub_81A9828 - .4byte sub_81A9834 - - .align 1 -gUnknown_08613F28:: @ 8613F28 - .2byte 0x003f, 0x0040, 0x0041, 0x0043, 0x0042, 0x0046 - - .align 2 -gUnknown_08613F34:: @ 8613F34 - .2byte 0x00b3, 0x00b4, 0x00b7, 0x00c8, 0x00b9, 0x00bb, 0x00c4, 0x00c6, 0x00ba - -gUnknown_08613F46:: @ 8613F46 - .byte 0x01, 0x04, 0xff, 0xff, 0x00, 0x02, 0x05, 0xff, 0x01, 0x03, 0x06, 0xff, 0x02, 0x07, 0xff, 0xff, 0x00, 0x05, 0x08, 0xff, 0x01, 0x04, 0x06, 0x09, 0x02, 0x05, 0x07, 0x0a, 0x03, 0x06, 0x0b, 0xff - .byte 0x04, 0x09, 0x0c, 0xff, 0x05, 0x08, 0x0a, 0x0d, 0x06, 0x09, 0x0b, 0x0e, 0x07, 0x0a, 0x0f, 0xff, 0x08, 0x0d, 0xff, 0xff, 0x09, 0x0c, 0x0e, 0xff, 0x0a, 0x0d, 0x0f, 0xff, 0x0b, 0x0e, 0xff, 0xff - -gUnknown_08613F86:: @ 8613F86 - .byte 0x1e, 0x28, 0x32, 0x3c, 0x46, 0x50, 0x55, 0x5a, 0x5f, 0x64 diff --git a/data/event_scripts.s b/data/event_scripts.s index e52b95f24..115c9921a 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -1662,7 +1662,7 @@ EventScript_271C3A:: @ 8271C3A waitmessage bufferitemnameplural 1, VAR_0x8004, 32773 setvar VAR_0x8004, 12 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 1 goto_eq EventScript_271C86 msgbox gUnknown_08272A9A, 4 @@ -3361,7 +3361,7 @@ EventScript_2736F8:: @ 82736F8 compare VAR_RESULT, 1 goto_eq BattleFrontier_BattlePikeThreePathRoom_EventScript_2C4222 setvar VAR_0x8004, 12 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 1 goto_eq BattleFrontier_BattlePyramidTop_EventScript_252B42 compare VAR_RESULT, 2 diff --git a/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc b/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc index 6225ae0cc..facd60979 100644 --- a/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc @@ -19,7 +19,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252A5D:: @ 8252A5D setvar VAR_RESULT, 0 BattleFrontier_BattlePyramidEmptySquare_EventScript_252A77:: @ 8252A77 - special sub_81A8E7C + special CallBattlePyramidFunction delay 2 compare VAR_RESULT, 2 goto_if 5, BattleFrontier_BattlePyramidEmptySquare_EventScript_252A77 @@ -39,7 +39,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252A98:: @ 8252A98 BattleFrontier_BattlePyramidEmptySquare_MapScript1_252AA2: @ 8252AA2 setvar VAR_0x8004, 15 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 0 special CallFrontierUtilFunc switch VAR_TEMP_0 @@ -68,7 +68,7 @@ BattleFrontier_BattlePyramidEmptySquare_MapScript1_252AA2: @ 8252AA2 BattleFrontier_BattlePyramidEmptySquare_EventScript_252B39:: @ 8252B39 setvar VAR_0x8004, 17 - special sub_81A8E7C + special CallBattlePyramidFunction end BattleFrontier_BattlePyramidEmptySquare_EventScript_252B42:: @ 8252B42 @@ -80,16 +80,16 @@ BattleFrontier_BattlePyramidTop_EventScript_252B42:: @ 8252B42 setvar VAR_0x8004, 2 setvar VAR_0x8005, 7 setvar VAR_0x8006, 255 - special sub_81A8E7C + special CallBattlePyramidFunction BattleFrontier_BattlePyramidEmptySquare_EventScript_252B66:: @ 8252B66 BattleFrontier_BattlePyramidTop_EventScript_252B66:: @ 8252B66 setvar VAR_0x8004, 13 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 14 - special sub_81A8E7C + special CallBattlePyramidFunction special HealPlayerParty warpsilent MAP_BATTLE_FRONTIER_BATTLE_PYRAMID_LOBBY, 255, 7, 13 waitstate @@ -98,14 +98,14 @@ BattleFrontier_BattlePyramidTop_EventScript_252B66:: @ 8252B66 BattleFrontier_BattlePyramidEmptySquare_EventScript_252B8D:: @ 8252B8D setvar VAR_0x8004, 3 setvar VAR_0x8005, 1 - special sub_81A8E7C + special CallBattlePyramidFunction special SavePlayerParty setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 special CallFrontierUtilFunc setvar VAR_0x8004, 9 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 3 special CallFrontierUtilFunc @@ -121,7 +121,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252BD5:: @ 8252BD5 setvar VAR_0x8004, 13 setvar VAR_0x8005, 32 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction return BattleFrontier_BattlePyramidEmptySquare_EventScript_252BE8:: @ 8252BE8 @@ -137,7 +137,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252BE8:: @ 8252BE8 compare VAR_RESULT, 7 goto_eq BattleFrontier_BattlePyramidEmptySquare_EventScript_252C45 setvar VAR_0x8004, 6 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 @@ -155,7 +155,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252C45:: @ 8252C45 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F:: @ 8252C4F trainerbattle 9, TRAINER_PHILLIP, 0, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D setvar VAR_0x8004, 10 - special sub_81A8E7C + special CallBattlePyramidFunction waitmessage waitbuttonpress closemessage @@ -164,12 +164,12 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F:: @ 8252C4F BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A:: @ 8252C6A setvar VAR_0x8004, 7 - special sub_81A8E7C + special CallBattlePyramidFunction callstd 1 compare VAR_0x8007, 0 goto_eq BattleFrontier_BattlePyramidEmptySquare_EventScript_252C87 setvar VAR_0x8004, 8 - special sub_81A8E7C + special CallBattlePyramidFunction BattleFrontier_BattlePyramidEmptySquare_EventScript_252C87:: @ 8252C87 end diff --git a/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc b/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc index 4ae7b8e55..bcd2e32c9 100644 --- a/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc @@ -35,11 +35,11 @@ BattleFrontier_BattlePyramidLobby_EventScript_250768:: @ 8250768 setvar VAR_0x8004, 2 setvar VAR_0x8005, 1 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 2 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 @@ -69,7 +69,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_2507DA:: @ 82507DA special CallFrontierUtilFunc special LoadPlayerParty setvar VAR_0x8004, 14 - special sub_81A8E7C + special CallBattlePyramidFunction special HealPlayerParty message BattleFrontier_BattlePyramidLobby_Text_2519F8 waitmessage @@ -82,10 +82,10 @@ BattleFrontier_BattlePyramidLobby_EventScript_2507DA:: @ 82507DA message BattleFrontier_BattlePyramidLobby_Text_251A77 waitmessage setvar VAR_0x8004, 4 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 0 - special sub_81A8E7C + special CallBattlePyramidFunction playse SE_SAVE waitse msgbox BattleFrontier_BattlePyramidLobby_Text_251BB6, 4 @@ -99,7 +99,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250852:: @ 8250852 special CallFrontierUtilFunc special LoadPlayerParty setvar VAR_0x8004, 14 - special sub_81A8E7C + special CallBattlePyramidFunction special HealPlayerParty lockall message BattleFrontier_BattlePyramidLobby_Text_251B5A @@ -111,10 +111,10 @@ BattleFrontier_BattlePyramidLobby_EventScript_250852:: @ 8250852 setvar VAR_0x8004, 2 setvar VAR_0x8005, 2 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 0 - special sub_81A8E7C + special CallBattlePyramidFunction playse SE_SAVE waitse msgbox BattleFrontier_BattlePyramidLobby_Text_251BB6, 4 @@ -180,11 +180,11 @@ BattleFrontier_BattlePyramidLobby_EventScript_2509A5:: @ 82509A5 setvar VAR_0x8005, 4 special CallFrontierUtilFunc setvar VAR_0x8004, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 2 setvar VAR_0x8006, 1 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 1 @@ -194,9 +194,9 @@ BattleFrontier_BattlePyramidLobby_EventScript_2509A5:: @ 82509A5 setvar VAR_0x8006, 0 special CallFrontierUtilFunc setvar VAR_0x8004, 6 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 9 - special sub_81A8E7C + special CallBattlePyramidFunction special LoadPlayerParty closemessage delay 2 @@ -284,7 +284,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B28:: @ 8250B28 msgbox BattleFrontier_BattlePyramidLobby_Text_251C8A, 4 setvar VAR_0x8004, 1 setvar VAR_0x8005, 5 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 0 goto_if 5, BattleFrontier_BattlePyramidLobby_EventScript_250B53 setvar VAR_RESULT, 0 @@ -294,7 +294,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B28:: @ 8250B28 BattleFrontier_BattlePyramidLobby_EventScript_250B53:: @ 8250B53 setvar VAR_0x8004, 1 setvar VAR_0x8005, 3 - special sub_81A8E7C + special CallBattlePyramidFunction goto BattleFrontier_BattlePyramidLobby_EventScript_250BA4 return @@ -302,7 +302,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B66:: @ 8250B66 msgbox BattleFrontier_BattlePyramidLobby_Text_251C8A, 4 setvar VAR_0x8004, 1 setvar VAR_0x8005, 6 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 0 goto_if 5, BattleFrontier_BattlePyramidLobby_EventScript_250B91 setvar VAR_RESULT, 0 @@ -312,7 +312,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B66:: @ 8250B66 BattleFrontier_BattlePyramidLobby_EventScript_250B91:: @ 8250B91 setvar VAR_0x8004, 1 setvar VAR_0x8005, 4 - special sub_81A8E7C + special CallBattlePyramidFunction goto BattleFrontier_BattlePyramidLobby_EventScript_250BA4 return @@ -439,7 +439,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250D56:: @ 8250D56 msgbox BattleFrontier_BattlePyramidLobby_Text_251569, 4 setvar VAR_0x8004, 1 setvar VAR_0x8005, 1 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 0 goto_eq BattleFrontier_BattlePyramidLobby_EventScript_250D94 msgbox BattleFrontier_BattlePyramidLobby_Text_2515AD, 4 diff --git a/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc b/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc index 46ecef737..e77013519 100644 --- a/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc @@ -9,7 +9,7 @@ BattleFrontier_BattlePyramidTop_MapScript1_2550B6: @ 82550B6 setvar VAR_0x8004, 13 setvar VAR_0x8005, 200 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_TEMP_F, 1 end @@ -71,14 +71,14 @@ BattleFrontier_BattlePyramidTop_EventScript_25518A:: @ 825518A BattleFrontier_BattlePyramidTop_EventScript_255193:: @ 8255193 setvar VAR_0x8004, 3 setvar VAR_0x8005, 1 - special sub_81A8E7C + special CallBattlePyramidFunction special SavePlayerParty setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 special CallFrontierUtilFunc setvar VAR_0x8004, 9 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 3 special CallFrontierUtilFunc diff --git a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc index de179850d..f16b7e6a0 100644 --- a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc @@ -7,7 +7,7 @@ BattleFrontier_BattleTowerMultiBattleRoom_MapScripts:: @ 8243D92 BattleFrontier_BattleTowerMultiBattleRoom_MapScript1_243DA7: @ 8243DA7 setvar VAR_0x8004, 17 - special sub_81A8E7C + special CallBattlePyramidFunction end BattleFrontier_BattleTowerMultiBattleRoom_MapScript1_243DB0: @ 8243DB0 diff --git a/data/specials.inc b/data/specials.inc index 5b2459805..75f180420 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -251,7 +251,7 @@ gSpecials:: @ 81DBA64 def_special CallBattleArenaFunction def_special CallBattleFactoryFunction def_special CallBattlePikeFunction - def_special sub_81A8E7C + def_special CallBattlePyramidFunction def_special StopMapMusic def_special sub_81B99B4 def_special sub_81B9B80 diff --git a/include/battle_pyramid.h b/include/battle_pyramid.h new file mode 100644 index 000000000..5d38e9f35 --- /dev/null +++ b/include/battle_pyramid.h @@ -0,0 +1,24 @@ +#ifndef GUARD_BATTLE_PYRAMID_H +#define GUARD_BATTLE_PYRAMID_H + +void CallBattlePyramidFunction(void); +u16 LocalIdToPyramidTrainerId(u8 localId); +bool8 GetBattlePyramidTrainerFlag(u8 eventId); +void sub_81A9B04(void); +void GenerateBattlePyramidWildMon(void); +u8 GetPyramidRunMultiplier(void); +u8 InBattlePyramid(void); +bool8 InBattlePyramid_(void); +void sub_81A9E90(void); +void sub_81A9EC8(void); +void CopyPyramidTrainerSpeechBefore(u16 trainerId); +void CopyPyramidTrainerWinSpeech(u16 trainerId); +void CopyPyramidTrainerLoseSpeech(u16 trainerId); +u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId); +void sub_81AA078(u16 *mapArg, u8 arg1); +void sub_81AA1D8(void); +void sub_81AA2F8(void); +u8 sub_81AAA40(void); +u16 GetBattlePyramidPickupItemId(void); + +#endif // GUARD_BATTLE_PYRAMID_H diff --git a/include/global.h b/include/global.h index 25e8c7faa..3da68185f 100644 --- a/include/global.h +++ b/include/global.h @@ -135,6 +135,7 @@ enum LanguageId #define BAG_POKEBALLS_COUNT 16 #define BAG_TMHM_COUNT 64 #define BAG_BERRIES_COUNT 46 +#define EVENT_OBJECT_TEMPLATES_COUNT 64 #define PYRAMID_BAG_ITEMS_COUNT 10 #define HALL_FACILITIES_COUNT 9 // 7 facilities for single mode + tower double mode + tower multi mode. @@ -907,7 +908,7 @@ struct SaveBlock1 /*0x9C8*/ u16 trainerRematchStepCounter; /*0x9CA*/ u8 trainerRematches[100]; /*0xA30*/ struct EventObject eventObjects[EVENT_OBJECTS_COUNT]; - /*0xC70*/ struct EventObjectTemplate eventObjectTemplates[64]; + /*0xC70*/ struct EventObjectTemplate eventObjectTemplates[EVENT_OBJECT_TEMPLATES_COUNT]; /*0x1270*/ u8 flags[FLAGS_COUNT]; /*0x139C*/ u16 vars[VARS_COUNT]; /*0x159C*/ u32 gameStats[NUM_GAME_STATS]; diff --git a/ld_script.txt b/ld_script.txt index 9de96ebcc..21fff394d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -270,7 +270,6 @@ SECTIONS { src/battle_pike.o(.text); asm/battle_frontier_2.o(.text); src/battle_pyramid.o(.text); - asm/battle_pyramid.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); src/dynamic_placeholder_text_util.o(.text); @@ -581,6 +580,7 @@ SECTIONS { data/battle_pike.o(.rodata); src/battle_pike.o(.rodata); data/battle_frontier_3.o(.rodata); + src/battle_pyramid.o(.rodata); src/item_menu.o(.rodata); src/list_menu.o(.rodata); src/save_location.o(.rodata); diff --git a/src/battle_main.c b/src/battle_main.c index f6c01aee2..dee2adf0b 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5,6 +5,7 @@ #include "battle_controllers.h" #include "battle_interface.h" #include "battle_message.h" +#include "battle_pyramid.h" #include "battle_scripts.h" #include "battle_setup.h" #include "battle_tower.h" @@ -109,10 +110,8 @@ extern const u8 gText_Love[]; // functions extern void sub_81B9150(void); extern void sub_80B3AF8(u8 taskId); // cable club -extern u8 sub_81A9E28(void); // battle frontier 2 extern void sub_81B8FB0(u8, u8); // party menu extern u8 pokemon_order_func(u8); // party menu -extern bool8 InBattlePyramid(void); // this file's functions static void CB2_InitBattleInternal(void); @@ -5604,7 +5603,7 @@ bool8 TryRunFromBattle(u8 battler) if (InBattlePyramid()) { gBattleStruct->runTries++; - pyramidMultiplier = sub_81A9E28(); + pyramidMultiplier = GetPyramidRunMultiplier(); speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); if (speedVar > (Random() & 0xFF)) { @@ -5630,7 +5629,7 @@ bool8 TryRunFromBattle(u8 battler) { if (InBattlePyramid()) { - pyramidMultiplier = sub_81A9E28(); + pyramidMultiplier = GetPyramidRunMultiplier(); speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); if (speedVar > (Random() & 0xFF)) effect++; diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 1ef59a438..34dd353d0 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -1,4 +1,5 @@ #include "global.h" +#include "battle_pyramid.h" #include "battle_pyramid_bag.h" #include "event_data.h" #include "battle.h" @@ -19,9 +20,12 @@ #include "load_save.h" #include "script.h" #include "malloc.h" +#include "overworld.h" #include "constants/battle_frontier.h" #include "constants/event_objects.h" #include "constants/event_object_movement_constants.h" +#include "constants/items.h" +#include "constants/maps.h" #include "constants/moves.h" extern u8 gUnknown_0203CEF8[3]; @@ -30,6 +34,7 @@ extern void door_upload_tiles(void); extern const struct MapLayout *const gMapLayouts[]; #define TOTAL_ROUNDS 20 +#define PICKUP_ITEMS_PER_ROUND 10 struct Struct_08613650 { @@ -38,47 +43,134 @@ struct Struct_08613650 u8 unk2; u8 unk3; u8 unk4; - u8 unk5; - u8 unk6[10]; + u8 unk5[11]; +}; + +struct PyramidWildMon +{ + u16 species; + u8 lvl; + u8 abilityBit; + u16 moves[4]; +}; + +struct ClassMusic +{ + u8 class; + u8 music; }; extern const u16 gBattleFrontierHeldItems[]; extern const struct FacilityMon gBattleFrontierMons[]; extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A[]; + // This file's functions. -void sub_81AAA7C(u8 lvlMode); -u8 sub_81AA9E4(void); -u16 sub_81A9AA8(u8); -u8 sub_81A9998(s32 *, u8, u8); -u8 sub_81AAA40(void); -u8 InBattlePyramid(void); -void sub_81A97DC(u8 taskId); -void sub_81A9B44(u16 trainerId); -void sub_81AA96C(u8 *); -void sub_81AA33C(u8 *, u8 *); +static void sub_81A8E9C(void); +static void sub_81A8F38(void); +static void sub_81A9048(void); +static void sub_81A9134(void); +static void sub_81A917C(void); +static void sub_81A91FC(void); +static void sub_81A9254(void); +static void sub_81A9290(void); +static void sub_81A93C8(void); +static void sub_81A9414(void); +static void sub_81A9424(void); +static void sub_81A9618(void); +static void sub_81A966C(void); +static void sub_81A9684(void); +static void sub_81A975C(void); +static void sub_81A97C8(void); +static void sub_81A9828(void); +static void sub_81A9834(void); +static void InitBagItems(u8 lvlMode); +static u8 sub_81AA9E4(void); +static u8 sub_81A9998(s32 *, u8, u8); +static void sub_81A97DC(u8 taskId); +static void sub_81A9B44(u16 trainerId); +static void sub_81AA96C(u8 *mapNums); +static void sub_81AA33C(u8 *, u8 *); +static void sub_81AA398(u8); +static bool8 sub_81AA4D8(u8, u8); +static bool8 sub_81AA648(u8, u8); +static bool8 sub_81AA760(u8 arg0, u8 *mapNums, u8 whichMap, u8 id); +static bool8 sub_81AA810(u8 arg0, u8 x, u8 y, u8 *mapNums, u8 whichMap, u8 id); // Const rom data. -extern void (* const gUnknown_08613EE0[])(void); extern const struct Struct_08613650 gUnknown_08613650[]; -extern const u16 sPickupItemsLvl50[TOTAL_ROUNDS][10]; -extern const u16 sPickupItemsLvlOpen[TOTAL_ROUNDS][10]; +extern const u16 sPickupItemsLvl50[TOTAL_ROUNDS][PICKUP_ITEMS_PER_ROUND]; +extern const u16 sPickupItemsLvlOpen[TOTAL_ROUNDS][PICKUP_ITEMS_PER_ROUND]; extern const u8 gUnknown_08613ABC[63][2]; extern const u8 gUnknown_08613B3A[]; -extern const u16 gUnknown_08613F34[9]; -extern const u16 gUnknown_08613F28[6]; extern const u16 gUnknown_08D856C8[][16]; extern const u8 gUnknown_08613C1C[50][2]; -extern const u8 gUnknown_08613ED8[]; extern const u8 *const *const *const gUnknown_08613EC0[]; +extern const struct ClassMusic gUnknown_08613B44[54]; +extern const struct PyramidWildMon *const gBattlePyramidOpenLevelWildMonPointers[]; +extern const struct PyramidWildMon *const gBattlePyramidLevel50WildMonPointers[]; +extern const u8 gUnknown_08613794[]; +extern const u8 gUnknown_08613750[34][2]; + +static const u8 gUnknown_08613ED8[] = {3, 4, 5, 6, 7, 8, 3, 4}; + +static void (* const sBattlePyramidFunctions[])(void) = +{ + sub_81A8E9C, + sub_81A8F38, + sub_81A9048, + sub_81A9134, + sub_81A917C, + sub_81A91FC, + sub_81A9254, + sub_81A9290, + sub_81A93C8, + sub_81A9414, + sub_81A9424, + sub_81A9618, + sub_81A966C, + sub_81A9684, + sub_81A975C, + sub_81A97C8, + sub_81A9828, + sub_81A9834, +}; + +static const u16 gUnknown_08613F28[] = {ITEM_HP_UP, ITEM_PROTEIN, ITEM_IRON, ITEM_CALCIUM, ITEM_CARBOS, ITEM_ZINC}; +static const u16 gUnknown_08613F34[] = {ITEM_BRIGHT_POWDER, ITEM_WHITE_HERB, ITEM_QUICK_CLAW, ITEM_LEFTOVERS, ITEM_MENTAL_HERB, ITEM_KINGS_ROCK, ITEM_FOCUS_BAND, ITEM_SCOPE_LENS, ITEM_CHOICE_BAND}; + +static const u8 gUnknown_08613F46[][4] = +{ + {0x01, 0x04, 0xff, 0xff}, + {0x00, 0x02, 0x05, 0xff}, + {0x01, 0x03, 0x06, 0xff}, + {0x02, 0x07, 0xff, 0xff}, + {0x00, 0x05, 0x08, 0xff}, + {0x01, 0x04, 0x06, 0x09}, + {0x02, 0x05, 0x07, 0x0a}, + {0x03, 0x06, 0x0b, 0xff}, + {0x04, 0x09, 0x0c, 0xff}, + {0x05, 0x08, 0x0a, 0x0d}, + {0x06, 0x09, 0x0b, 0x0e}, + {0x07, 0x0a, 0x0f, 0xff}, + {0x08, 0x0d, 0xff, 0xff}, + {0x09, 0x0c, 0x0e, 0xff}, + {0x0a, 0x0d, 0x0f, 0xff}, + {0x0b, 0x0e, 0xff, 0xff}, +}; + +static const u8 sPickupPercentages[PICKUP_ITEMS_PER_ROUND] = {30, 40, 50, 60, 70, 80, 85, 90, 95, 100}; // code -void sub_81A8E7C(void) +void CallBattlePyramidFunction(void) { - gUnknown_08613EE0[gSpecialVar_0x8004](); + sBattlePyramidFunctions[gSpecialVar_0x8004](); } -void sub_81A8E9C(void) +static void sub_81A8E9C(void) { bool32 isCurrent; u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -94,7 +186,7 @@ void sub_81A8E9C(void) if (!isCurrent) { gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] = 0; - sub_81AAA7C(lvlMode); + InitBagItems(lvlMode); } sub_81C4EEC(); @@ -102,7 +194,7 @@ void sub_81A8E9C(void) gBattleOutcome = 0; } -void sub_81A8F38(void) +static void sub_81A8F38(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -135,7 +227,7 @@ void sub_81A8F38(void) } } -void sub_81A9048(void) +static void sub_81A9048(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -169,7 +261,7 @@ void sub_81A9048(void) } } -void sub_81A9134(void) +static void sub_81A9134(void) { gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; VarSet(VAR_TEMP_0, 0); @@ -178,7 +270,7 @@ void sub_81A9134(void) TrySavingData(SAVE_LINK); } -void sub_81A917C(void) +static void sub_81A917C(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -188,7 +280,7 @@ void sub_81A917C(void) gSaveBlock2Ptr->frontier.field_E18 = gUnknown_08613F28[Random() % ARRAY_COUNT(gUnknown_08613F28)]; } -void sub_81A91FC(void) +static void sub_81A91FC(void) { if (AddBagItem(gSaveBlock2Ptr->frontier.field_E18, 1) == TRUE) { @@ -202,7 +294,7 @@ void sub_81A91FC(void) } } -void sub_81A9254(void) +static void sub_81A9254(void) { s32 i; @@ -212,7 +304,7 @@ void sub_81A9254(void) gSaveBlock2Ptr->frontier.field_E2A = 0; } -void sub_81A9290(void) +static void sub_81A9290(void) { s32 i; s32 r7; @@ -247,7 +339,7 @@ void sub_81A9290(void) gSpecialVar_0x8001 = 1; } -void sub_81A93C8(void) +static void sub_81A93C8(void) { struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; s32 i = 0; @@ -266,12 +358,12 @@ void sub_81A93C8(void) } } -void sub_81A9414(void) +static void sub_81A9414(void) { gFacilityTrainers = gBattleFrontierTrainers; } -void sub_81A9424(void) +static void sub_81A9424(void) { s32 i; s32 var_24; @@ -279,7 +371,7 @@ void sub_81A9424(void) s32 class = 0; s32 r7 = 0; struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; - u16 trainerId = sub_81A9AA8(gEventObjects[gSelectedEventObject].localId); + u16 trainerId = LocalIdToPyramidTrainerId(gEventObjects[gSelectedEventObject].localId); for (i = 0; i < ARRAY_COUNT(gUnknown_08613C1C); i++) { @@ -341,7 +433,7 @@ void sub_81A9424(void) ShowFieldMessage(gUnknown_08613EC0[class][var_24][r7]); } -void sub_81A9618(void) +static void sub_81A9618(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -351,12 +443,12 @@ void sub_81A9618(void) gSaveBlock2Ptr->frontier.pyramidRecordStreaks[lvlMode] = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]; } -void sub_81A966C(void) +static void sub_81A966C(void) { gSpecialVar_Result = InBattlePyramid(); } -void sub_81A9684(void) +static void sub_81A9684(void) { switch (gSpecialVar_0x8006) { @@ -401,7 +493,7 @@ void sub_81A9684(void) } } -void sub_81A975C(void) +static void sub_81A975C(void) { s32 i, j; u16 item = 0; @@ -416,12 +508,12 @@ void sub_81A975C(void) } } -void sub_81A97C8(void) +static void sub_81A97C8(void) { CreateTask(sub_81A97DC, 0); } -void sub_81A97DC(u8 taskId) +static void sub_81A97DC(u8 taskId) { if (gPaletteFade.active) { @@ -430,12 +522,12 @@ void sub_81A97DC(u8 taskId) } } -void sub_81A9828(void) +static void sub_81A9828(void) { sub_809FDD4(); } -void sub_81A9834(void) +static void sub_81A9834(void) { s32 i, j, k, l; @@ -467,7 +559,7 @@ void sub_81A9834(void) gSaveBlock2Ptr->frontier.selectedPartyMons[i] = gUnknown_0203CEF8[i]; } -u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) +static u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) { s32 i, j; u8 ret = 0; @@ -537,9 +629,9 @@ u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) return ret; } -u16 sub_81A9AA8(u8 arg0) +u16 LocalIdToPyramidTrainerId(u8 localId) { - return gSaveBlock2Ptr->frontier.field_CB4[arg0 - 1]; + return gSaveBlock2Ptr->frontier.field_CB4[localId - 1]; } bool8 GetBattlePyramidTrainerFlag(u8 eventId) @@ -557,18 +649,7 @@ void sub_81A9B04(void) } } -struct PyramidWildMon -{ - u16 species; - u8 lvl; - u8 abilityBit; - u16 moves[4]; -}; - -extern const struct PyramidWildMon *const gBattlePyramidOpenLevelWildMonPointers[]; -extern const struct PyramidWildMon *const gBattlePyramidLevel50WildMonPointers[]; - -void sub_81A9B44(u16 trainerId) +static void sub_81A9B44(u16 trainerId) { s32 i; @@ -652,7 +733,7 @@ void GenerateBattlePyramidWildMon(void) CalculateMonStats(&gEnemyParty[0]); } -u8 sub_81A9E28(void) +u8 GetPyramidRunMultiplier(void) { u8 id = sub_81AA9E4(); return gUnknown_08613650[id].unk4; @@ -690,30 +771,21 @@ void sub_81A9EC8(void) DoSoftReset(); } -void sub_81A9EDC(u16 trainerId) +void CopyPyramidTrainerSpeechBefore(u16 trainerId) { FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore); } -void sub_81A9EFC(u16 trainerId) +void CopyPyramidTrainerWinSpeech(u16 trainerId) { FrontierSpeechToString(gFacilityTrainers[trainerId].speechWin); } -void sub_81A9F1C(u16 trainerId) +void CopyPyramidTrainerLoseSpeech(u16 trainerId) { FrontierSpeechToString(gFacilityTrainers[trainerId].speechLose); } -struct ClassMusic -{ - u8 class; - u8 music; -}; - -extern const struct ClassMusic gUnknown_08613B44[54]; -extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88[]; - u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId) { s32 i; @@ -726,12 +798,12 @@ u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId) return 0; } -void sub_81A9F80(void) +static void sub_81A9F80(void) { ScriptContext1_SetupScript(BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88); } -u16 sub_81A9F90(u8 count) +static u16 sub_81A9F90(u8 count) { s32 i; u16 trainerId; @@ -818,3 +890,408 @@ void sub_81AA078(u16 *mapArg, u8 arg1) mapheader_run_script_with_tag_x1(); free(allocated); } + +void sub_81AA1D8(void) +{ + s32 i; + u8 id; + u8 var0, var1; + + for (i = 0; i < 8; i++) + gSaveBlock2Ptr->frontier.field_CB4[i] |= 0xFFFF; + + id = sub_81AA9E4(); + sub_81AA33C(&var0, &var1); + CpuFill32(0, gSaveBlock1Ptr->eventObjectTemplates, sizeof(gSaveBlock1Ptr->eventObjectTemplates)); + for (i = 0; i < 2; i++) + { + u8 value; + + if (i == 0) + value = gUnknown_08613650[id].unk3; + else + value = gUnknown_08613650[id].unk2; + + switch (value) + { + case 0: + sub_81AA398(i); + break; + case 1: + if (sub_81AA4D8(i, var0)) + sub_81AA398(i); + break; + case 2: + if (sub_81AA4D8(i, var1)) + sub_81AA398(i); + break; + case 3: + if (sub_81AA648(i, var0)) + sub_81AA398(i); + break; + case 4: + if (sub_81AA648(i, var1)) + sub_81AA398(i); + break; + } + } +} + +void sub_81AA2F8(void) +{ + s32 i; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++) + { + if (events[i].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + events[i].script = BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F; + else + events[i].script = BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A; + } +} + +static void sub_81AA33C(u8 *var0, u8 *var1) +{ + *var0 = gSaveBlock2Ptr->frontier.field_E22[3] % 16; + *var1 = gSaveBlock2Ptr->frontier.field_E22[0] % 16; + + if (*var0 == *var1) + { + *var0 = (gSaveBlock2Ptr->frontier.field_E22[3] + 1 ) % 16; + *var1 = (gSaveBlock2Ptr->frontier.field_E22[0] + 15) % 16; + } +} + +static void sub_81AA398(u8 arg0) +{ + s32 i; + s32 count; + s32 var_28; + s32 r4; + u32 bits = 0; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + r4 = gSaveBlock2Ptr->frontier.field_E22[2] % 16; + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + do + { + do + { + if (bits & 1) + { + if (!(gBitTable[r4] & gSaveBlock2Ptr->frontier.field_E22[3])) + bits |= 2; + } + else + { + if (gBitTable[r4] & gSaveBlock2Ptr->frontier.field_E22[3]) + bits |= 2; + } + if (++r4 >= 16) + r4 = 0; + + if (r4 == gSaveBlock2Ptr->frontier.field_E22[2] % 16) + { + if (bits & 1) + bits |= 6; + else + bits |= 1; + } + } while (!(bits & 2)); + + } while (!(bits & 4) && sub_81AA760(arg0, allocated, r4, var_28 + i)); + bits &= 1; + } + free(allocated); +} + +static bool8 sub_81AA4D8(u8 arg0, u8 arg1) +{ + s32 i; + s32 var_28; + s32 r6 = 0; + s32 r7 = 0; + s32 var_34 = 0; + s32 count; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + if (r7 == 0) + { + if (sub_81AA760(arg0, allocated, arg1, var_28 + i)) + r7 = 1; + else + var_34++; + } + if (r7 & 1) + { + if (sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r6], var_28 + i)) + { + do + { + r6++; + if (gUnknown_08613F46[arg1][r6] == 0xFF || r6 >= 4) + r6 = 0; + r7 += 2; + } while (r7 >> 1 != 4 && sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r6], var_28 + i)); + var_34++; + } + else + { + r6++; + if (gUnknown_08613F46[arg1][r6] == 0xFF || r6 >= 4) + r6 = 0; + var_34++; + } + } + + if (r7 >> 1 == 4) + break; + + r7 &= 1; + } + // free(allocated); BUG: allocated memory not freed + + return (count / 2 > var_34); +} + +static bool8 sub_81AA648(u8 arg0, u8 arg1) +{ + s32 i; + s32 var_28; + s32 r4 = 0; + s32 r7 = 0; + s32 r8 = 0; + s32 count; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + if (sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r4], var_28 + i)) + { + do + { + r4++; + if (gUnknown_08613F46[arg1][r4] == 0xFF || r4 >= 4) + r4 = 0; + r8++; + } while (r8 != 4 && sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r4], var_28 + i)); + r7++; + } + else + { + r4++; + if (gUnknown_08613F46[arg1][r4] == 0xFF || r4 >= 4) + r4 = 0; + r7++; + } + + if (r8 == 4) + break; + } + // free(allocated); BUG: allocated memory not freed + + return (count / 2 > r7); +} + +static bool8 sub_81AA760(u8 arg0, u8 *mapNums, u8 whichMap, u8 id) +{ + s32 i, j; + + if (gSaveBlock2Ptr->frontier.field_E22[0] & 1) + { + s32 minus1 = -1; + for (i = 7; i > minus1; i--) + { + for (j = 7; j >= 0; j--) + { + if (!sub_81AA810(arg0, j, i, mapNums, whichMap, id)) + return FALSE; + } + } + } + else + { + for (i = 0; i < 8; i++) + { + for (j = 0; j < 8; j++) + { + if (!sub_81AA810(arg0, j, i, mapNums, whichMap, id)) + return FALSE; + } + } + } + + return TRUE; +} + +static bool8 sub_81AA810(u8 arg0, u8 x, u8 y, u8 *mapNums, u8 whichMap, u8 id) +{ + s32 i, j; + const struct MapHeader *mapHeader; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + mapHeader = Overworld_GetMapHeaderByGroupAndId(MAP_GROUP(BATTLE_PYRAMID_SQUARE01), mapNums[whichMap] + MAP_NUM(BATTLE_PYRAMID_SQUARE01)); + for (i = 0; i < mapHeader->events->eventObjectCount; i++) + { + if (mapHeader->events->eventObjects[i].x != x || mapHeader->events->eventObjects[i].y != y) + continue; + + if (arg0 != 0 || mapHeader->events->eventObjects[i].graphicsId == EVENT_OBJ_GFX_ITEM_BALL) + { + if (arg0 != 1 || mapHeader->events->eventObjects[i].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + continue; + } + + for (j = 0; j < id; j++) + { + if (events[j].x == x + ((whichMap % 4) * 8) && events[j].y == y + ((whichMap / 4) * 8)) + break; + } + if (j != id) + continue; + + events[id] = mapHeader->events->eventObjects[i]; + events[id].x += ((whichMap % 4) * 8); + events[id].y += ((whichMap / 4) * 8); + events[id].localId = id + 1; + if (events[id].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + { + i = sub_81A9F90(id); + events[id].graphicsId = GetBattleFacilityTrainerGfxId(i); + gSaveBlock2Ptr->frontier.field_CB4[id] = i; + } + return FALSE; + } + + return TRUE; +} + +static void sub_81AA96C(u8 *mapNums) +{ + s32 i; + s32 bits = (gSaveBlock2Ptr->frontier.field_E22[0]) | (gSaveBlock2Ptr->frontier.field_E22[1] << 16); + u8 id = sub_81AA9E4(); + + for (i = 0; i < 16; i++) + { + mapNums[i] = gUnknown_08613650[id].unk5[bits & 7]; + bits >>= 3; + if (i == 7) + { + bits = (gSaveBlock2Ptr->frontier.field_E22[2]) | (gSaveBlock2Ptr->frontier.field_E22[3] << 16); + bits >>= 8; + } + } +} + +static u8 sub_81AA9E4(void) +{ + s32 i; + s32 var = gSaveBlock2Ptr->frontier.field_E22[3] % 100; + s32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + + for (i = gUnknown_08613794[battleNum]; i < ARRAY_COUNT(gUnknown_08613750); i++) + { + if (var < gUnknown_08613750[i][0]) + return gUnknown_08613750[i][1]; + } + return 0; +} + +u8 sub_81AAA40(void) +{ + u8 i; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + for (i = 0; i < 16; i++) + { + if (events[i].localId == 0) + break; + } + + return i; +} + +static void InitBagItems(u8 lvlMode) +{ + s32 i; + + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) + { + gSaveBlock2Ptr->frontier.pyramidBag.itemId[lvlMode][i] = 0; + gSaveBlock2Ptr->frontier.pyramidBag.quantity[lvlMode][i] = 0; + } + + AddPyramidBagItem(ITEM_HYPER_POTION, 1); + AddPyramidBagItem(ITEM_ETHER, 1); +} + +u16 GetBattlePyramidPickupItemId(void) +{ + s32 rand; + u32 i; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + s32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7); + + if (round >= TOTAL_ROUNDS) + round = TOTAL_ROUNDS - 1; + + rand = Random() % 100; + + for (i = 0; i < ARRAY_COUNT(sPickupPercentages); i++) + { + if (sPickupPercentages[i] > rand) + break; + } + + if (i >= PICKUP_ITEMS_PER_ROUND) + i = PICKUP_ITEMS_PER_ROUND - 1; + + if (lvlMode != FRONTIER_LVL_50) + return sPickupItemsLvlOpen[round][i]; + else + return sPickupItemsLvl50[round][i]; +} diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 920e1045b..ae397159a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -45,6 +45,7 @@ #include "party_menu.h" #include "battle_arena.h" #include "battle_pike.h" +#include "battle_pyramid.h" extern u16 gBattle_BG1_X; extern u16 gBattle_BG1_Y; @@ -62,11 +63,8 @@ extern void sub_81D388C(struct Pokemon* mon, void* statStoreLocation); // pokena extern void sub_81D3640(u8 arg0, void* statStoreLocation1, void* statStoreLocation2, u8 arg3, u8 arg4, u8 arg5); // pokenav.s extern void sub_81D3784(u8 arg0, void* statStoreLocation1, u8 arg2, u8 arg3, u8 arg4); // pokenav.s extern u8* GetMonNickname(struct Pokemon* mon, u8* dst); // party_menu -extern u8 BattleArena_ShowJudgmentWindow(u8* arg0); // battle frontier 2 extern void sub_81B8E80(u8 battlerId, u8, u8); // party menu extern bool8 sub_81B1250(void); // ? -extern bool8 InBattlePyramid(void); -extern u16 GetBattlePyramidPickupItemId(void); extern u8 sub_813B21C(void); extern u16 get_unknown_box_id(void); diff --git a/src/battle_setup.c b/src/battle_setup.c index 18998e564..ab2a12fb7 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -34,6 +34,7 @@ #include "battle_tower.h" #include "gym_leader_rematch.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "constants/map_types.h" #include "constants/battle_frontier.h" @@ -54,7 +55,6 @@ struct TrainerBattleParameter u8 ptrType; }; -extern bool8 InBattlePyramid(void); extern bool32 InTrainerHill(void); extern bool32 FieldPoisonEffectIsRunning(void); extern void RestartWildEncounterImmunitySteps(void); @@ -63,17 +63,13 @@ extern void sub_81BE72C(void); extern void sub_808BCF4(void); extern void sub_80EECC8(void); extern void sub_80AF6F0(void); -extern u16 sub_81A9AA8(u8 localId); extern u16 sub_81D6180(u8 localId); -extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjId); extern bool8 GetTrainerHillTrainerFlag(u8 eventObjId); extern bool8 sub_81D5C18(void); -extern void sub_81A9B04(void); extern void sub_81D639C(void); extern void sub_81D6384(void); extern void sub_81D61E8(void); extern void sub_80982B8(void); -extern void sub_81A9EDC(u16 a0); extern void CopyTrainerHillTrainerText(u8 a0, u16 arg1); // this file's functions @@ -1131,12 +1127,12 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) { TrainerBattleLoadArgs(sOrdinaryBattleParams, data); SetMapVarsToTrainer(); - gTrainerBattleOpponent_A = sub_81A9AA8(gSpecialVar_LastTalked); + gTrainerBattleOpponent_A = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } else { TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); - gTrainerBattleOpponent_B = sub_81A9AA8(gSpecialVar_LastTalked); + gTrainerBattleOpponent_B = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } return EventScript_271362; case TRAINER_BATTLE_SET_TRAINER_A: @@ -1360,9 +1356,9 @@ void ShowTrainerIntroSpeech(void) if (InBattlePyramid()) { if (gNoOfApproachingTrainers == 0 || gNoOfApproachingTrainers == 1) - sub_81A9EDC(sub_81A9AA8(gSpecialVar_LastTalked)); + CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gSpecialVar_LastTalked)); else - sub_81A9EDC(sub_81A9AA8(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId)); + CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId)); sub_80982B8(); } diff --git a/src/item.c b/src/item.c index b4a2fd6f0..b2c009be6 100644 --- a/src/item.c +++ b/src/item.c @@ -10,9 +10,9 @@ #include "item_menu.h" #include "strings.h" #include "load_save.h" +#include "battle_pyramid.h" #include "battle_pyramid_bag.h" -extern bool8 InBattlePyramid(void); extern u16 gUnknown_0203CF30[]; extern const struct Item gItems[]; diff --git a/src/overworld.c b/src/overworld.c index 4e1f8cc4f..5c0a06f38 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1,5 +1,6 @@ #include "global.h" #include "overworld.h" +#include "battle_pyramid.h" #include "battle_setup.h" #include "berry.h" #include "bg.h" @@ -113,7 +114,6 @@ extern void ShowMapNamePopup(void); extern bool32 InTrainerHill(void); extern bool32 sub_808651C(void); extern bool8 sub_80AF6A4(void); -extern bool8 InBattlePyramid_(void); extern bool8 sub_80E909C(void); extern void sub_81AA1D8(void); extern void c2_change_map(void); diff --git a/src/pokemon.c b/src/pokemon.c index 47c4f9217..0f7c80b77 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4,6 +4,7 @@ #include "battle_controllers.h" #include "battle_message.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "battle_setup.h" #include "battle_tower.h" #include "event_data.h" @@ -81,9 +82,7 @@ extern u8 StorageGetCurrentBox(void); extern void set_unknown_box_id(u8); extern void sub_803FA70(u8 battlerId); extern u8 sav1_map_get_name(void); -extern bool8 InBattlePyramid(void); extern bool8 sub_806F104(void); -extern u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerOpponentId); extern u8 sub_81D63C8(u16 trainerOpponentId); extern void SummaryScreen_SetUnknownTaskId(u8); diff --git a/src/trainer_see.c b/src/trainer_see.c index 726d89847..b74608d0b 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -12,11 +12,10 @@ #include "task.h" #include "trainer_see.h" #include "util.h" +#include "battle_pyramid.h" #include "constants/field_effects.h" -extern bool8 InBattlePyramid(void); extern bool32 InTrainerHill(void); -extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjectId); extern bool8 GetTrainerHillTrainerFlag(u8 eventObjectId); extern void sub_809BE48(u16 npcId); diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 52dbdf65e..9b3c70ad7 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -19,6 +19,7 @@ #include "link.h" #include "script.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "constants/items.h" #include "constants/maps.h" @@ -26,9 +27,6 @@ extern const u8 EventScript_RepelWoreOff[]; #define NUM_FEEBAS_SPOTS 6 -extern void GenerateBattlePyramidWildMon(void); -extern bool8 InBattlePyramid(void); - // this file's functions static u16 FeebasRandom(void); static void FeebasSeedRng(u16 seed);