From 7ae74721b9af15f6ebd1352b7459f87697ea3258 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 6 Nov 2024 10:42:40 +0100 Subject: [PATCH 01/30] sub_804B534 --- asm/code_804AFAC.s | 782 --------------------------- include/structs/str_dungeon.h | 3 +- ld_script.txt | 3 +- src/code_804AFAC_1.c | 971 ++++++++++++++++++++++++++++++++++ 4 files changed, 975 insertions(+), 784 deletions(-) create mode 100644 src/code_804AFAC_1.c diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index c2f4a3fea..1dea514e9 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -5,788 +5,6 @@ .text - thumb_func_start sub_804AFAC -sub_804AFAC: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x44 - movs r0, 0 - mov r10, r0 - ldr r4, _0804B0E8 - ldr r0, [r4] - ldr r1, _0804B0EC - adds r1, r0 - mov r8, r1 - ldr r0, _0804B0F0 - ldr r1, _0804B0F4 - bl OpenFileAndGetFileDataPtr - ldr r2, [r4] - ldr r3, _0804B0F8 - adds r1, r2, r3 - str r0, [r1] - ldr r0, _0804B0FC - mov r6, r10 - strb r6, [r0] - ldr r0, _0804B100 - strb r6, [r0] - ldr r0, _0804B104 - strb r6, [r0] - ldr r5, _0804B108 - movs r3, 0 - ldr r1, _0804B10C - ldr r0, _0804B110 - adds r2, r0 - movs r6, 0 - ldrsh r0, [r2, r6] - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0x2 - bne _0804AFFC - movs r3, 0x1 -_0804AFFC: - strb r3, [r5] - ldr r1, _0804B114 - movs r0, 0xFF - strb r0, [r1] - ldr r0, _0804B118 - mov r1, r10 - strb r1, [r0] - ldr r1, _0804B11C - mov r2, r8 - ldrb r0, [r2, 0x7] - strh r0, [r1] - ldr r1, _0804B120 - ldrb r0, [r2, 0x8] - strh r0, [r1] - ldr r1, _0804B124 - movs r0, 0x1 - strb r0, [r1] - ldr r1, _0804B128 - movs r0, 0x1 - negs r0, r0 - str r0, [r1] - str r0, [r1, 0x8] - str r0, [r1, 0x4] - str r0, [r1, 0xC] - bl sub_804FD30 - ldr r3, [r4] - mov r6, r8 - ldrb r2, [r6, 0x6] - ldr r1, _0804B12C - adds r0, r3, r1 - movs r1, 0 - strh r2, [r0] - ldr r2, _0804B130 - adds r0, r3, r2 - strb r1, [r0] - ldr r0, [r4] - ldr r3, _0804B134 - adds r0, r3 - strb r1, [r0] - ldr r1, _0804B138 - mov r6, r8 - ldrb r0, [r6, 0xC] - str r0, [r1] - movs r0, 0 - str r0, [sp, 0x40] -_0804B058: - ldr r0, _0804B0E8 - ldr r2, [r0] - ldr r3, _0804B13C - adds r1, r2, r3 - ldr r0, _0804B140 - strh r0, [r1] - ldr r6, _0804B144 - adds r1, r2, r6 - movs r0, 0x1 - negs r0, r0 - strh r0, [r1] - ldr r0, _0804B148 - adds r1, r2, r0 - movs r0, 0x1 - negs r0, r0 - strh r0, [r1] - ldr r1, _0804B14C - adds r2, r1 - strh r0, [r2] - movs r2, 0 - mov r9, r2 -_0804B082: - ldr r4, _0804B0E8 - ldr r0, [r4] - ldr r3, _0804B150 - adds r0, r3 - movs r5, 0 - movs r1, 0 - mov r6, r9 - strh r6, [r0] - mov r0, r9 - cmp r0, 0 - ble _0804B09C - ldr r0, _0804B138 - str r1, [r0] -_0804B09C: - ldr r0, _0804B154 - strb r5, [r0] - ldr r1, _0804B158 - ldr r0, _0804B140 - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - bl sub_804FD30 - ldr r1, [r4] - ldr r3, _0804B13C - adds r2, r1, r3 - movs r0, 0x1 - negs r0, r0 - strh r0, [r2] - ldr r6, _0804B144 - adds r2, r1, r6 - strh r0, [r2] - ldr r0, _0804B15C - adds r1, r0 - strb r5, [r1] - ldr r0, [r4] - ldr r2, _0804B160 - adds r1, r0, r2 - movs r3, 0 - ldrsh r0, [r1, r3] - cmp r0, 0 - beq _0804B164 - mov r1, r8 - bl sub_804C70C - lsls r0, 24 - cmp r0, 0 - beq _0804B0E4 - b _0804B376 -_0804B0E4: - b _0804B2F6 - .align 2, 0 -_0804B0E8: .4byte gDungeon -_0804B0EC: .4byte 0x0001c574 -_0804B0F0: .4byte gUnknown_80F6DCC -_0804B0F4: .4byte gDungeonFileArchive -_0804B0F8: .4byte 0x00013568 -_0804B0FC: .4byte gUnknown_202F1AA -_0804B100: .4byte gUnknown_202F1AB -_0804B104: .4byte gUnknown_202F1AC -_0804B108: .4byte gUnknown_202F1A8 -_0804B10C: .4byte gDungeonWaterType -_0804B110: .4byte 0x00003a0e -_0804B114: .4byte gUnknown_202F1B4 -_0804B118: .4byte gUnknown_202F1AE -_0804B11C: .4byte gUnknown_202F1B0 -_0804B120: .4byte gUnknown_202F1B2 -_0804B124: .4byte gUnknown_202F1AD -_0804B128: .4byte gUnknown_202F1B8 -_0804B12C: .4byte 0x00000664 -_0804B130: .4byte 0x00003a09 -_0804B134: .4byte 0x00003a0a -_0804B138: .4byte gUnknown_202F1C8 -_0804B13C: .4byte 0x0000e218 -_0804B140: .4byte 0x0000ffff -_0804B144: .4byte 0x0000e21a -_0804B148: .4byte 0x0000e21c -_0804B14C: .4byte 0x0000e21e -_0804B150: .4byte 0x00003a16 -_0804B154: .4byte gUnknown_202F1A9 -_0804B158: .4byte gUnknown_202F1D8 -_0804B15C: .4byte 0x00003a08 -_0804B160: .4byte 0x00003a14 -_0804B164: - mov r0, r8 - ldrb r7, [r0] - movs r6, 0x20 -_0804B16A: - cmp r7, 0x8 - beq _0804B17E - movs r0, 0x2 - movs r1, 0x9 - bl DungeonRandRange - adds r5, r0, 0 - movs r0, 0x2 - movs r1, 0x8 - b _0804B18C -_0804B17E: - movs r0, 0x2 - movs r1, 0x5 - bl DungeonRandRange - adds r5, r0, 0 - movs r0, 0x2 - movs r1, 0x4 -_0804B18C: - bl DungeonRandRange - adds r4, r0, 0 - cmp r5, 0x6 - bgt _0804B19A - cmp r4, 0x4 - ble _0804B1A4 -_0804B19A: - subs r6, 0x1 - cmp r6, 0 - bne _0804B16A - movs r5, 0x4 - movs r4, 0x4 -_0804B1A4: - movs r0, 0x38 - adds r1, r5, 0 - bl __divsi3 - cmp r0, 0x7 - bgt _0804B1B2 - movs r5, 0x1 -_0804B1B2: - movs r0, 0x20 - adds r1, r4, 0 - bl __divsi3 - cmp r0, 0x7 - bgt _0804B1C0 - movs r4, 0x1 -_0804B1C0: - ldr r2, _0804B1EC - ldr r0, [r2] - ldr r1, _0804B1F0 - adds r0, r1 - movs r1, 0 - strb r1, [r0] - ldr r0, [r2] - ldr r2, _0804B1F4 - adds r0, r2 - movs r1, 0xFF - strb r1, [r0] - ldr r0, _0804B1F8 - str r7, [r0] - movs r0, 0xF - ands r0, r7 - cmp r0, 0xB - bhi _0804B274 - lsls r0, 2 - ldr r1, _0804B1FC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_0804B1EC: .4byte gDungeon -_0804B1F0: .4byte 0x00003a08 -_0804B1F4: .4byte 0x00003a0c -_0804B1F8: .4byte gUnknown_202F1D0 -_0804B1FC: .4byte _0804B200 - .align 2, 0 -_0804B200: - .4byte _0804B274 - .4byte _0804B230 - .4byte _0804B280 - .4byte _0804B298 - .4byte _0804B2A4 - .4byte _0804B2B0 - .4byte _0804B2CC - .4byte _0804B2D8 - .4byte _0804B274 - .4byte _0804B2E0 - .4byte _0804B2E8 - .4byte _0804B250 -_0804B230: - movs r0, 0x2 - bl DungeonRandInt - adds r4, r0, 0x2 - ldr r1, _0804B24C - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x4 - adds r1, r4, 0 - mov r2, r8 - bl sub_804B634 - b _0804B2AA - .align 2, 0 -_0804B24C: .4byte gUnknown_202F1AE -_0804B250: - movs r0, 0x2 - bl DungeonRandInt - adds r4, r0, 0x2 - ldr r1, _0804B270 - movs r0, 0x2 - strb r0, [r1] - movs r0, 0x4 - adds r1, r4, 0 - mov r2, r8 - bl sub_804B634 - movs r6, 0x1 - mov r10, r6 - b _0804B2F6 - .align 2, 0 -_0804B270: .4byte gUnknown_202F1AE -_0804B274: - adds r0, r5, 0 - adds r1, r4, 0 - mov r2, r8 - bl sub_804B634 - b _0804B2D2 -_0804B280: - bl sub_804C918 - ldr r0, _0804B290 - ldr r0, [r0] - ldr r1, _0804B294 - adds r0, r1 - b _0804B2BC - .align 2, 0 -_0804B290: .4byte gDungeon -_0804B294: .4byte 0x00003a08 -_0804B298: - mov r0, r8 - bl sub_804B72C - movs r2, 0x1 - mov r10, r2 - b _0804B2F6 -_0804B2A4: - mov r0, r8 - bl sub_804BC80 -_0804B2AA: - movs r3, 0x1 - mov r10, r3 - b _0804B2F6 -_0804B2B0: - bl sub_804C9D0 - ldr r0, _0804B2C4 - ldr r0, [r0] - ldr r6, _0804B2C8 - adds r0, r6 -_0804B2BC: - movs r1, 0x1 - strb r1, [r0] - b _0804B2F6 - .align 2, 0 -_0804B2C4: .4byte gDungeon -_0804B2C8: .4byte 0x00003a08 -_0804B2CC: - mov r0, r8 - bl sub_804C0A8 -_0804B2D2: - movs r0, 0x1 - mov r10, r0 - b _0804B2F6 -_0804B2D8: - mov r0, r8 - bl sub_804C190 - b _0804B2F6 -_0804B2E0: - mov r0, r8 - bl sub_804C2F4 - b _0804B2F6 -_0804B2E8: - adds r0, r5, 0 - adds r1, r4, 0 - mov r2, r8 - bl sub_804C53C - movs r1, 0x1 - mov r10, r1 -_0804B2F6: - bl sub_80518F0 - bl sub_804FCCC - ldr r0, _0804B4B4 - ldrb r0, [r0] - cmp r0, 0 - bne _0804B36A - movs r7, 0 - movs r1, 0 - mov r0, sp - adds r0, 0x3F -_0804B30E: - strb r1, [r0] - subs r0, 0x1 - cmp r0, sp - bge _0804B30E - movs r5, 0 -_0804B318: - movs r4, 0 - adds r6, r5, 0x1 -_0804B31C: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - adds r1, r0, 0 - ldrh r0, [r1] - movs r2, 0x3 - ands r2, r0 - cmp r2, 0x1 - bne _0804B340 - ldrb r0, [r1, 0x9] - cmp r0, 0xF0 - bhi _0804B340 - adds r7, 0x1 - cmp r0, 0x3F - bhi _0804B340 - add r0, sp - strb r2, [r0] -_0804B340: - adds r4, 0x1 - cmp r4, 0x1F - ble _0804B31C - adds r5, r6, 0 - cmp r5, 0x37 - ble _0804B318 - movs r1, 0 - movs r4, 0 -_0804B350: - mov r2, sp - adds r0, r2, r4 - ldrb r0, [r0] - cmp r0, 0 - beq _0804B35C - adds r1, 0x1 -_0804B35C: - adds r4, 0x1 - cmp r4, 0x3F - ble _0804B350 - cmp r7, 0x1D - ble _0804B36A - cmp r1, 0x1 - bgt _0804B376 -_0804B36A: - movs r3, 0x1 - add r9, r3 - mov r6, r9 - cmp r6, 0x9 - bgt _0804B376 - b _0804B082 -_0804B376: - mov r0, r9 - cmp r0, 0xA - bne _0804B398 - ldr r1, _0804B4B8 - ldr r0, _0804B4BC - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - bl sub_804C918 - ldr r0, _0804B4C0 - ldr r0, [r0] - ldr r1, _0804B4C4 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0] -_0804B398: - bl sub_804E9DC - mov r2, r10 - cmp r2, 0 - beq _0804B3AA - movs r0, 0x1 - mov r1, r8 - bl sub_80506F0 -_0804B3AA: - movs r0, 0x64 - bl DungeonRandInt - movs r4, 0 - mov r3, r8 - ldrb r3, [r3, 0x19] - cmp r0, r3 - bge _0804B3BC - movs r4, 0x1 -_0804B3BC: - mov r0, r8 - adds r1, r4, 0 - bl sub_804FF08 - mov r0, r8 - adds r1, r4, 0 - bl sub_8050438 - bl sub_804FBE8 - ldr r5, _0804B4C0 - ldr r1, [r5] - ldr r6, _0804B4C8 - adds r0, r1, r6 - movs r2, 0 - ldrsh r0, [r0, r2] - movs r4, 0x1 - negs r4, r4 - cmp r0, r4 - beq _0804B42A - ldr r3, _0804B4CC - adds r0, r1, r3 - movs r6, 0 - ldrsh r0, [r0, r6] - cmp r0, r4 - beq _0804B42A - bl sub_8043D10 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _0804B436 - ldr r1, [r5] - ldr r0, _0804B4D0 - adds r2, r1, r0 - movs r3, 0 - ldrsh r0, [r2, r3] - cmp r0, r4 - beq _0804B42A - ldr r6, _0804B4D4 - adds r1, r6 - movs r3, 0 - ldrsh r0, [r1, r3] - cmp r0, r4 - beq _0804B42A - movs r6, 0 - ldrsh r0, [r2, r6] - movs r2, 0 - ldrsh r1, [r1, r2] - movs r2, 0 - bl sub_8050C30 - lsls r0, 24 - cmp r0, 0 - bne _0804B436 -_0804B42A: - ldr r3, [sp, 0x40] - adds r3, 0x1 - str r3, [sp, 0x40] - cmp r3, 0x9 - bgt _0804B436 - b _0804B058 -_0804B436: - ldr r6, [sp, 0x40] - cmp r6, 0xA - bne _0804B474 - ldr r1, _0804B4B8 - ldr r0, _0804B4BC - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - bl sub_804FD30 - bl sub_804C918 - ldr r0, _0804B4C0 - ldr r0, [r0] - ldr r1, _0804B4C4 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0] - bl sub_804E9DC - mov r0, r8 - movs r1, 0 - bl sub_804FF08 - mov r0, r8 - movs r1, 0 - bl sub_8050438 - bl sub_804FBE8 -_0804B474: - ldr r1, _0804B4B8 - movs r2, 0 - ldrsh r0, [r1, r2] - cmp r0, 0 - blt _0804B498 - movs r3, 0x2 - ldrsh r0, [r1, r3] - cmp r0, 0 - blt _0804B498 - movs r6, 0 - ldrsh r0, [r1, r6] - movs r2, 0x2 - ldrsh r1, [r1, r2] - movs r2, 0xBE - lsls r2, 1 - movs r3, 0 - bl sub_806C330 -_0804B498: - ldr r0, _0804B4D8 - ldr r0, [r0] - cmp r0, 0 - blt _0804B4E0 - mov r0, r8 - bl sub_8051654 - ldr r0, _0804B4C0 - ldr r0, [r0] - ldr r3, _0804B4DC - adds r0, r3 - movs r1, 0x1 - b _0804B4EA - .align 2, 0 -_0804B4B4: .4byte gUnknown_202F1A9 -_0804B4B8: .4byte gUnknown_202F1D8 -_0804B4BC: .4byte 0x0000ffff -_0804B4C0: .4byte gDungeon -_0804B4C4: .4byte 0x00003a08 -_0804B4C8: .4byte 0x0000e218 -_0804B4CC: .4byte 0x0000e21a -_0804B4D0: .4byte 0x0000e21c -_0804B4D4: .4byte 0x0000e21e -_0804B4D8: .4byte gUnknown_202F1B8 -_0804B4DC: .4byte 0x00003a0a -_0804B4E0: - ldr r0, _0804B524 - ldr r0, [r0] - ldr r6, _0804B528 - adds r0, r6 - movs r1, 0 -_0804B4EA: - strb r1, [r0] - movs r0, 0 - movs r1, 0 - movs r2, 0x38 - movs r3, 0x20 - bl sub_804B534 - ldr r0, _0804B52C - ldrb r0, [r0] - cmp r0, 0 - beq _0804B504 - bl sub_804FC74 -_0804B504: - ldr r0, _0804B524 - ldr r0, [r0] - ldr r1, _0804B530 - adds r0, r1 - ldr r0, [r0] - bl CloseFile - add sp, 0x44 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804B524: .4byte gDungeon -_0804B528: .4byte 0x00003a0a -_0804B52C: .4byte gUnknown_202F1A8 -_0804B530: .4byte 0x00013568 - thumb_func_end sub_804AFAC - - thumb_func_start sub_804B534 -sub_804B534: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - str r1, [sp] - str r2, [sp, 0x4] - mov r10, r3 - adds r5, r0, 0 - cmp r5, r2 - bge _0804B620 -_0804B54C: - ldr r4, [sp] - adds r0, r5, 0x1 - mov r9, r0 - cmp r4, r10 - bge _0804B618 - movs r6, 0x3 - mov r8, r6 -_0804B55A: - movs r3, 0 - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0xC] - bl GetTileSafe - adds r2, r0, 0 - ldrh r0, [r2] - ldr r6, _0804B630 - adds r1, r6, 0 - ands r1, r0 - strh r1, [r2] - ldrb r0, [r2, 0x9] - adds r6, r4, 0x1 - ldr r3, [sp, 0xC] - cmp r0, 0xFF - bne _0804B612 - movs r7, 0x3 - adds r0, r1, 0 - ands r0, r7 - cmp r0, 0x1 - bne _0804B612 - cmp r5, 0 - ble _0804B5A4 - subs r0, r5, 0x1 - adds r1, r4, 0 - str r2, [sp, 0x8] - bl GetTile - ldrh r1, [r0] - adds r0, r7, 0 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B5A4 - movs r3, 0x1 -_0804B5A4: - cmp r4, 0 - ble _0804B5C4 - subs r1, r4, 0x1 - adds r0, r5, 0 - str r2, [sp, 0x8] - str r3, [sp, 0xC] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B5C4 - adds r3, 0x1 -_0804B5C4: - cmp r5, 0x35 - bgt _0804B5E4 - mov r0, r9 - adds r1, r4, 0 - str r2, [sp, 0x8] - str r3, [sp, 0xC] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B5E4 - adds r3, 0x1 -_0804B5E4: - adds r6, r4, 0x1 - cmp r5, 0x1D - bgt _0804B606 - adds r0, r5, 0 - adds r1, r6, 0 - str r2, [sp, 0x8] - str r3, [sp, 0xC] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B606 - adds r3, 0x1 -_0804B606: - cmp r3, 0x2 - ble _0804B612 - ldrh r1, [r2] - movs r0, 0x8 - orrs r0, r1 - strh r0, [r2] -_0804B612: - adds r4, r6, 0 - cmp r4, r10 - blt _0804B55A -_0804B618: - mov r5, r9 - ldr r0, [sp, 0x4] - cmp r5, r0 - blt _0804B54C -_0804B620: - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804B630: .4byte 0x0000fffb - thumb_func_end sub_804B534 thumb_func_start sub_804B634 sub_804B634: diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index c7daddb1b..a8f99c070 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -372,7 +372,8 @@ typedef struct Dungeon u16 unk12BEC[9]; u16 unk12BFE[19]; u8 unk12C24[0x930]; - u16 unk13554[12]; + u16 unk13554[10]; + OpenedFile *unk13568; u8 unk1356C; u8 fill1356D[0x13570 - 0x1356D]; /* 0x13570 */ u8 unk13570; diff --git a/ld_script.txt b/ld_script.txt index 77ff0e155..8afa0922a 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -228,7 +228,8 @@ SECTIONS { src/dungeon_ai_item_weight.o(.text); src/dungeon_map_access.o(.text); src/tile_types.o(.text); - asm/code_804AFAC.o(.text); + src/code_804AFAC_1.o(.text); + asm/code_804AFAC.o(.text); src/code_804AFAC.o(.text); asm/code_804FD30.o(.text); src/dungeon_message.o(.text); diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c new file mode 100644 index 000000000..7fcf4b59a --- /dev/null +++ b/src/code_804AFAC_1.c @@ -0,0 +1,971 @@ +#include "global.h" +#include "file_system.h" +#include "tile_types.h" +#include "dungeon_map_access.h" +#include "dungeon_random.h" +#include "structs/str_dungeon.h" +#include "structs/map.h" + +extern const u8 gUnknown_80F6DCC[]; +extern struct FileArchive gDungeonFileArchive; + +extern u8 gUnknown_202F1AA; +extern u8 gUnknown_202F1AB; +extern u8 gUnknown_202F1AC; +extern u8 gUnknown_202F1A8; +extern u8 gUnknown_202F1B4; +extern u8 gUnknown_202F1AE; +extern u8 gUnknown_202F1AD; +extern u8 gUnknown_202F1A9; +extern u16 gUnknown_202F1B0; +extern s32 gUnknown_202F1C8; +extern s32 gUnknown_202F1D0; +extern Position gUnknown_202F1D8; + +struct UnkStruct_202F1B8 +{ + s32 unk0; + s32 unk4; + s32 unk8; + s32 unkC; +}; + +extern struct UnkStruct_202F1B8 gUnknown_202F1B8; + +extern void sub_804FD30(void); +extern void sub_804FD30(void); +extern void sub_80518F0(void); +extern void sub_804FCCC(void); +extern void sub_804C918(void); +extern void sub_804FBE8(void); +extern void sub_804FC74(void); +extern void sub_804E9DC(void); +extern void sub_804C9D0(void); +extern u8 sub_8043D10(); +extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); +extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); +extern void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); + +bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); +void sub_804B634(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); +void sub_804B72C(UnkDungeonGlobal_unk1C574 *a0); +void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0); +void sub_804C0A8(UnkDungeonGlobal_unk1C574 *a0); +void sub_804C190(UnkDungeonGlobal_unk1C574 *a0); +void sub_804C2F4(UnkDungeonGlobal_unk1C574 *a0); +void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); +void sub_80506F0(s32 a0, UnkDungeonGlobal_unk1C574 *a1); +void sub_804FF08(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); +void sub_8050438(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); + +// Some weird-ass regswap prevents the function from being matched - https://decomp.me/scratch/9SUV3 +#ifdef NONMATCHING +void sub_804AFAC(void) +{ + s32 x, y; + s32 i, j, k; + bool8 r10 = FALSE; + UnkDungeonGlobal_unk1C574 *unkPtr = &gDungeon->unk1C574; + + gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); + gUnknown_202F1AA = 0; + gUnknown_202F1AB = 0; + gUnknown_202F1AC = 0; + gUnknown_202F1A8 = (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_WATER); + gUnknown_202F1B4 = 0xFF; + gUnknown_202F1AE = 0; + gUnknown_202F1B0 = unkPtr->unk7; + gUnknown_202F1B2 = unkPtr->unk8; + gUnknown_202F1AD = 1; + gUnknown_202F1B8.unk0 = -1; + gUnknown_202F1B8.unk8 = -1; + gUnknown_202F1B8.unk4 = -1; + gUnknown_202F1B8.unkC = -1; + + sub_804FD30(); + + gDungeon->unk664 = unkPtr->unk6; + + gDungeon->unk3A09 = 0; + gDungeon->unk3A0A = 0; + + gUnknown_202F1C8 = unkPtr->unkC; + + for (i = 0; i < 10; i++) { + bool32 r4 = 0; + + gDungeon->unkE218.x = -1; + gDungeon->unkE218.y = -1; + gDungeon->unkE21C.x = -1; + gDungeon->unkE21C.y = -1; + for (j = 0; j < 10; j++) { + gDungeon->unk3A16 = j; + if (j > 0) { + gUnknown_202F1C8 = 0; + } + gUnknown_202F1A9 = 0; + gUnknown_202F1D8.x = -1; + gUnknown_202F1D8.y = -1; + sub_804FD30(); + gDungeon->unkE218.x = -1; + gDungeon->unkE218.y = -1; + gDungeon->unk3A08 = 0; + if (gDungeon->bossBattleIndex != 0) { + if (sub_804C70C(gDungeon->bossBattleIndex, unkPtr)) { + break; + } + } + else { + u8 r7 = unkPtr->unk0; + + k = 32; + while (1) { + if (r7 != 8) { + x = DungeonRandRange(2, 9); + y = DungeonRandRange(2, 8); + } + else { + x = DungeonRandRange(2, 5); + y = DungeonRandRange(2, 4); + } + + if (x <= 6 && y <= 4) { + break; + } + if (--k == 0) { + x = 4; + y = 4; + break; + } + } + + if (DUNGEON_MAX_SIZE_X / x < 8) { + x = 1; + } + if (DUNGEON_MAX_SIZE_Y / y < 8) { + y = 1; + } + + gDungeon->unk3A08 = 0; + gDungeon->unk3A0C = 0xFF; + gUnknown_202F1D0 = r7; + switch (r7 & 0xF) { + case 1: + y = DungeonRandInt(2) + 2; + gUnknown_202F1AE = 1; + sub_804B634(4, y, unkPtr); + r10 = TRUE; + break; + case 11: + y = DungeonRandInt(2) + 2; + gUnknown_202F1AE = 2; + sub_804B634(4, y, unkPtr); + r10 = TRUE; + break; + case 0: + default: + sub_804B634(x, y, unkPtr); + r10 = TRUE; + break; + case 2: + sub_804C918(); + gDungeon->unk3A08 = 1; + break; + case 3: + sub_804B72C(unkPtr); + r10 = TRUE; + break; + case 4: + sub_804BC80(unkPtr); + r10 = TRUE; + break; + case 5: + sub_804C9D0(); + gDungeon->unk3A08 = 1; + break; + case 6: + sub_804C0A8(unkPtr); + r10 = TRUE; + break; + case 7: + sub_804C190(unkPtr); + break; + case 9: + sub_804C2F4(unkPtr); + break; + case 10: + sub_804B634(x, y, unkPtr); + r10 = TRUE; + break; + } + } + + sub_80518F0(); + sub_804FCCC(); + if (gUnknown_202F1A9 == 0) { + s32 countSp = 0; + u8 spArray[64]; + s32 countRooms = 0; + + for (k = 0; k < 64; k++) { + spArray[k] = 0; + } + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + Tile *tile = GetTile(x, y); + if ((tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL && tile->room <= 240) { + countRooms++; + if (tile->room < 64) { + spArray[tile->room] = 1; + } + } + } + } + + countSp = 0; + // In order to match, 'y' had to be re-used as an iterator var + for (y = 0; y < 64; y++) { + if (spArray[y]) { + countSp++; + } + } + + if (countRooms >= 30 && countSp > 1) { + break; + } + } + } + + if (j == 10) { + gUnknown_202F1D8.x = -1; + gUnknown_202F1D8.y = -1; + sub_804C918(); + gDungeon->unk3A08 = 1; + } + sub_804E9DC(); + if (r10) { + sub_80506F0(1, unkPtr); + } + r4 = (DungeonRandInt(100) < unkPtr->unk19); + sub_804FF08(unkPtr, r4); + sub_8050438(unkPtr, r4); + sub_804FBE8(); + if (gDungeon->unkE218.x != -1 && gDungeon->unkE218.y != -1) + { + if (sub_8043D10() == 1) + break; + if (gDungeon->unkE21C.x != -1 && gDungeon->unkE21C.y != -1 && sub_8050C30(gDungeon->unkE21C.x, gDungeon->unkE21C.y, 0)) + break; + } + } + + if (i == 10) { + gUnknown_202F1D8.x = -1; + gUnknown_202F1D8.y = -1; + sub_804FD30(); + sub_804C918(); + gDungeon->unk3A08 = 1; + sub_804E9DC(); + sub_804FF08(unkPtr, FALSE); + sub_8050438(unkPtr, FALSE); + sub_804FBE8(); + } + + if (gUnknown_202F1D8.x >= 0 && gUnknown_202F1D8.y >= 0) { + sub_806C330(gUnknown_202F1D8.x, gUnknown_202F1D8.y, 380, 0); + } + + if (gUnknown_202F1B8.unk0 >= 0) { + sub_8051654(unkPtr); + gDungeon->unk3A0A = 1; + } + else { + gDungeon->unk3A0A = 0; + } + + sub_804B534(0, 0, DUNGEON_MAX_SIZE_X, DUNGEON_MAX_SIZE_Y); + if (gUnknown_202F1A8 != 0) { + sub_804FC74(); + } + + CloseFile(gDungeon->unk13568); +} +#else +void NAKED sub_804AFAC(void) +{ + asm_unified(" push {r4-r7,lr}\n" +" mov r7, r10\n" +" mov r6, r9\n" +" mov r5, r8\n" +" push {r5-r7}\n" +" sub sp, 0x44\n" +" movs r0, 0\n" +" mov r10, r0\n" +" ldr r4, _0804B0E8\n" +" ldr r0, [r4]\n" +" ldr r1, _0804B0EC\n" +" adds r1, r0\n" +" mov r8, r1\n" +" ldr r0, _0804B0F0\n" +" ldr r1, _0804B0F4\n" +" bl OpenFileAndGetFileDataPtr\n" +" ldr r2, [r4]\n" +" ldr r3, _0804B0F8\n" +" adds r1, r2, r3\n" +" str r0, [r1]\n" +" ldr r0, _0804B0FC\n" +" mov r6, r10\n" +" strb r6, [r0]\n" +" ldr r0, _0804B100\n" +" strb r6, [r0]\n" +" ldr r0, _0804B104\n" +" strb r6, [r0]\n" +" ldr r5, _0804B108\n" +" movs r3, 0\n" +" ldr r1, _0804B10C\n" +" ldr r0, _0804B110\n" +" adds r2, r0\n" +" movs r6, 0\n" +" ldrsh r0, [r2, r6]\n" +" adds r0, r1\n" +" ldrb r0, [r0]\n" +" cmp r0, 0x2\n" +" bne _0804AFFC\n" +" movs r3, 0x1\n" +"_0804AFFC:\n" +" strb r3, [r5]\n" +" ldr r1, _0804B114\n" +" movs r0, 0xFF\n" +" strb r0, [r1]\n" +" ldr r0, _0804B118\n" +" mov r1, r10\n" +" strb r1, [r0]\n" +" ldr r1, _0804B11C\n" +" mov r2, r8\n" +" ldrb r0, [r2, 0x7]\n" +" strh r0, [r1]\n" +" ldr r1, _0804B120\n" +" ldrb r0, [r2, 0x8]\n" +" strh r0, [r1]\n" +" ldr r1, _0804B124\n" +" movs r0, 0x1\n" +" strb r0, [r1]\n" +" ldr r1, _0804B128\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" str r0, [r1]\n" +" str r0, [r1, 0x8]\n" +" str r0, [r1, 0x4]\n" +" str r0, [r1, 0xC]\n" +" bl sub_804FD30\n" +" ldr r3, [r4]\n" +" mov r6, r8\n" +" ldrb r2, [r6, 0x6]\n" +" ldr r1, _0804B12C\n" +" adds r0, r3, r1\n" +" movs r1, 0\n" +" strh r2, [r0]\n" +" ldr r2, _0804B130\n" +" adds r0, r3, r2\n" +" strb r1, [r0]\n" +" ldr r0, [r4]\n" +" ldr r3, _0804B134\n" +" adds r0, r3\n" +" strb r1, [r0]\n" +" ldr r1, _0804B138\n" +" mov r6, r8\n" +" ldrb r0, [r6, 0xC]\n" +" str r0, [r1]\n" +" movs r0, 0\n" +" str r0, [sp, 0x40]\n" +"_0804B058:\n" +" ldr r0, _0804B0E8\n" +" ldr r2, [r0]\n" +" ldr r3, _0804B13C\n" +" adds r1, r2, r3\n" +" ldr r0, _0804B140\n" +" strh r0, [r1]\n" +" ldr r6, _0804B144\n" +" adds r1, r2, r6\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" strh r0, [r1]\n" +" ldr r0, _0804B148\n" +" adds r1, r2, r0\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" strh r0, [r1]\n" +" ldr r1, _0804B14C\n" +" adds r2, r1\n" +" strh r0, [r2]\n" +" movs r2, 0\n" +" mov r9, r2\n" +"_0804B082:\n" +" ldr r4, _0804B0E8\n" +" ldr r0, [r4]\n" +" ldr r3, _0804B150\n" +" adds r0, r3\n" +" movs r5, 0\n" +" movs r1, 0\n" +" mov r6, r9\n" +" strh r6, [r0]\n" +" mov r0, r9\n" +" cmp r0, 0\n" +" ble _0804B09C\n" +" ldr r0, _0804B138\n" +" str r1, [r0]\n" +"_0804B09C:\n" +" ldr r0, _0804B154\n" +" strb r5, [r0]\n" +" ldr r1, _0804B158\n" +" ldr r0, _0804B140\n" +" strh r0, [r1]\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" strh r0, [r1, 0x2]\n" +" bl sub_804FD30\n" +" ldr r1, [r4]\n" +" ldr r3, _0804B13C\n" +" adds r2, r1, r3\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" strh r0, [r2]\n" +" ldr r6, _0804B144\n" +" adds r2, r1, r6\n" +" strh r0, [r2]\n" +" ldr r0, _0804B15C\n" +" adds r1, r0\n" +" strb r5, [r1]\n" +" ldr r0, [r4]\n" +" ldr r2, _0804B160\n" +" adds r1, r0, r2\n" +" movs r3, 0\n" +" ldrsh r0, [r1, r3]\n" +" cmp r0, 0\n" +" beq _0804B164\n" +" mov r1, r8\n" +" bl sub_804C70C\n" +" lsls r0, 24\n" +" cmp r0, 0\n" +" beq _0804B0E4\n" +" b _0804B376\n" +"_0804B0E4:\n" +" b _0804B2F6\n" +" .align 2, 0\n" +"_0804B0E8: .4byte gDungeon\n" +"_0804B0EC: .4byte 0x0001c574\n" +"_0804B0F0: .4byte gUnknown_80F6DCC\n" +"_0804B0F4: .4byte gDungeonFileArchive\n" +"_0804B0F8: .4byte 0x00013568\n" +"_0804B0FC: .4byte gUnknown_202F1AA\n" +"_0804B100: .4byte gUnknown_202F1AB\n" +"_0804B104: .4byte gUnknown_202F1AC\n" +"_0804B108: .4byte gUnknown_202F1A8\n" +"_0804B10C: .4byte gDungeonWaterType\n" +"_0804B110: .4byte 0x00003a0e\n" +"_0804B114: .4byte gUnknown_202F1B4\n" +"_0804B118: .4byte gUnknown_202F1AE\n" +"_0804B11C: .4byte gUnknown_202F1B0\n" +"_0804B120: .4byte gUnknown_202F1B2\n" +"_0804B124: .4byte gUnknown_202F1AD\n" +"_0804B128: .4byte gUnknown_202F1B8\n" +"_0804B12C: .4byte 0x00000664\n" +"_0804B130: .4byte 0x00003a09\n" +"_0804B134: .4byte 0x00003a0a\n" +"_0804B138: .4byte gUnknown_202F1C8\n" +"_0804B13C: .4byte 0x0000e218\n" +"_0804B140: .4byte 0x0000ffff\n" +"_0804B144: .4byte 0x0000e21a\n" +"_0804B148: .4byte 0x0000e21c\n" +"_0804B14C: .4byte 0x0000e21e\n" +"_0804B150: .4byte 0x00003a16\n" +"_0804B154: .4byte gUnknown_202F1A9\n" +"_0804B158: .4byte gUnknown_202F1D8\n" +"_0804B15C: .4byte 0x00003a08\n" +"_0804B160: .4byte 0x00003a14\n" +"_0804B164:\n" +" mov r0, r8\n" +" ldrb r7, [r0]\n" +" movs r6, 0x20\n" +"_0804B16A:\n" +" cmp r7, 0x8\n" +" beq _0804B17E\n" +" movs r0, 0x2\n" +" movs r1, 0x9\n" +" bl DungeonRandRange\n" +" adds r5, r0, 0\n" +" movs r0, 0x2\n" +" movs r1, 0x8\n" +" b _0804B18C\n" +"_0804B17E:\n" +" movs r0, 0x2\n" +" movs r1, 0x5\n" +" bl DungeonRandRange\n" +" adds r5, r0, 0\n" +" movs r0, 0x2\n" +" movs r1, 0x4\n" +"_0804B18C:\n" +" bl DungeonRandRange\n" +" adds r4, r0, 0\n" +" cmp r5, 0x6\n" +" bgt _0804B19A\n" +" cmp r4, 0x4\n" +" ble _0804B1A4\n" +"_0804B19A:\n" +" subs r6, 0x1\n" +" cmp r6, 0\n" +" bne _0804B16A\n" +" movs r5, 0x4\n" +" movs r4, 0x4\n" +"_0804B1A4:\n" +" movs r0, 0x38\n" +" adds r1, r5, 0\n" +" bl __divsi3\n" +" cmp r0, 0x7\n" +" bgt _0804B1B2\n" +" movs r5, 0x1\n" +"_0804B1B2:\n" +" movs r0, 0x20\n" +" adds r1, r4, 0\n" +" bl __divsi3\n" +" cmp r0, 0x7\n" +" bgt _0804B1C0\n" +" movs r4, 0x1\n" +"_0804B1C0:\n" +" ldr r2, _0804B1EC\n" +" ldr r0, [r2]\n" +" ldr r1, _0804B1F0\n" +" adds r0, r1\n" +" movs r1, 0\n" +" strb r1, [r0]\n" +" ldr r0, [r2]\n" +" ldr r2, _0804B1F4\n" +" adds r0, r2\n" +" movs r1, 0xFF\n" +" strb r1, [r0]\n" +" ldr r0, _0804B1F8\n" +" str r7, [r0]\n" +" movs r0, 0xF\n" +" ands r0, r7\n" +" cmp r0, 0xB\n" +" bhi _0804B274\n" +" lsls r0, 2\n" +" ldr r1, _0804B1FC\n" +" adds r0, r1\n" +" ldr r0, [r0]\n" +" mov pc, r0\n" +" .align 2, 0\n" +"_0804B1EC: .4byte gDungeon\n" +"_0804B1F0: .4byte 0x00003a08\n" +"_0804B1F4: .4byte 0x00003a0c\n" +"_0804B1F8: .4byte gUnknown_202F1D0\n" +"_0804B1FC: .4byte _0804B200\n" +" .align 2, 0\n" +"_0804B200:\n" +" .4byte _0804B274\n" +" .4byte _0804B230\n" +" .4byte _0804B280\n" +" .4byte _0804B298\n" +" .4byte _0804B2A4\n" +" .4byte _0804B2B0\n" +" .4byte _0804B2CC\n" +" .4byte _0804B2D8\n" +" .4byte _0804B274\n" +" .4byte _0804B2E0\n" +" .4byte _0804B2E8\n" +" .4byte _0804B250\n" +"_0804B230:\n" +" movs r0, 0x2\n" +" bl DungeonRandInt\n" +" adds r4, r0, 0x2\n" +" ldr r1, _0804B24C\n" +" movs r0, 0x1\n" +" strb r0, [r1]\n" +" movs r0, 0x4\n" +" adds r1, r4, 0\n" +" mov r2, r8\n" +" bl sub_804B634\n" +" b _0804B2AA\n" +" .align 2, 0\n" +"_0804B24C: .4byte gUnknown_202F1AE\n" +"_0804B250:\n" +" movs r0, 0x2\n" +" bl DungeonRandInt\n" +" adds r4, r0, 0x2\n" +" ldr r1, _0804B270\n" +" movs r0, 0x2\n" +" strb r0, [r1]\n" +" movs r0, 0x4\n" +" adds r1, r4, 0\n" +" mov r2, r8\n" +" bl sub_804B634\n" +" movs r6, 0x1\n" +" mov r10, r6\n" +" b _0804B2F6\n" +" .align 2, 0\n" +"_0804B270: .4byte gUnknown_202F1AE\n" +"_0804B274:\n" +" adds r0, r5, 0\n" +" adds r1, r4, 0\n" +" mov r2, r8\n" +" bl sub_804B634\n" +" b _0804B2D2\n" +"_0804B280:\n" +" bl sub_804C918\n" +" ldr r0, _0804B290\n" +" ldr r0, [r0]\n" +" ldr r1, _0804B294\n" +" adds r0, r1\n" +" b _0804B2BC\n" +" .align 2, 0\n" +"_0804B290: .4byte gDungeon\n" +"_0804B294: .4byte 0x00003a08\n" +"_0804B298:\n" +" mov r0, r8\n" +" bl sub_804B72C\n" +" movs r2, 0x1\n" +" mov r10, r2\n" +" b _0804B2F6\n" +"_0804B2A4:\n" +" mov r0, r8\n" +" bl sub_804BC80\n" +"_0804B2AA:\n" +" movs r3, 0x1\n" +" mov r10, r3\n" +" b _0804B2F6\n" +"_0804B2B0:\n" +" bl sub_804C9D0\n" +" ldr r0, _0804B2C4\n" +" ldr r0, [r0]\n" +" ldr r6, _0804B2C8\n" +" adds r0, r6\n" +"_0804B2BC:\n" +" movs r1, 0x1\n" +" strb r1, [r0]\n" +" b _0804B2F6\n" +" .align 2, 0\n" +"_0804B2C4: .4byte gDungeon\n" +"_0804B2C8: .4byte 0x00003a08\n" +"_0804B2CC:\n" +" mov r0, r8\n" +" bl sub_804C0A8\n" +"_0804B2D2:\n" +" movs r0, 0x1\n" +" mov r10, r0\n" +" b _0804B2F6\n" +"_0804B2D8:\n" +" mov r0, r8\n" +" bl sub_804C190\n" +" b _0804B2F6\n" +"_0804B2E0:\n" +" mov r0, r8\n" +" bl sub_804C2F4\n" +" b _0804B2F6\n" +"_0804B2E8:\n" +" adds r0, r5, 0\n" +" adds r1, r4, 0\n" +" mov r2, r8\n" +" bl sub_804C53C\n" +" movs r1, 0x1\n" +" mov r10, r1\n" +"_0804B2F6:\n" +" bl sub_80518F0\n" +" bl sub_804FCCC\n" +" ldr r0, _0804B4B4\n" +" ldrb r0, [r0]\n" +" cmp r0, 0\n" +" bne _0804B36A\n" +" movs r7, 0\n" +" movs r1, 0\n" +" mov r0, sp\n" +" adds r0, 0x3F\n" +"_0804B30E:\n" +" strb r1, [r0]\n" +" subs r0, 0x1\n" +" cmp r0, sp\n" +" bge _0804B30E\n" +" movs r5, 0\n" +"_0804B318:\n" +" movs r4, 0\n" +" adds r6, r5, 0x1\n" +"_0804B31C:\n" +" adds r0, r5, 0\n" +" adds r1, r4, 0\n" +" bl GetTile\n" +" adds r1, r0, 0\n" +" ldrh r0, [r1]\n" +" movs r2, 0x3\n" +" ands r2, r0\n" +" cmp r2, 0x1\n" +" bne _0804B340\n" +" ldrb r0, [r1, 0x9]\n" +" cmp r0, 0xF0\n" +" bhi _0804B340\n" +" adds r7, 0x1\n" +" cmp r0, 0x3F\n" +" bhi _0804B340\n" +" add r0, sp\n" +" strb r2, [r0]\n" +"_0804B340:\n" +" adds r4, 0x1\n" +" cmp r4, 0x1F\n" +" ble _0804B31C\n" +" adds r5, r6, 0\n" +" cmp r5, 0x37\n" +" ble _0804B318\n" +" movs r1, 0\n" +" movs r4, 0\n" +"_0804B350:\n" +" mov r2, sp\n" +" adds r0, r2, r4\n" +" ldrb r0, [r0]\n" +" cmp r0, 0\n" +" beq _0804B35C\n" +" adds r1, 0x1\n" +"_0804B35C:\n" +" adds r4, 0x1\n" +" cmp r4, 0x3F\n" +" ble _0804B350\n" +" cmp r7, 0x1D\n" +" ble _0804B36A\n" +" cmp r1, 0x1\n" +" bgt _0804B376\n" +"_0804B36A:\n" +" movs r3, 0x1\n" +" add r9, r3\n" +" mov r6, r9\n" +" cmp r6, 0x9\n" +" bgt _0804B376\n" +" b _0804B082\n" +"_0804B376:\n" +" mov r0, r9\n" +" cmp r0, 0xA\n" +" bne _0804B398\n" +" ldr r1, _0804B4B8\n" +" ldr r0, _0804B4BC\n" +" strh r0, [r1]\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" strh r0, [r1, 0x2]\n" +" bl sub_804C918\n" +" ldr r0, _0804B4C0\n" +" ldr r0, [r0]\n" +" ldr r1, _0804B4C4\n" +" adds r0, r1\n" +" movs r1, 0x1\n" +" strb r1, [r0]\n" +"_0804B398:\n" +" bl sub_804E9DC\n" +" mov r2, r10\n" +" cmp r2, 0\n" +" beq _0804B3AA\n" +" movs r0, 0x1\n" +" mov r1, r8\n" +" bl sub_80506F0\n" +"_0804B3AA:\n" +" movs r0, 0x64\n" +" bl DungeonRandInt\n" +" movs r4, 0\n" +" mov r3, r8\n" +" ldrb r3, [r3, 0x19]\n" +" cmp r0, r3\n" +" bge _0804B3BC\n" +" movs r4, 0x1\n" +"_0804B3BC:\n" +" mov r0, r8\n" +" adds r1, r4, 0\n" +" bl sub_804FF08\n" +" mov r0, r8\n" +" adds r1, r4, 0\n" +" bl sub_8050438\n" +" bl sub_804FBE8\n" +" ldr r5, _0804B4C0\n" +" ldr r1, [r5]\n" +" ldr r6, _0804B4C8\n" +" adds r0, r1, r6\n" +" movs r2, 0\n" +" ldrsh r0, [r0, r2]\n" +" movs r4, 0x1\n" +" negs r4, r4\n" +" cmp r0, r4\n" +" beq _0804B42A\n" +" ldr r3, _0804B4CC\n" +" adds r0, r1, r3\n" +" movs r6, 0\n" +" ldrsh r0, [r0, r6]\n" +" cmp r0, r4\n" +" beq _0804B42A\n" +" bl sub_8043D10\n" +" lsls r0, 24\n" +" lsrs r0, 24\n" +" cmp r0, 0x1\n" +" beq _0804B436\n" +" ldr r1, [r5]\n" +" ldr r0, _0804B4D0\n" +" adds r2, r1, r0\n" +" movs r3, 0\n" +" ldrsh r0, [r2, r3]\n" +" cmp r0, r4\n" +" beq _0804B42A\n" +" ldr r6, _0804B4D4\n" +" adds r1, r6\n" +" movs r3, 0\n" +" ldrsh r0, [r1, r3]\n" +" cmp r0, r4\n" +" beq _0804B42A\n" +" movs r6, 0\n" +" ldrsh r0, [r2, r6]\n" +" movs r2, 0\n" +" ldrsh r1, [r1, r2]\n" +" movs r2, 0\n" +" bl sub_8050C30\n" +" lsls r0, 24\n" +" cmp r0, 0\n" +" bne _0804B436\n" +"_0804B42A:\n" +" ldr r3, [sp, 0x40]\n" +" adds r3, 0x1\n" +" str r3, [sp, 0x40]\n" +" cmp r3, 0x9\n" +" bgt _0804B436\n" +" b _0804B058\n" +"_0804B436:\n" +" ldr r6, [sp, 0x40]\n" +" cmp r6, 0xA\n" +" bne _0804B474\n" +" ldr r1, _0804B4B8\n" +" ldr r0, _0804B4BC\n" +" strh r0, [r1]\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" strh r0, [r1, 0x2]\n" +" bl sub_804FD30\n" +" bl sub_804C918\n" +" ldr r0, _0804B4C0\n" +" ldr r0, [r0]\n" +" ldr r1, _0804B4C4\n" +" adds r0, r1\n" +" movs r1, 0x1\n" +" strb r1, [r0]\n" +" bl sub_804E9DC\n" +" mov r0, r8\n" +" movs r1, 0\n" +" bl sub_804FF08\n" +" mov r0, r8\n" +" movs r1, 0\n" +" bl sub_8050438\n" +" bl sub_804FBE8\n" +"_0804B474:\n" +" ldr r1, _0804B4B8\n" +" movs r2, 0\n" +" ldrsh r0, [r1, r2]\n" +" cmp r0, 0\n" +" blt _0804B498\n" +" movs r3, 0x2\n" +" ldrsh r0, [r1, r3]\n" +" cmp r0, 0\n" +" blt _0804B498\n" +" movs r6, 0\n" +" ldrsh r0, [r1, r6]\n" +" movs r2, 0x2\n" +" ldrsh r1, [r1, r2]\n" +" movs r2, 0xBE\n" +" lsls r2, 1\n" +" movs r3, 0\n" +" bl sub_806C330\n" +"_0804B498:\n" +" ldr r0, _0804B4D8\n" +" ldr r0, [r0]\n" +" cmp r0, 0\n" +" blt _0804B4E0\n" +" mov r0, r8\n" +" bl sub_8051654\n" +" ldr r0, _0804B4C0\n" +" ldr r0, [r0]\n" +" ldr r3, _0804B4DC\n" +" adds r0, r3\n" +" movs r1, 0x1\n" +" b _0804B4EA\n" +" .align 2, 0\n" +"_0804B4B4: .4byte gUnknown_202F1A9\n" +"_0804B4B8: .4byte gUnknown_202F1D8\n" +"_0804B4BC: .4byte 0x0000ffff\n" +"_0804B4C0: .4byte gDungeon\n" +"_0804B4C4: .4byte 0x00003a08\n" +"_0804B4C8: .4byte 0x0000e218\n" +"_0804B4CC: .4byte 0x0000e21a\n" +"_0804B4D0: .4byte 0x0000e21c\n" +"_0804B4D4: .4byte 0x0000e21e\n" +"_0804B4D8: .4byte gUnknown_202F1B8\n" +"_0804B4DC: .4byte 0x00003a0a\n" +"_0804B4E0:\n" +" ldr r0, _0804B524\n" +" ldr r0, [r0]\n" +" ldr r6, _0804B528\n" +" adds r0, r6\n" +" movs r1, 0\n" +"_0804B4EA:\n" +" strb r1, [r0]\n" +" movs r0, 0\n" +" movs r1, 0\n" +" movs r2, 0x38\n" +" movs r3, 0x20\n" +" bl sub_804B534\n" +" ldr r0, _0804B52C\n" +" ldrb r0, [r0]\n" +" cmp r0, 0\n" +" beq _0804B504\n" +" bl sub_804FC74\n" +"_0804B504:\n" +" ldr r0, _0804B524\n" +" ldr r0, [r0]\n" +" ldr r1, _0804B530\n" +" adds r0, r1\n" +" ldr r0, [r0]\n" +" bl CloseFile\n" +" add sp, 0x44\n" +" pop {r3-r5}\n" +" mov r8, r3\n" +" mov r9, r4\n" +" mov r10, r5\n" +" pop {r4-r7}\n" +" pop {r0}\n" +" bx r0\n" +" .align 2, 0\n" +"_0804B524: .4byte gDungeon\n" +"_0804B528: .4byte 0x00003a0a\n" +"_0804B52C: .4byte gUnknown_202F1A8\n" +"_0804B530: .4byte 0x00013568\n"); +} +#endif // NONMATCHING + +void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) +{ + s32 x, y; + for (x = xStart; x < maxX; x++) { + for (y = yStart; y < maxY; y++) { + s32 unkCount = 0; + Tile *tile = GetTileSafe(x, y); + + tile->terrainType &= ~(TERRAIN_TYPE_UNK_2); + if (tile->room == CORRIDOR_ROOM && ((tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) { + if (x > 0 && ((GetTile(x - 1, y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + unkCount++; + if (y > 0 && ((GetTile(x, y - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + unkCount++; + if (x < DUNGEON_MAX_SIZE_X - 2 && ((GetTile(x + 1, y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + unkCount++; + // BUG: It should check for y and not x. Not sure if it has any effect, because this function is called only once with maxY equal to DUNGEON_MAX_SIZE_Y + if (x < DUNGEON_MAX_SIZE_Y - 2 && ((GetTile(x, y + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + unkCount++; + + if (unkCount > 2) { + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + } + } + } + } +} + +// From 5701369a9aad828a1e1092349302498949582126 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 7 Nov 2024 15:11:26 +0100 Subject: [PATCH 02/30] sub_804C43C --- asm/code_804AFAC.s | 1830 --------------------------------- include/structs/str_dungeon.h | 2 +- src/code_804AFAC_1.c | 1417 ++++++++++++++++++++++++- 3 files changed, 1416 insertions(+), 1833 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 1dea514e9..1438679b1 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -6,1836 +6,6 @@ .text - thumb_func_start sub_804B634 -sub_804B634: - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - ldr r4, _0804B718 - add sp, r4 - adds r4, r0, 0 - adds r5, r1, 0 - mov r9, r2 - ldr r0, _0804B71C - add r0, sp - mov r8, r0 - ldr r6, _0804B720 - add r6, sp - adds r1, r6, 0 - adds r2, r4, 0 - adds r3, r5, 0 - bl sub_804D024 - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804D084 - mov r1, r9 - movs r3, 0x1 - ldrsb r3, [r1, r3] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804D154 - str r6, [sp] - mov r1, r9 - ldrb r0, [r1, 0xD] - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804D2D0 - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r9 - bl sub_804D5B0 - str r6, [sp] - movs r0, 0 - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804D8C8 - str r6, [sp] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804E590 - mov r0, r9 - ldrb r3, [r0, 0x9] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804F0D0 - ldr r0, _0804B724 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804EBC8 - ldr r0, _0804B728 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804EEE4 - mov r0, r9 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804CBEC - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804E03C - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804D534 - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0804B718: .4byte 0xffffe360 -_0804B71C: .4byte 0x00001c28 -_0804B720: .4byte 0x00001c64 -_0804B724: .4byte gUnknown_202F1B0 -_0804B728: .4byte gUnknown_202F1B2 - thumb_func_end sub_804B634 - - thumb_func_start sub_804B72C -sub_804B72C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804B9AC - add sp, r4 - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - str r0, [r1] - movs r5, 0 - movs r6, 0x1 - ldr r1, _0804B9B0 - add r1, sp - str r5, [r1] - movs r0, 0x5 - str r0, [r1, 0x4] - movs r0, 0x1C - str r0, [r1, 0xC] - movs r0, 0x33 - str r0, [r1, 0x14] - movs r0, 0x38 - str r0, [r1, 0x18] - movs r2, 0x10 - str r2, [r1, 0x8] - movs r0, 0x27 - str r0, [r1, 0x10] - ldr r1, _0804B9B4 - add r1, sp - movs r0, 0x2 - str r0, [r1] - movs r0, 0x7 - str r0, [r1, 0x4] - str r2, [r1, 0x8] - movs r0, 0x19 - str r0, [r1, 0xC] - movs r0, 0x1E - str r0, [r1, 0x10] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804D084 - mov r2, sp - adds r2, 0x3B - ldr r3, _0804B9B8 - add r3, sp - str r2, [r3] - mov r4, sp - adds r4, 0x3C - ldr r0, _0804B9BC - add r0, sp - str r4, [r0] - mov r1, sp - adds r1, 0x5B - ldr r2, _0804B9C0 - add r2, sp - str r1, [r2] - mov r3, sp - adds r3, 0x5C - movs r4, 0xE6 - lsls r4, 5 - add r4, sp - str r3, [r4] - mov r0, sp - adds r0, 0x7B - ldr r1, _0804B9C4 - add r1, sp - str r0, [r1] - mov r2, sp - adds r2, 0x7E - ldr r3, _0804B9C8 - add r3, sp - str r2, [r3] - add r1, sp, 0x68 - add r0, sp, 0x8 - movs r2, 0xF0 - lsls r2, 1 - movs r4, 0x6 -_0804B7CC: - strb r5, [r0, 0xA] - strb r5, [r1, 0xA] - adds r1, r2 - adds r0, r2 - subs r4, 0x1 - cmp r4, 0 - bne _0804B7CC - movs r2, 0x6 - subs r2, 0x1 - movs r4, 0x4 - cmp r4, 0 - beq _0804B80C - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - add r1, sp, 0x8 - ldr r3, _0804B9CC - add r3, sp - str r4, [r3] -_0804B7F6: - strb r5, [r1, 0xA] - strb r5, [r0, 0xA] - adds r0, 0x20 - adds r1, 0x20 - ldr r3, _0804B9CC - add r3, sp - ldr r4, [r3] - subs r4, 0x1 - str r4, [r3] - cmp r4, 0 - bne _0804B7F6 -_0804B80C: - movs r4, 0x1 - cmp r4, r2 - bge _0804B848 - movs r1, 0x3 -_0804B814: - adds r5, r4, 0x1 - mov r8, r5 - cmp r1, 0x1 - ble _0804B842 - lsls r0, r4, 4 - subs r0, r4 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r0, 0x20 - subs r3, r1, 0x1 - ldr r4, _0804B9CC - add r4, sp - str r3, [r4] -_0804B830: - strb r6, [r0, 0xA] - adds r0, 0x20 - ldr r3, _0804B9CC - add r3, sp - ldr r5, [r3] - subs r5, 0x1 - str r5, [r3] - cmp r5, 0 - bne _0804B830 -_0804B842: - mov r4, r8 - cmp r4, r2 - blt _0804B814 -_0804B848: - movs r4, 0 - ldr r5, _0804B9D0 - add r5, sp - str r4, [r5] - ldr r0, _0804B9CC - add r0, sp - str r4, [r0] - cmp r4, 0x4 - blt _0804B85C - b _0804BA8C -_0804B85C: - movs r4, 0 - ldr r2, _0804B9CC - add r2, sp - ldr r1, [r2] - adds r1, 0x1 - ldr r2, _0804B9D4 - add r2, sp - str r1, [r2] - cmp r4, 0x6 - blt _0804B872 - b _0804BA7A -_0804B872: - ldr r3, _0804B9B0 - add r3, sp - ldr r5, _0804B9D8 - add r5, sp - str r3, [r5] - ldr r0, _0804B9B4 - add r0, sp - ldr r1, _0804B9DC - add r1, sp - str r0, [r1] - ldr r2, _0804B9CC - add r2, sp - ldr r2, [r2] - lsls r0, r2, 2 - ldr r3, [r1] - adds r0, r3, r0 - ldr r3, _0804B9E0 - add r3, sp - str r0, [r3] -_0804B898: - lsls r0, r4, 4 - subs r0, r4 - ldr r5, _0804B9CC - add r5, sp - ldr r5, [r5] - adds r0, r5 - lsls r0, 5 - mov r7, sp - adds r7, r0 - adds r7, 0x8 - ldrb r0, [r7, 0xA] - cmp r0, 0 - bne _0804B8B4 - b _0804B9F4 -_0804B8B4: - lsls r0, r4, 2 - ldr r1, _0804B9D8 - add r1, sp - ldr r1, [r1] - adds r0, r1, r0 - ldr r1, [r0] - adds r2, r1, 0x2 - mov r10, r2 - ldr r3, _0804B9E0 - add r3, sp - ldr r3, [r3] - ldr r2, [r3] - adds r5, r2, 0x2 - ldr r0, _0804B9E4 - add r0, sp - str r5, [r0] - adds r4, 0x1 - mov r9, r4 - lsls r0, r4, 2 - ldr r3, _0804B9D8 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r4, [r0] - subs r4, r1 - subs r4, 0x3 - ldr r5, _0804B9D4 - add r5, sp - ldr r5, [r5] - lsls r0, r5, 2 - ldr r1, _0804B9DC - add r1, sp - ldr r1, [r1] - adds r0, r1, r0 - ldr r5, [r0] - subs r5, r2 - subs r5, 0x3 - movs r0, 0x5 - adds r1, r4, 0 - bl DungeonRandRange - mov r8, r0 - movs r0, 0x4 - adds r1, r5, 0 - bl DungeonRandRange - adds r6, r0, 0 - mov r2, r8 - subs r4, r2 - adds r0, r4, 0 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r10 - subs r5, r6 - adds r0, r5, 0 - bl DungeonRandInt - ldr r5, _0804B9E4 - add r5, sp - ldr r3, [r5] - adds r3, r0 - mov r10, r3 - mov r0, r8 - adds r3, r4, r0 - add r6, r10 - strh r4, [r7] - strh r3, [r7, 0x4] - mov r1, r10 - strh r1, [r7, 0x2] - strh r6, [r7, 0x6] - mov r8, r9 - ldr r5, _0804B9D0 - add r5, sp - ldr r2, [r5] - adds r2, 0x1 - ldr r5, _0804B9E8 - add r5, sp - str r2, [r5] - cmp r4, r3 - bge _0804B99E -_0804B956: - mov r5, r10 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804B998 - ldr r0, _0804B9EC - mov r9, r0 -_0804B962: - adds r0, r4, 0 - adds r1, r5, 0 - ldr r2, _0804B9F0 - add r2, sp - str r3, [r2] - bl GetTileSafe - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileSafe - ldr r1, _0804B9D0 - add r1, sp - ldrb r1, [r1] - strb r1, [r0, 0x9] - adds r5, 0x1 - ldr r2, _0804B9F0 - add r2, sp - ldr r3, [r2] - cmp r5, r6 - blt _0804B962 -_0804B998: - adds r4, r7, 0 - cmp r4, r3 - blt _0804B956 -_0804B99E: - ldr r3, _0804B9E8 - add r3, sp - ldr r3, [r3] - ldr r4, _0804B9D0 - add r4, sp - str r3, [r4] - b _0804BA72 - .align 2, 0 -_0804B9AC: .4byte 0xffffe320 -_0804B9B0: .4byte 0x00001c28 -_0804B9B4: .4byte 0x00001c64 -_0804B9B8: .4byte 0x00001cd4 -_0804B9BC: .4byte 0x00001cd8 -_0804B9C0: .4byte 0x00001cbc -_0804B9C4: .4byte 0x00001cc4 -_0804B9C8: .4byte 0x00001cc8 -_0804B9CC: .4byte 0x00001ca4 -_0804B9D0: .4byte 0x00001ca8 -_0804B9D4: .4byte 0x00001ccc -_0804B9D8: .4byte 0x00001cac -_0804B9DC: .4byte 0x00001cb4 -_0804B9E0: .4byte 0x00001cb8 -_0804B9E4: .4byte 0x00001cb0 -_0804B9E8: .4byte 0x00001cd0 -_0804B9EC: .4byte 0x0000fffc -_0804B9F0: .4byte 0x00001cdc -_0804B9F4: - lsls r0, r4, 2 - ldr r5, _0804BBE8 - add r5, sp - ldr r5, [r5] - adds r0, r5, r0 - ldr r2, [r0] - adds r0, r2, 0x1 - ldr r1, _0804BBEC - add r1, sp - ldr r1, [r1] - ldr r3, [r1] - adds r6, r3, 0x1 - adds r4, 0x1 - mov r8, r4 - lsls r1, r4, 2 - adds r1, r5, r1 - ldr r1, [r1] - subs r1, r2 - subs r1, 0x3 - ldr r5, _0804BBF0 - add r5, sp - ldr r5, [r5] - lsls r2, r5, 2 - ldr r4, _0804BBF4 - add r4, sp - ldr r4, [r4] - adds r2, r4, r2 - ldr r4, [r2] - subs r4, r3 - subs r4, 0x3 - adds r1, r0, r1 - bl DungeonRandRange - adds r5, r0, 0 - adds r4, r6, r4 - adds r0, r6, 0 - adds r1, r4, 0 - bl DungeonRandRange - adds r4, r0, 0 - strh r5, [r7] - adds r0, r5, 0x1 - strh r0, [r7, 0x4] - strh r4, [r7, 0x2] - adds r0, r4, 0x1 - strh r0, [r7, 0x6] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r1, [r0] - ldr r3, _0804BBF8 - adds r2, r3, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0xFF - strb r1, [r0, 0x9] -_0804BA72: - mov r4, r8 - cmp r4, 0x6 - bge _0804BA7A - b _0804B898 -_0804BA7A: - ldr r4, _0804BBF0 - add r4, sp - ldr r4, [r4] - ldr r5, _0804BBFC - add r5, sp - str r4, [r5] - cmp r4, 0x4 - bge _0804BA8C - b _0804B85C -_0804BA8C: - add r1, sp, 0x8 - movs r6, 0 - movs r0, 0x1 - strb r0, [r1, 0x16] - ldr r1, _0804BC00 - add r1, sp - strb r0, [r1] - movs r1, 0xFF - lsls r1, 1 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC04 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC08 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC0C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC10 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC14 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC18 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC1C - add r1, sp - strb r0, [r1] - add r1, sp, 0x8 - strb r0, [r1, 0x14] - ldr r5, _0804BC20 - add r5, sp - ldr r5, [r5] - strb r0, [r5] - ldr r1, _0804BC24 - add r1, sp - ldr r1, [r1] - strb r0, [r1] - ldr r2, _0804BC28 - add r2, sp - ldr r2, [r2] - strb r0, [r2] - movs r3, 0xE6 - lsls r3, 5 - add r3, sp - ldr r3, [r3] - strb r0, [r3] - ldr r4, _0804BC2C - add r4, sp - ldr r4, [r4] - strb r0, [r4] - ldr r5, _0804BC30 - add r5, sp - ldr r5, [r5] - strb r0, [r5] - ldr r1, _0804BC34 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC38 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC3C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC40 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC44 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC48 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC4C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC50 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC54 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC58 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC5C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC60 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC64 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC68 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC6C - add r1, sp - strb r0, [r1] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - movs r4, 0xE5 - lsls r4, 5 - add r4, sp - ldr r3, [r4] - bl sub_804D5B0 - ldr r5, _0804BC70 - add r5, sp - ldr r4, _0804BC74 - add r4, sp - str r4, [sp] - str r6, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804D8C8 - str r4, [sp] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804E590 - ldr r0, _0804BC78 - movs r5, 0 - ldrsh r3, [r0, r5] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804EBC8 - ldr r0, _0804BC7C - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804EEE4 - movs r2, 0xE5 - lsls r2, 5 - add r2, sp - ldr r2, [r2] - ldrb r3, [r2, 0x13] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804CBEC - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804E03C - movs r3, 0xE7 - lsls r3, 5 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804BBE8: .4byte 0x00001cac -_0804BBEC: .4byte 0x00001cb8 -_0804BBF0: .4byte 0x00001ccc -_0804BBF4: .4byte 0x00001cb4 -_0804BBF8: .4byte 0x0000fffc -_0804BBFC: .4byte 0x00001ca4 -_0804BC00: .4byte 0x000001fd -_0804BC04: .4byte 0x000003dd -_0804BC08: .4byte 0x000003de -_0804BC0C: .4byte 0x000005bd -_0804BC10: .4byte 0x000005be -_0804BC14: .4byte 0x0000079d -_0804BC18: .4byte 0x0000079e -_0804BC1C: .4byte 0x0000097d -_0804BC20: .4byte 0x00001cd4 -_0804BC24: .4byte 0x00001cd8 -_0804BC28: .4byte 0x00001cbc -_0804BC2C: .4byte 0x00001cc4 -_0804BC30: .4byte 0x00001cc8 -_0804BC34: .4byte 0x0000025d -_0804BC38: .4byte 0x0000025e -_0804BC3C: .4byte 0x0000043d -_0804BC40: .4byte 0x0000043e -_0804BC44: .4byte 0x0000061d -_0804BC48: .4byte 0x0000061e -_0804BC4C: .4byte 0x000007fd -_0804BC50: .4byte 0x000007fe -_0804BC54: .4byte 0x000009dd -_0804BC58: .4byte 0x0000097c -_0804BC5C: .4byte 0x0000099b -_0804BC60: .4byte 0x0000099c -_0804BC64: .4byte 0x000009bb -_0804BC68: .4byte 0x000009bc -_0804BC6C: .4byte 0x000009db -_0804BC70: .4byte 0x00001c28 -_0804BC74: .4byte 0x00001c64 -_0804BC78: .4byte gUnknown_202F1B0 -_0804BC7C: .4byte gUnknown_202F1B2 - thumb_func_end sub_804B72C - - thumb_func_start sub_804BC80 -sub_804BC80: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804BED0 - add sp, r4 - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - str r0, [r1] - movs r4, 0x1 - movs r5, 0 - ldr r1, _0804BED4 - add r1, sp - str r5, [r1] - movs r0, 0xB - str r0, [r1, 0x4] - movs r0, 0x16 - str r0, [r1, 0x8] - movs r0, 0x21 - str r0, [r1, 0xC] - movs r0, 0x2C - str r0, [r1, 0x10] - movs r0, 0x38 - str r0, [r1, 0x14] - ldr r1, _0804BED8 - add r1, sp - str r4, [r1] - movs r0, 0x9 - str r0, [r1, 0x4] - movs r0, 0x10 - str r0, [r1, 0x8] - movs r0, 0x17 - str r0, [r1, 0xC] - movs r0, 0x1F - str r0, [r1, 0x10] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804D084 - add r6, sp, 0x70 - add r1, sp, 0x68 - add r0, sp, 0x8 - movs r3, 0xF0 - lsls r3, 1 - movs r2, 0x5 -_0804BCE0: - strb r4, [r0, 0xA] - strb r4, [r1, 0xA] - adds r1, r3 - adds r0, r3 - subs r2, 0x1 - cmp r2, 0 - bne _0804BCE0 - movs r3, 0x5 - subs r3, 0x1 - movs r2, 0x4 - cmp r2, 0 - beq _0804BD1A - lsls r0, r3, 4 - subs r0, r3 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - add r1, sp, 0x8 - mov r10, r2 -_0804BD06: - strb r4, [r1, 0xA] - strb r4, [r0, 0xA] - adds r0, 0x20 - adds r1, 0x20 - movs r2, 0x1 - negs r2, r2 - add r10, r2 - mov r2, r10 - cmp r2, 0 - bne _0804BD06 -_0804BD1A: - movs r2, 0x1 - cmp r2, r3 - bge _0804BD58 - movs r1, 0x3 -_0804BD22: - adds r4, r2, 0x1 - ldr r0, _0804BEDC - add r0, sp - str r4, [r0] - cmp r1, 0x1 - ble _0804BD4E - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r0, 0x20 - subs r2, r1, 0x1 - mov r10, r2 -_0804BD3E: - strb r5, [r0, 0xA] - adds r0, 0x20 - movs r4, 0x1 - negs r4, r4 - add r10, r4 - mov r2, r10 - cmp r2, 0 - bne _0804BD3E -_0804BD4E: - ldr r4, _0804BEDC - add r4, sp - ldr r2, [r4] - cmp r2, r3 - blt _0804BD22 -_0804BD58: - add r0, sp, 0x8 - movs r1, 0x1 - strb r1, [r0, 0x8] - movs r0, 0xF2 - lsls r0, 3 - add r0, sp - strb r1, [r0] - strb r1, [r6] - movs r0, 0xFE - lsls r0, 3 - add r0, sp - strb r1, [r0] - movs r5, 0 - ldr r6, _0804BEE0 - add r6, sp - str r5, [r6] - mov r10, r5 - cmp r5, 0x4 - blt _0804BD80 - b _0804BFAC -_0804BD80: - movs r0, 0x4 - movs r1, 0xE6 - lsls r1, 5 - add r1, sp - str r0, [r1] -_0804BD8A: - movs r2, 0 - cmp r2, 0x5 - blt _0804BD92 - b _0804BF94 -_0804BD92: - ldr r3, _0804BED4 - add r3, sp - ldr r4, _0804BEE4 - add r4, sp - str r3, [r4] - ldr r5, _0804BED8 - add r5, sp - ldr r6, _0804BEE8 - add r6, sp - str r5, [r6] - mov r1, r10 - lsls r0, r1, 2 - adds r0, r5, r0 - ldr r3, _0804BEEC - add r3, sp - str r0, [r3] -_0804BDB2: - lsls r0, r2, 4 - subs r0, r2 - add r0, r10 - lsls r0, 5 - mov r7, sp - adds r7, r0 - adds r7, 0x8 - ldrb r0, [r7, 0x8] - adds r4, r2, 0x1 - ldr r5, _0804BEDC - add r5, sp - str r4, [r5] - cmp r0, 0 - beq _0804BDD0 - b _0804BF88 -_0804BDD0: - ldrb r0, [r7, 0xA] - cmp r0, 0 - bne _0804BDD8 - b _0804BF00 -_0804BDD8: - lsls r0, r2, 2 - ldr r6, _0804BEE4 - add r6, sp - ldr r6, [r6] - adds r0, r6, r0 - ldr r1, [r0] - adds r0, r1, 0x2 - mov r9, r0 - ldr r3, _0804BEEC - add r3, sp - ldr r3, [r3] - ldr r2, [r3] - adds r4, r2, 0x2 - ldr r5, _0804BEF0 - add r5, sp - str r4, [r5] - ldr r6, _0804BEDC - add r6, sp - ldr r6, [r6] - lsls r0, r6, 2 - ldr r3, _0804BEE4 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r4, [r0] - subs r4, r1 - subs r4, 0x3 - ldr r5, _0804BEE8 - add r5, sp - ldr r5, [r5] - movs r6, 0xE6 - lsls r6, 5 - add r6, sp - ldr r6, [r6] - adds r0, r5, r6 - ldr r5, [r0] - subs r5, r2 - subs r5, 0x3 - movs r0, 0x5 - adds r1, r4, 0 - bl DungeonRandRange - mov r8, r0 - movs r0, 0x4 - adds r1, r5, 0 - bl DungeonRandRange - adds r6, r0, 0 - mov r0, r8 - subs r4, r0 - adds r0, r4, 0 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r9 - subs r5, r6 - adds r0, r5, 0 - bl DungeonRandInt - ldr r2, _0804BEF0 - add r2, sp - ldr r1, [r2] - adds r1, r0 - mov r9, r1 - mov r5, r8 - adds r3, r4, r5 - add r6, r9 - strh r4, [r7] - strh r3, [r7, 0x4] - strh r1, [r7, 0x2] - strh r6, [r7, 0x6] - ldr r1, _0804BEE0 - add r1, sp - ldr r0, [r1] - adds r0, 0x1 - ldr r1, _0804BEF4 - add r1, sp - str r0, [r1] - cmp r4, r3 - bge _0804BEC0 -_0804BE78: - mov r5, r9 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804BEBA - ldr r2, _0804BEF8 - mov r8, r2 -_0804BE84: - adds r0, r4, 0 - adds r1, r5, 0 - ldr r2, _0804BEFC - add r2, sp - str r3, [r2] - bl GetTileSafe - ldrh r1, [r0] - mov r2, r8 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileSafe - ldr r1, _0804BEE0 - add r1, sp - ldrb r1, [r1] - strb r1, [r0, 0x9] - adds r5, 0x1 - ldr r2, _0804BEFC - add r2, sp - ldr r3, [r2] - cmp r5, r6 - blt _0804BE84 -_0804BEBA: - adds r4, r7, 0 - cmp r4, r3 - blt _0804BE78 -_0804BEC0: - ldr r3, _0804BEF4 - add r3, sp - ldr r3, [r3] - ldr r4, _0804BEE0 - add r4, sp - str r3, [r4] - b _0804BF88 - .align 2, 0 -_0804BED0: .4byte 0xffffe338 -_0804BED4: .4byte 0x00001c28 -_0804BED8: .4byte 0x00001c64 -_0804BEDC: .4byte 0x00001cb8 -_0804BEE0: .4byte 0x00001ca4 -_0804BEE4: .4byte 0x00001ca8 -_0804BEE8: .4byte 0x00001cb0 -_0804BEEC: .4byte 0x00001cb4 -_0804BEF0: .4byte 0x00001cac -_0804BEF4: .4byte 0x00001cbc -_0804BEF8: .4byte 0x0000fffc -_0804BEFC: .4byte 0x00001cc4 -_0804BF00: - lsls r0, r2, 2 - ldr r4, _0804C080 - add r4, sp - ldr r4, [r4] - adds r0, r4, r0 - ldr r2, [r0] - adds r0, r2, 0x1 - ldr r5, _0804C084 - add r5, sp - ldr r5, [r5] - ldr r3, [r5] - adds r6, r3, 0x1 - mov r8, r6 - ldr r4, _0804C088 - add r4, sp - ldr r4, [r4] - lsls r1, r4, 2 - ldr r5, _0804C080 - add r5, sp - ldr r5, [r5] - adds r1, r5, r1 - ldr r1, [r1] - subs r1, r2 - subs r1, 0x3 - ldr r6, _0804C08C - add r6, sp - ldr r6, [r6] - movs r4, 0xE6 - lsls r4, 5 - add r4, sp - ldr r4, [r4] - adds r2, r6, r4 - ldr r4, [r2] - subs r4, r3 - subs r4, 0x3 - adds r1, r0, r1 - bl DungeonRandRange - adds r5, r0, 0 - add r4, r8 - mov r0, r8 - adds r1, r4, 0 - bl DungeonRandRange - adds r4, r0, 0 - strh r5, [r7] - adds r0, r5, 0x1 - strh r0, [r7, 0x4] - strh r4, [r7, 0x2] - adds r0, r4, 0x1 - strh r0, [r7, 0x6] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r1, [r0] - ldr r6, _0804C090 - adds r2, r6, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0xFF - strb r1, [r0, 0x9] -_0804BF88: - ldr r0, _0804C088 - add r0, sp - ldr r2, [r0] - cmp r2, 0x5 - bge _0804BF94 - b _0804BDB2 -_0804BF94: - movs r2, 0xE6 - lsls r2, 5 - add r2, sp - ldr r1, [r2] - adds r1, 0x4 - str r1, [r2] - movs r3, 0x1 - add r10, r3 - mov r4, r10 - cmp r4, 0x4 - bge _0804BFAC - b _0804BD8A -_0804BFAC: - movs r2, 0x1 - movs r1, 0x1 - movs r3, 0xF - add r4, sp, 0x1C -_0804BFB4: - movs r5, 0 - mov r10, r5 - lsls r0, r3, 5 - adds r0, r4 -_0804BFBC: - strb r1, [r0] - strb r1, [r0, 0x1F] - adds r0, 0x20 - movs r6, 0x1 - add r10, r6 - mov r5, r10 - cmp r5, 0x2 - ble _0804BFBC - movs r0, 0xF0 - lsls r0, 1 - adds r3, 0xF - adds r2, 0x1 - cmp r2, 0x3 - ble _0804BFB4 - mov r10, r6 - movs r5, 0x1 - adds r4, r0, 0 - mov r6, sp - adds r6, r4 - adds r6, 0x8 -_0804BFE4: - movs r2, 0 - mov r1, r10 - lsls r0, r1, 5 - mov r3, r10 - adds r3, 0x1 - adds r1, r0, r6 - add r0, sp - adds r0, 0x8 -_0804BFF4: - strb r5, [r0, 0x16] - strb r5, [r1, 0x15] - adds r1, r4 - adds r0, r4 - adds r2, 0x1 - cmp r2, 0x3 - ble _0804BFF4 - mov r10, r3 - cmp r3, 0x2 - ble _0804BFE4 - ldr r5, _0804C094 - add r5, sp - ldr r4, _0804C098 - add r4, sp - str r4, [sp] - movs r0, 0x1 - str r0, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804D8C8 - str r4, [sp] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804E590 - ldr r0, _0804C09C - movs r2, 0 - ldrsh r3, [r0, r2] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804EBC8 - ldr r0, _0804C0A0 - movs r4, 0 - ldrsh r3, [r0, r4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804EEE4 - movs r5, 0xE5 - lsls r5, 5 - add r5, sp - ldr r5, [r5] - ldrb r3, [r5, 0x13] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804CBEC - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804E03C - ldr r3, _0804C0A4 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C080: .4byte 0x00001ca8 -_0804C084: .4byte 0x00001cb4 -_0804C088: .4byte 0x00001cb8 -_0804C08C: .4byte 0x00001cb0 -_0804C090: .4byte 0x0000fffc -_0804C094: .4byte 0x00001c28 -_0804C098: .4byte 0x00001c64 -_0804C09C: .4byte gUnknown_202F1B0 -_0804C0A0: .4byte gUnknown_202F1B2 -_0804C0A4: .4byte 0x00001cc8 - thumb_func_end sub_804BC80 - - thumb_func_start sub_804C0A8 -sub_804C0A8: - push {r4-r6,lr} - mov r6, r8 - push {r6} - ldr r4, _0804C17C - add sp, r4 - adds r6, r0, 0 - ldr r4, _0804C180 - add r4, sp - movs r0, 0 - str r0, [r4] - movs r0, 0xB - str r0, [r4, 0x4] - movs r0, 0x16 - str r0, [r4, 0x8] - movs r0, 0x21 - str r0, [r4, 0xC] - movs r0, 0x2C - str r0, [r4, 0x10] - movs r0, 0x38 - str r0, [r4, 0x14] - ldr r5, _0804C184 - add r5, sp - movs r0, 0x4 - str r0, [r5] - movs r0, 0xF - str r0, [r5, 0x4] - movs r0, 0x1 - mov r8, r0 - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804D084 - movs r3, 0x1 - ldrsb r3, [r6, r3] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804D154 - str r5, [sp] - ldrb r0, [r6, 0xD] - str r0, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r4, 0 - bl sub_804D2D0 - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r6, 0 - bl sub_804D5B0 - str r5, [sp] - mov r1, r8 - str r1, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r4, 0 - bl sub_804D8C8 - str r5, [sp] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r4, 0 - bl sub_804E590 - ldr r0, _0804C188 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804EBC8 - ldr r0, _0804C18C - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804EEE4 - ldrb r3, [r6, 0x13] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804CBEC - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804E03C - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0804C17C: .4byte 0xffffe360 -_0804C180: .4byte 0x00001c28 -_0804C184: .4byte 0x00001c64 -_0804C188: .4byte gUnknown_202F1B0 -_0804C18C: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C0A8 - - thumb_func_start sub_804C190 -sub_804C190: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804C2CC - add sp, r4 - mov r10, r0 - ldr r1, _0804C2D0 - add r1, sp - movs r2, 0xB - str r2, [r1] - movs r0, 0x16 - str r0, [r1, 0x4] - movs r0, 0x21 - str r0, [r1, 0x8] - movs r0, 0x2C - str r0, [r1, 0xC] - ldr r1, _0804C2D4 - add r1, sp - movs r0, 0x2 - str r0, [r1] - str r2, [r1, 0x4] - movs r0, 0x14 - str r0, [r1, 0x8] - movs r0, 0x1E - str r0, [r1, 0xC] - movs r0, 0x3 - mov r8, r0 - movs r7, 0x3 - add r0, sp, 0x8 - movs r1, 0x3 - movs r2, 0x3 - bl sub_804D084 - movs r1, 0 - add r5, sp, 0x50 - movs r0, 0x3E - add r0, sp - mov r9, r0 - mov r0, r10 - ldrb r0, [r0, 0xD] - mov r12, r0 -_0804C1E6: - adds r3, r1, 0x1 - cmp r7, 0 - beq _0804C204 - lsls r0, r1, 4 - subs r0, r1 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r1, r7, 0 -_0804C1FA: - strb r2, [r0, 0xA] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C1FA -_0804C204: - adds r1, r3, 0 - cmp r1, r8 - blt _0804C1E6 - add r0, sp, 0x8 - movs r4, 0x1 - strb r4, [r0, 0x8] - add r0, sp, 0x3D0 - strb r4, [r0] - strb r4, [r5] - movs r0, 0x82 - lsls r0, 3 - add r0, sp - strb r4, [r0] - ldr r6, _0804C2D0 - add r6, sp - ldr r5, _0804C2D4 - add r5, sp - str r5, [sp] - mov r1, r12 - str r1, [sp, 0x4] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804D2D0 - mov r0, r9 - strb r4, [r0] - ldr r0, _0804C2D8 - add r0, sp - strb r4, [r0] - ldr r0, _0804C2DC - add r0, sp - strb r4, [r0] - ldr r0, _0804C2E0 - add r0, sp - strb r4, [r0] - add r0, sp, 0x1FC - strb r4, [r0] - ldr r0, _0804C2E4 - add r0, sp - strb r4, [r0] - add r0, sp, 0x21C - strb r4, [r0] - ldr r0, _0804C2E8 - add r0, sp - strb r4, [r0] - str r5, [sp] - str r4, [sp, 0x4] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804D8C8 - str r5, [sp] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804E590 - ldr r0, _0804C2EC - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804EBC8 - ldr r0, _0804C2F0 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804EEE4 - mov r0, r10 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804CBEC - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804E03C - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C2CC: .4byte 0xffffe360 -_0804C2D0: .4byte 0x00001c28 -_0804C2D4: .4byte 0x00001c64 -_0804C2D8: .4byte 0x0000021d -_0804C2DC: .4byte 0x0000021e -_0804C2E0: .4byte 0x000003fd -_0804C2E4: .4byte 0x0000021b -_0804C2E8: .4byte 0x0000023b -_0804C2EC: .4byte gUnknown_202F1B0 -_0804C2F0: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C190 - - thumb_func_start sub_804C2F4 -sub_804C2F4: - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r4, _0804C420 - add sp, r4 - mov r8, r0 - ldr r1, _0804C424 - add r1, sp - movs r0, 0x5 - str r0, [r1] - movs r0, 0xF - str r0, [r1, 0x4] - movs r0, 0x23 - str r0, [r1, 0x8] - movs r0, 0x32 - str r0, [r1, 0xC] - ldr r1, _0804C428 - add r1, sp - movs r0, 0x2 - str r0, [r1] - movs r0, 0xB - str r0, [r1, 0x4] - movs r0, 0x14 - str r0, [r1, 0x8] - movs r0, 0x1E - str r0, [r1, 0xC] - movs r7, 0x3 - movs r6, 0x3 - add r0, sp, 0x8 - movs r1, 0x3 - movs r2, 0x3 - bl sub_804D084 - movs r1, 0 - mov r0, r8 - ldrb r4, [r0, 0xD] -_0804C33C: - adds r3, r1, 0x1 - cmp r6, 0 - beq _0804C35A - lsls r0, r1, 4 - subs r0, r1 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r1, r6, 0 -_0804C350: - strb r2, [r0, 0xA] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C350 -_0804C35A: - adds r1, r3, 0 - cmp r1, r7 - blt _0804C33C - ldr r3, _0804C424 - add r3, sp - ldr r0, _0804C428 - add r0, sp - str r0, [sp] - str r4, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D2D0 - movs r4, 0x1 - ldr r3, _0804C42C - add r3, sp - ldr r0, _0804C430 - add r0, sp - add r2, sp, 0x8 - movs r1, 0x2 -_0804C384: - strb r4, [r2, 0x16] - strb r4, [r0] - strb r4, [r0, 0x1] - strb r4, [r3] - adds r3, 0x20 - adds r0, 0x20 - adds r2, 0x20 - subs r1, 0x1 - cmp r1, 0 - bge _0804C384 - ldr r5, _0804C424 - add r5, sp - ldr r4, _0804C428 - add r4, sp - str r4, [sp] - movs r0, 0x1 - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804D8C8 - movs r0, 0x1 - movs r1, 0 - movs r2, 0x1 - add r3, sp, 0x8 - bl sub_804C43C - movs r0, 0x1 - movs r1, 0 - movs r2, 0x2 - add r3, sp, 0x8 - bl sub_804C43C - str r4, [sp] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804E590 - ldr r0, _0804C434 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EBC8 - ldr r0, _0804C438 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EEE4 - mov r0, r8 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804CBEC - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804E03C - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C420: .4byte 0xffffe360 -_0804C424: .4byte 0x00001c28 -_0804C428: .4byte 0x00001c64 -_0804C42C: .4byte 0x000003dd -_0804C430: .4byte 0x000001fd -_0804C434: .4byte gUnknown_202F1B0 -_0804C438: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C2F4 - - thumb_func_start sub_804C43C -sub_804C43C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - str r0, [sp] - str r3, [sp, 0x4] - lsls r7, r1, 5 - lsls r0, 4 - str r0, [sp, 0xC] - ldr r3, [sp] - subs r0, r3 - lsls r0, 5 - ldr r4, [sp, 0x4] - adds r0, r4 - adds r3, r7, r0 - adds r6, r1, r2 - lsls r1, r6, 5 - adds r2, r1, r0 - movs r5, 0 - ldrsh r1, [r2, r5] - adds r4, r1, 0 - ldrh r0, [r3] - mov r8, r0 - movs r5, 0 - ldrsh r0, [r3, r5] - cmp r1, r0 - ble _0804C478 - mov r4, r8 -_0804C478: - lsls r0, r4, 16 - asrs r0, 16 - str r0, [sp, 0x8] - movs r1, 0x2 - ldrsh r0, [r3, r1] - mov r10, r0 - movs r4, 0x4 - ldrsh r1, [r2, r4] - adds r4, r1, 0 - ldrh r5, [r3, 0x4] - mov r8, r5 - movs r5, 0x4 - ldrsh r0, [r3, r5] - cmp r1, r0 - bge _0804C498 - mov r4, r8 -_0804C498: - lsls r0, r4, 16 - asrs r0, 16 - str r0, [sp, 0x10] - movs r1, 0x6 - ldrsh r0, [r2, r1] - mov r8, r0 - movs r2, 0 - ldrsh r0, [r3, r2] - mov r1, r10 - bl GetTile - ldrb r0, [r0, 0x9] - mov r9, r0 - ldr r5, [sp, 0x8] - str r7, [sp, 0x1C] - ldr r3, [sp, 0xC] - str r3, [sp, 0x18] - str r6, [sp, 0x14] - ldr r4, [sp, 0x10] - cmp r5, r4 - bge _0804C4F2 -_0804C4C2: - mov r4, r10 - adds r6, r5, 0x1 - cmp r10, r8 - bge _0804C4EA - ldr r0, _0804C538 - adds r7, r0, 0 -_0804C4CE: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r1, [r0] - ands r1, r7 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r9 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r8 - blt _0804C4CE -_0804C4EA: - adds r5, r6, 0 - ldr r2, [sp, 0x10] - cmp r5, r2 - blt _0804C4C2 -_0804C4F2: - ldr r3, [sp, 0x18] - ldr r4, [sp] - subs r1, r3, r4 - lsls r1, 5 - ldr r5, [sp, 0x4] - adds r1, r5 - ldr r0, [sp, 0x1C] - adds r2, r0, r1 - movs r3, 0 - mov r4, sp - ldrh r4, [r4, 0x8] - strh r4, [r2] - mov r5, sp - ldrh r5, [r5, 0x10] - strh r5, [r2, 0x4] - mov r0, r10 - strh r0, [r2, 0x2] - mov r4, r8 - strh r4, [r2, 0x6] - ldr r5, [sp, 0x14] - lsls r0, r5, 5 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0, 0x12] - strb r1, [r2, 0x12] - strb r3, [r0, 0xB] - strb r1, [r0, 0x11] - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C538: .4byte 0x0000fffc - thumb_func_end sub_804C43C thumb_func_start sub_804C53C sub_804C53C: diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index a8f99c070..3a10faf66 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -117,7 +117,7 @@ typedef struct UnkDungeonGlobal_unk181E8_sub typedef struct UnkDungeonGlobal_unk1C574 { u8 unk0; - u8 unk1; + s8 unk1; u8 unk2; u8 unk3; u8 unk4; diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 7fcf4b59a..bf5876ffb 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -17,7 +17,8 @@ extern u8 gUnknown_202F1B4; extern u8 gUnknown_202F1AE; extern u8 gUnknown_202F1AD; extern u8 gUnknown_202F1A9; -extern u16 gUnknown_202F1B0; +extern s16 gUnknown_202F1B0; +extern s16 gUnknown_202F1B2; extern s32 gUnknown_202F1C8; extern s32 gUnknown_202F1D0; extern Position gUnknown_202F1D8; @@ -44,8 +45,8 @@ extern void sub_804C9D0(void); extern u8 sub_8043D10(); extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); -extern void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); +void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); void sub_804B634(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); void sub_804B72C(UnkDungeonGlobal_unk1C574 *a0); @@ -968,4 +969,1416 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) } } +// Note: 15 seems to determine the array size, give it a better name and a define. + + +// Size 480 = 32 * 15 + +struct UnkHugeSpStructSubUnk0 +{ + Position unk0; + Position unk4; + u8 unk8; + u8 unk9; + u8 unk10; + u8 unk11; + u8 unk12; + u8 unk13; + u8 unk14; + u8 unk15; + u8 unk16; + u8 unk17; + u8 unk18; + u8 unk19; + u8 unk20; + u8 unk21; + u8 unk22; + u8 unk23; + u8 unk24; + u8 unk25; + u8 unk26; + u8 unk27; + u8 unk28; + u8 unk29; + u8 unk30; + u8 unk31; +}; + +// Size 7200, however this struct is usually put at sp+8, so 8 needs to be added to these fields(in decimal) +struct UnkHugeSpStruct +{ + struct UnkHugeSpStructSubUnk0 unk0[15][15]; +}; + +void sub_804D024(s32 *a0, s32 *a1, s32 x, s32 y); +void sub_804D084(struct UnkHugeSpStruct *a0, s32 x, s32 y); +void sub_804E03C(struct UnkHugeSpStruct *a0, s32 x, s32 y); +void sub_804D534(struct UnkHugeSpStruct *a0, s32 x, s32 y); +void sub_804D154(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); +void sub_804D2D0(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); +void sub_804D8C8(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); +void sub_804E590(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 *a3, s32 *a4); +void sub_804D5B0(struct UnkHugeSpStruct *a0, s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr); +void sub_804F0D0(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); +void sub_804EBC8(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); +void sub_804EEE4(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); +void sub_804CBEC(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); +void sub_804C43C(s32 a0, s32 a1, s32 a2, struct UnkHugeSpStructSubUnk0 sp[15][15]); + +void sub_804B634(s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct UnkHugeSpStruct sp; + s32 unk7200[15]; + s32 unk7260[15]; + + sub_804D024(unk7200, unk7260, x, y); + sub_804D084(&sp, x, y); + sub_804D154(&sp, x, y, unkPtr->unk1); + sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); + sub_804D5B0(&sp, x, y, unkPtr); + sub_804D8C8(&sp, x, y, unk7200, unk7260, 0); + sub_804E590(&sp, x, y, unk7200, unk7260); + sub_804F0D0(&sp, x, y, unkPtr->unk9); + sub_804EBC8(&sp, x, y, gUnknown_202F1B0); + sub_804EEE4(&sp, x, y, gUnknown_202F1B2); + sub_804CBEC(&sp, x, y, unkPtr->unk13); + sub_804E03C(&sp, x, y); + sub_804D534(&sp, x, y); +} + +// Decompile once data structure is better understood + +#ifdef NONMATCHING +void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct UnkHugeSpStruct sp; + + sp.unk7200[0] = 0; + sp.unk7200[1] = 5; + sp.unk7200[3] = 28; + sp.unk7200[5] = 51 + sp.unk7200[6] = 56; + sp.unk7200[2] = 16; + sp.unk7200[4] = 29; + + sp.unk7260[0] = 2; + sp.unk7260[1] = 7; + sp.unk7260[2] = 16; + sp.unk7260[3] = 25; + sp.unk7260[4] = 30; + + sub_804D084(&sp, 6, 4); +} +#else +NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) +{ + asm_unified("push {r4-r7,lr}\n" +" mov r7, r10\n" +" mov r6, r9\n" +" mov r5, r8\n" +" push {r5-r7}\n" +" ldr r4, _0804B9AC\n" +" add sp, r4\n" +" movs r1, 0xE5\n" +" lsls r1, 5\n" +" add r1, sp\n" +" str r0, [r1]\n" +" movs r5, 0\n" +" movs r6, 0x1\n" +" ldr r1, _0804B9B0\n" +" add r1, sp\n" +" str r5, [r1]\n" +" movs r0, 0x5\n" +" str r0, [r1, 0x4]\n" +" movs r0, 0x1C\n" +" str r0, [r1, 0xC]\n" +" movs r0, 0x33\n" +" str r0, [r1, 0x14]\n" +" movs r0, 0x38\n" +" str r0, [r1, 0x18]\n" +" movs r2, 0x10\n" +" str r2, [r1, 0x8]\n" +" movs r0, 0x27\n" +" str r0, [r1, 0x10]\n" +" ldr r1, _0804B9B4\n" +" add r1, sp\n" +" movs r0, 0x2\n" +" str r0, [r1]\n" +" movs r0, 0x7\n" +" str r0, [r1, 0x4]\n" +" str r2, [r1, 0x8]\n" +" movs r0, 0x19\n" +" str r0, [r1, 0xC]\n" +" movs r0, 0x1E\n" +" str r0, [r1, 0x10]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" bl sub_804D084\n" +" mov r2, sp\n" +" adds r2, 0x3B\n" +" ldr r3, _0804B9B8\n" +" add r3, sp\n" +" str r2, [r3]\n" +" mov r4, sp\n" +" adds r4, 0x3C\n" +" ldr r0, _0804B9BC\n" +" add r0, sp\n" +" str r4, [r0]\n" +" mov r1, sp\n" +" adds r1, 0x5B\n" +" ldr r2, _0804B9C0\n" +" add r2, sp\n" +" str r1, [r2]\n" +" mov r3, sp\n" +" adds r3, 0x5C\n" +" movs r4, 0xE6\n" +" lsls r4, 5\n" +" add r4, sp\n" +" str r3, [r4]\n" +" mov r0, sp\n" +" adds r0, 0x7B\n" +" ldr r1, _0804B9C4\n" +" add r1, sp\n" +" str r0, [r1]\n" +" mov r2, sp\n" +" adds r2, 0x7E\n" +" ldr r3, _0804B9C8\n" +" add r3, sp\n" +" str r2, [r3]\n" +" add r1, sp, 0x68\n" +" add r0, sp, 0x8\n" +" movs r2, 0xF0\n" +" lsls r2, 1\n" +" movs r4, 0x6\n" +"_0804B7CC:\n" +" strb r5, [r0, 0xA]\n" +" strb r5, [r1, 0xA]\n" +" adds r1, r2\n" +" adds r0, r2\n" +" subs r4, 0x1\n" +" cmp r4, 0\n" +" bne _0804B7CC\n" +" movs r2, 0x6\n" +" subs r2, 0x1\n" +" movs r4, 0x4\n" +" cmp r4, 0\n" +" beq _0804B80C\n" +" lsls r0, r2, 4\n" +" subs r0, r2\n" +" lsls r0, 5\n" +" add r0, sp\n" +" adds r0, 0x8\n" +" add r1, sp, 0x8\n" +" ldr r3, _0804B9CC\n" +" add r3, sp\n" +" str r4, [r3]\n" +"_0804B7F6:\n" +" strb r5, [r1, 0xA]\n" +" strb r5, [r0, 0xA]\n" +" adds r0, 0x20\n" +" adds r1, 0x20\n" +" ldr r3, _0804B9CC\n" +" add r3, sp\n" +" ldr r4, [r3]\n" +" subs r4, 0x1\n" +" str r4, [r3]\n" +" cmp r4, 0\n" +" bne _0804B7F6\n" +"_0804B80C:\n" +" movs r4, 0x1\n" +" cmp r4, r2\n" +" bge _0804B848\n" +" movs r1, 0x3\n" +"_0804B814:\n" +" adds r5, r4, 0x1\n" +" mov r8, r5\n" +" cmp r1, 0x1\n" +" ble _0804B842\n" +" lsls r0, r4, 4\n" +" subs r0, r4\n" +" lsls r0, 5\n" +" add r0, sp\n" +" adds r0, 0x8\n" +" adds r0, 0x20\n" +" subs r3, r1, 0x1\n" +" ldr r4, _0804B9CC\n" +" add r4, sp\n" +" str r3, [r4]\n" +"_0804B830:\n" +" strb r6, [r0, 0xA]\n" +" adds r0, 0x20\n" +" ldr r3, _0804B9CC\n" +" add r3, sp\n" +" ldr r5, [r3]\n" +" subs r5, 0x1\n" +" str r5, [r3]\n" +" cmp r5, 0\n" +" bne _0804B830\n" +"_0804B842:\n" +" mov r4, r8\n" +" cmp r4, r2\n" +" blt _0804B814\n" +"_0804B848:\n" +" movs r4, 0\n" +" ldr r5, _0804B9D0\n" +" add r5, sp\n" +" str r4, [r5]\n" +" ldr r0, _0804B9CC\n" +" add r0, sp\n" +" str r4, [r0]\n" +" cmp r4, 0x4\n" +" blt _0804B85C\n" +" b _0804BA8C\n" +"_0804B85C:\n" +" movs r4, 0\n" +" ldr r2, _0804B9CC\n" +" add r2, sp\n" +" ldr r1, [r2]\n" +" adds r1, 0x1\n" +" ldr r2, _0804B9D4\n" +" add r2, sp\n" +" str r1, [r2]\n" +" cmp r4, 0x6\n" +" blt _0804B872\n" +" b _0804BA7A\n" +"_0804B872:\n" +" ldr r3, _0804B9B0\n" +" add r3, sp\n" +" ldr r5, _0804B9D8\n" +" add r5, sp\n" +" str r3, [r5]\n" +" ldr r0, _0804B9B4\n" +" add r0, sp\n" +" ldr r1, _0804B9DC\n" +" add r1, sp\n" +" str r0, [r1]\n" +" ldr r2, _0804B9CC\n" +" add r2, sp\n" +" ldr r2, [r2]\n" +" lsls r0, r2, 2\n" +" ldr r3, [r1]\n" +" adds r0, r3, r0\n" +" ldr r3, _0804B9E0\n" +" add r3, sp\n" +" str r0, [r3]\n" +"_0804B898:\n" +" lsls r0, r4, 4\n" +" subs r0, r4\n" +" ldr r5, _0804B9CC\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" adds r0, r5\n" +" lsls r0, 5\n" +" mov r7, sp\n" +" adds r7, r0\n" +" adds r7, 0x8\n" +" ldrb r0, [r7, 0xA]\n" +" cmp r0, 0\n" +" bne _0804B8B4\n" +" b _0804B9F4\n" +"_0804B8B4:\n" +" lsls r0, r4, 2\n" +" ldr r1, _0804B9D8\n" +" add r1, sp\n" +" ldr r1, [r1]\n" +" adds r0, r1, r0\n" +" ldr r1, [r0]\n" +" adds r2, r1, 0x2\n" +" mov r10, r2\n" +" ldr r3, _0804B9E0\n" +" add r3, sp\n" +" ldr r3, [r3]\n" +" ldr r2, [r3]\n" +" adds r5, r2, 0x2\n" +" ldr r0, _0804B9E4\n" +" add r0, sp\n" +" str r5, [r0]\n" +" adds r4, 0x1\n" +" mov r9, r4\n" +" lsls r0, r4, 2\n" +" ldr r3, _0804B9D8\n" +" add r3, sp\n" +" ldr r3, [r3]\n" +" adds r0, r3, r0\n" +" ldr r4, [r0]\n" +" subs r4, r1\n" +" subs r4, 0x3\n" +" ldr r5, _0804B9D4\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" lsls r0, r5, 2\n" +" ldr r1, _0804B9DC\n" +" add r1, sp\n" +" ldr r1, [r1]\n" +" adds r0, r1, r0\n" +" ldr r5, [r0]\n" +" subs r5, r2\n" +" subs r5, 0x3\n" +" movs r0, 0x5\n" +" adds r1, r4, 0\n" +" bl DungeonRandRange\n" +" mov r8, r0\n" +" movs r0, 0x4\n" +" adds r1, r5, 0\n" +" bl DungeonRandRange\n" +" adds r6, r0, 0\n" +" mov r2, r8\n" +" subs r4, r2\n" +" adds r0, r4, 0\n" +" bl DungeonRandInt\n" +" adds r4, r0, 0\n" +" add r4, r10\n" +" subs r5, r6\n" +" adds r0, r5, 0\n" +" bl DungeonRandInt\n" +" ldr r5, _0804B9E4\n" +" add r5, sp\n" +" ldr r3, [r5]\n" +" adds r3, r0\n" +" mov r10, r3\n" +" mov r0, r8\n" +" adds r3, r4, r0\n" +" add r6, r10\n" +" strh r4, [r7]\n" +" strh r3, [r7, 0x4]\n" +" mov r1, r10\n" +" strh r1, [r7, 0x2]\n" +" strh r6, [r7, 0x6]\n" +" mov r8, r9\n" +" ldr r5, _0804B9D0\n" +" add r5, sp\n" +" ldr r2, [r5]\n" +" adds r2, 0x1\n" +" ldr r5, _0804B9E8\n" +" add r5, sp\n" +" str r2, [r5]\n" +" cmp r4, r3\n" +" bge _0804B99E\n" +"_0804B956:\n" +" mov r5, r10\n" +" adds r7, r4, 0x1\n" +" cmp r5, r6\n" +" bge _0804B998\n" +" ldr r0, _0804B9EC\n" +" mov r9, r0\n" +"_0804B962:\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" ldr r2, _0804B9F0\n" +" add r2, sp\n" +" str r3, [r2]\n" +" bl GetTileSafe\n" +" ldrh r1, [r0]\n" +" mov r2, r9\n" +" ands r1, r2\n" +" movs r2, 0x1\n" +" orrs r1, r2\n" +" strh r1, [r0]\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" bl GetTileSafe\n" +" ldr r1, _0804B9D0\n" +" add r1, sp\n" +" ldrb r1, [r1]\n" +" strb r1, [r0, 0x9]\n" +" adds r5, 0x1\n" +" ldr r2, _0804B9F0\n" +" add r2, sp\n" +" ldr r3, [r2]\n" +" cmp r5, r6\n" +" blt _0804B962\n" +"_0804B998:\n" +" adds r4, r7, 0\n" +" cmp r4, r3\n" +" blt _0804B956\n" +"_0804B99E:\n" +" ldr r3, _0804B9E8\n" +" add r3, sp\n" +" ldr r3, [r3]\n" +" ldr r4, _0804B9D0\n" +" add r4, sp\n" +" str r3, [r4]\n" +" b _0804BA72\n" +" .align 2, 0\n" +"_0804B9AC: .4byte 0xffffe320\n" +"_0804B9B0: .4byte 0x00001c28\n" +"_0804B9B4: .4byte 0x00001c64\n" +"_0804B9B8: .4byte 0x00001cd4\n" +"_0804B9BC: .4byte 0x00001cd8\n" +"_0804B9C0: .4byte 0x00001cbc\n" +"_0804B9C4: .4byte 0x00001cc4\n" +"_0804B9C8: .4byte 0x00001cc8\n" +"_0804B9CC: .4byte 0x00001ca4\n" +"_0804B9D0: .4byte 0x00001ca8\n" +"_0804B9D4: .4byte 0x00001ccc\n" +"_0804B9D8: .4byte 0x00001cac\n" +"_0804B9DC: .4byte 0x00001cb4\n" +"_0804B9E0: .4byte 0x00001cb8\n" +"_0804B9E4: .4byte 0x00001cb0\n" +"_0804B9E8: .4byte 0x00001cd0\n" +"_0804B9EC: .4byte 0x0000fffc\n" +"_0804B9F0: .4byte 0x00001cdc\n" +"_0804B9F4:\n" +" lsls r0, r4, 2\n" +" ldr r5, _0804BBE8\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" adds r0, r5, r0\n" +" ldr r2, [r0]\n" +" adds r0, r2, 0x1\n" +" ldr r1, _0804BBEC\n" +" add r1, sp\n" +" ldr r1, [r1]\n" +" ldr r3, [r1]\n" +" adds r6, r3, 0x1\n" +" adds r4, 0x1\n" +" mov r8, r4\n" +" lsls r1, r4, 2\n" +" adds r1, r5, r1\n" +" ldr r1, [r1]\n" +" subs r1, r2\n" +" subs r1, 0x3\n" +" ldr r5, _0804BBF0\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" lsls r2, r5, 2\n" +" ldr r4, _0804BBF4\n" +" add r4, sp\n" +" ldr r4, [r4]\n" +" adds r2, r4, r2\n" +" ldr r4, [r2]\n" +" subs r4, r3\n" +" subs r4, 0x3\n" +" adds r1, r0, r1\n" +" bl DungeonRandRange\n" +" adds r5, r0, 0\n" +" adds r4, r6, r4\n" +" adds r0, r6, 0\n" +" adds r1, r4, 0\n" +" bl DungeonRandRange\n" +" adds r4, r0, 0\n" +" strh r5, [r7]\n" +" adds r0, r5, 0x1\n" +" strh r0, [r7, 0x4]\n" +" strh r4, [r7, 0x2]\n" +" adds r0, r4, 0x1\n" +" strh r0, [r7, 0x6]\n" +" adds r0, r5, 0\n" +" adds r1, r4, 0\n" +" bl GetTileSafe\n" +" ldrh r1, [r0]\n" +" ldr r3, _0804BBF8\n" +" adds r2, r3, 0\n" +" ands r1, r2\n" +" movs r2, 0x1\n" +" orrs r1, r2\n" +" strh r1, [r0]\n" +" adds r0, r5, 0\n" +" adds r1, r4, 0\n" +" bl GetTileSafe\n" +" movs r1, 0xFF\n" +" strb r1, [r0, 0x9]\n" +"_0804BA72:\n" +" mov r4, r8\n" +" cmp r4, 0x6\n" +" bge _0804BA7A\n" +" b _0804B898\n" +"_0804BA7A:\n" +" ldr r4, _0804BBF0\n" +" add r4, sp\n" +" ldr r4, [r4]\n" +" ldr r5, _0804BBFC\n" +" add r5, sp\n" +" str r4, [r5]\n" +" cmp r4, 0x4\n" +" bge _0804BA8C\n" +" b _0804B85C\n" +"_0804BA8C:\n" +" add r1, sp, 0x8\n" +" movs r6, 0\n" +" movs r0, 0x1\n" +" strb r0, [r1, 0x16]\n" +" ldr r1, _0804BC00\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" movs r1, 0xFF\n" +" lsls r1, 1\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC04\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC08\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC0C\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC10\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC14\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC18\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC1C\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" add r1, sp, 0x8\n" +" strb r0, [r1, 0x14]\n" +" ldr r5, _0804BC20\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" strb r0, [r5]\n" +" ldr r1, _0804BC24\n" +" add r1, sp\n" +" ldr r1, [r1]\n" +" strb r0, [r1]\n" +" ldr r2, _0804BC28\n" +" add r2, sp\n" +" ldr r2, [r2]\n" +" strb r0, [r2]\n" +" movs r3, 0xE6\n" +" lsls r3, 5\n" +" add r3, sp\n" +" ldr r3, [r3]\n" +" strb r0, [r3]\n" +" ldr r4, _0804BC2C\n" +" add r4, sp\n" +" ldr r4, [r4]\n" +" strb r0, [r4]\n" +" ldr r5, _0804BC30\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" strb r0, [r5]\n" +" ldr r1, _0804BC34\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC38\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC3C\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC40\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC44\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC48\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC4C\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC50\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC54\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC58\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC5C\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC60\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC64\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC68\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" ldr r1, _0804BC6C\n" +" add r1, sp\n" +" strb r0, [r1]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" movs r4, 0xE5\n" +" lsls r4, 5\n" +" add r4, sp\n" +" ldr r3, [r4]\n" +" bl sub_804D5B0\n" +" ldr r5, _0804BC70\n" +" add r5, sp\n" +" ldr r4, _0804BC74\n" +" add r4, sp\n" +" str r4, [sp]\n" +" str r6, [sp, 0x4]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" adds r3, r5, 0\n" +" bl sub_804D8C8\n" +" str r4, [sp]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" adds r3, r5, 0\n" +" bl sub_804E590\n" +" ldr r0, _0804BC78\n" +" movs r5, 0\n" +" ldrsh r3, [r0, r5]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" bl sub_804EBC8\n" +" ldr r0, _0804BC7C\n" +" movs r1, 0\n" +" ldrsh r3, [r0, r1]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" bl sub_804EEE4\n" +" movs r2, 0xE5\n" +" lsls r2, 5\n" +" add r2, sp\n" +" ldr r2, [r2]\n" +" ldrb r3, [r2, 0x13]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" bl sub_804CBEC\n" +" add r0, sp, 0x8\n" +" movs r1, 0x6\n" +" movs r2, 0x4\n" +" bl sub_804E03C\n" +" movs r3, 0xE7\n" +" lsls r3, 5\n" +" add sp, r3\n" +" pop {r3-r5}\n" +" mov r8, r3\n" +" mov r9, r4\n" +" mov r10, r5\n" +" pop {r4-r7}\n" +" pop {r0}\n" +" bx r0\n" +" .align 2, 0\n" +"_0804BBE8: .4byte 0x00001cac\n" +"_0804BBEC: .4byte 0x00001cb8\n" +"_0804BBF0: .4byte 0x00001ccc\n" +"_0804BBF4: .4byte 0x00001cb4\n" +"_0804BBF8: .4byte 0x0000fffc\n" +"_0804BBFC: .4byte 0x00001ca4\n" +"_0804BC00: .4byte 0x000001fd\n" +"_0804BC04: .4byte 0x000003dd\n" +"_0804BC08: .4byte 0x000003de\n" +"_0804BC0C: .4byte 0x000005bd\n" +"_0804BC10: .4byte 0x000005be\n" +"_0804BC14: .4byte 0x0000079d\n" +"_0804BC18: .4byte 0x0000079e\n" +"_0804BC1C: .4byte 0x0000097d\n" +"_0804BC20: .4byte 0x00001cd4\n" +"_0804BC24: .4byte 0x00001cd8\n" +"_0804BC28: .4byte 0x00001cbc\n" +"_0804BC2C: .4byte 0x00001cc4\n" +"_0804BC30: .4byte 0x00001cc8\n" +"_0804BC34: .4byte 0x0000025d\n" +"_0804BC38: .4byte 0x0000025e\n" +"_0804BC3C: .4byte 0x0000043d\n" +"_0804BC40: .4byte 0x0000043e\n" +"_0804BC44: .4byte 0x0000061d\n" +"_0804BC48: .4byte 0x0000061e\n" +"_0804BC4C: .4byte 0x000007fd\n" +"_0804BC50: .4byte 0x000007fe\n" +"_0804BC54: .4byte 0x000009dd\n" +"_0804BC58: .4byte 0x0000097c\n" +"_0804BC5C: .4byte 0x0000099b\n" +"_0804BC60: .4byte 0x0000099c\n" +"_0804BC64: .4byte 0x000009bb\n" +"_0804BC68: .4byte 0x000009bc\n" +"_0804BC6C: .4byte 0x000009db\n" +"_0804BC70: .4byte 0x00001c28\n" +"_0804BC74: .4byte 0x00001c64\n" +"_0804BC78: .4byte gUnknown_202F1B0\n" +"_0804BC7C: .4byte gUnknown_202F1B2"); +} +#endif // NONMATCHING + +#ifdef NONMATCHING +void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) +{ + +} +#else +NAKED void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) +{ + asm_unified("push {r4-r7,lr}\n" +" mov r7, r10\n" +" mov r6, r9\n" +" mov r5, r8\n" +" push {r5-r7}\n" +" ldr r4, _0804BED0\n" +" add sp, r4\n" +" movs r1, 0xE5\n" +" lsls r1, 5\n" +" add r1, sp\n" +" str r0, [r1]\n" +" movs r4, 0x1\n" +" movs r5, 0\n" +" ldr r1, _0804BED4\n" +" add r1, sp\n" +" str r5, [r1]\n" +" movs r0, 0xB\n" +" str r0, [r1, 0x4]\n" +" movs r0, 0x16\n" +" str r0, [r1, 0x8]\n" +" movs r0, 0x21\n" +" str r0, [r1, 0xC]\n" +" movs r0, 0x2C\n" +" str r0, [r1, 0x10]\n" +" movs r0, 0x38\n" +" str r0, [r1, 0x14]\n" +" ldr r1, _0804BED8\n" +" add r1, sp\n" +" str r4, [r1]\n" +" movs r0, 0x9\n" +" str r0, [r1, 0x4]\n" +" movs r0, 0x10\n" +" str r0, [r1, 0x8]\n" +" movs r0, 0x17\n" +" str r0, [r1, 0xC]\n" +" movs r0, 0x1F\n" +" str r0, [r1, 0x10]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x5\n" +" movs r2, 0x4\n" +" bl sub_804D084\n" +" add r6, sp, 0x70\n" +" add r1, sp, 0x68\n" +" add r0, sp, 0x8\n" +" movs r3, 0xF0\n" +" lsls r3, 1\n" +" movs r2, 0x5\n" +"_0804BCE0:\n" +" strb r4, [r0, 0xA]\n" +" strb r4, [r1, 0xA]\n" +" adds r1, r3\n" +" adds r0, r3\n" +" subs r2, 0x1\n" +" cmp r2, 0\n" +" bne _0804BCE0\n" +" movs r3, 0x5\n" +" subs r3, 0x1\n" +" movs r2, 0x4\n" +" cmp r2, 0\n" +" beq _0804BD1A\n" +" lsls r0, r3, 4\n" +" subs r0, r3\n" +" lsls r0, 5\n" +" add r0, sp\n" +" adds r0, 0x8\n" +" add r1, sp, 0x8\n" +" mov r10, r2\n" +"_0804BD06:\n" +" strb r4, [r1, 0xA]\n" +" strb r4, [r0, 0xA]\n" +" adds r0, 0x20\n" +" adds r1, 0x20\n" +" movs r2, 0x1\n" +" negs r2, r2\n" +" add r10, r2\n" +" mov r2, r10\n" +" cmp r2, 0\n" +" bne _0804BD06\n" +"_0804BD1A:\n" +" movs r2, 0x1\n" +" cmp r2, r3\n" +" bge _0804BD58\n" +" movs r1, 0x3\n" +"_0804BD22:\n" +" adds r4, r2, 0x1\n" +" ldr r0, _0804BEDC\n" +" add r0, sp\n" +" str r4, [r0]\n" +" cmp r1, 0x1\n" +" ble _0804BD4E\n" +" lsls r0, r2, 4\n" +" subs r0, r2\n" +" lsls r0, 5\n" +" add r0, sp\n" +" adds r0, 0x8\n" +" adds r0, 0x20\n" +" subs r2, r1, 0x1\n" +" mov r10, r2\n" +"_0804BD3E:\n" +" strb r5, [r0, 0xA]\n" +" adds r0, 0x20\n" +" movs r4, 0x1\n" +" negs r4, r4\n" +" add r10, r4\n" +" mov r2, r10\n" +" cmp r2, 0\n" +" bne _0804BD3E\n" +"_0804BD4E:\n" +" ldr r4, _0804BEDC\n" +" add r4, sp\n" +" ldr r2, [r4]\n" +" cmp r2, r3\n" +" blt _0804BD22\n" +"_0804BD58:\n" +" add r0, sp, 0x8\n" +" movs r1, 0x1\n" +" strb r1, [r0, 0x8]\n" +" movs r0, 0xF2\n" +" lsls r0, 3\n" +" add r0, sp\n" +" strb r1, [r0]\n" +" strb r1, [r6]\n" +" movs r0, 0xFE\n" +" lsls r0, 3\n" +" add r0, sp\n" +" strb r1, [r0]\n" +" movs r5, 0\n" +" ldr r6, _0804BEE0\n" +" add r6, sp\n" +" str r5, [r6]\n" +" mov r10, r5\n" +" cmp r5, 0x4\n" +" blt _0804BD80\n" +" b _0804BFAC\n" +"_0804BD80:\n" +" movs r0, 0x4\n" +" movs r1, 0xE6\n" +" lsls r1, 5\n" +" add r1, sp\n" +" str r0, [r1]\n" +"_0804BD8A:\n" +" movs r2, 0\n" +" cmp r2, 0x5\n" +" blt _0804BD92\n" +" b _0804BF94\n" +"_0804BD92:\n" +" ldr r3, _0804BED4\n" +" add r3, sp\n" +" ldr r4, _0804BEE4\n" +" add r4, sp\n" +" str r3, [r4]\n" +" ldr r5, _0804BED8\n" +" add r5, sp\n" +" ldr r6, _0804BEE8\n" +" add r6, sp\n" +" str r5, [r6]\n" +" mov r1, r10\n" +" lsls r0, r1, 2\n" +" adds r0, r5, r0\n" +" ldr r3, _0804BEEC\n" +" add r3, sp\n" +" str r0, [r3]\n" +"_0804BDB2:\n" +" lsls r0, r2, 4\n" +" subs r0, r2\n" +" add r0, r10\n" +" lsls r0, 5\n" +" mov r7, sp\n" +" adds r7, r0\n" +" adds r7, 0x8\n" +" ldrb r0, [r7, 0x8]\n" +" adds r4, r2, 0x1\n" +" ldr r5, _0804BEDC\n" +" add r5, sp\n" +" str r4, [r5]\n" +" cmp r0, 0\n" +" beq _0804BDD0\n" +" b _0804BF88\n" +"_0804BDD0:\n" +" ldrb r0, [r7, 0xA]\n" +" cmp r0, 0\n" +" bne _0804BDD8\n" +" b _0804BF00\n" +"_0804BDD8:\n" +" lsls r0, r2, 2\n" +" ldr r6, _0804BEE4\n" +" add r6, sp\n" +" ldr r6, [r6]\n" +" adds r0, r6, r0\n" +" ldr r1, [r0]\n" +" adds r0, r1, 0x2\n" +" mov r9, r0\n" +" ldr r3, _0804BEEC\n" +" add r3, sp\n" +" ldr r3, [r3]\n" +" ldr r2, [r3]\n" +" adds r4, r2, 0x2\n" +" ldr r5, _0804BEF0\n" +" add r5, sp\n" +" str r4, [r5]\n" +" ldr r6, _0804BEDC\n" +" add r6, sp\n" +" ldr r6, [r6]\n" +" lsls r0, r6, 2\n" +" ldr r3, _0804BEE4\n" +" add r3, sp\n" +" ldr r3, [r3]\n" +" adds r0, r3, r0\n" +" ldr r4, [r0]\n" +" subs r4, r1\n" +" subs r4, 0x3\n" +" ldr r5, _0804BEE8\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" movs r6, 0xE6\n" +" lsls r6, 5\n" +" add r6, sp\n" +" ldr r6, [r6]\n" +" adds r0, r5, r6\n" +" ldr r5, [r0]\n" +" subs r5, r2\n" +" subs r5, 0x3\n" +" movs r0, 0x5\n" +" adds r1, r4, 0\n" +" bl DungeonRandRange\n" +" mov r8, r0\n" +" movs r0, 0x4\n" +" adds r1, r5, 0\n" +" bl DungeonRandRange\n" +" adds r6, r0, 0\n" +" mov r0, r8\n" +" subs r4, r0\n" +" adds r0, r4, 0\n" +" bl DungeonRandInt\n" +" adds r4, r0, 0\n" +" add r4, r9\n" +" subs r5, r6\n" +" adds r0, r5, 0\n" +" bl DungeonRandInt\n" +" ldr r2, _0804BEF0\n" +" add r2, sp\n" +" ldr r1, [r2]\n" +" adds r1, r0\n" +" mov r9, r1\n" +" mov r5, r8\n" +" adds r3, r4, r5\n" +" add r6, r9\n" +" strh r4, [r7]\n" +" strh r3, [r7, 0x4]\n" +" strh r1, [r7, 0x2]\n" +" strh r6, [r7, 0x6]\n" +" ldr r1, _0804BEE0\n" +" add r1, sp\n" +" ldr r0, [r1]\n" +" adds r0, 0x1\n" +" ldr r1, _0804BEF4\n" +" add r1, sp\n" +" str r0, [r1]\n" +" cmp r4, r3\n" +" bge _0804BEC0\n" +"_0804BE78:\n" +" mov r5, r9\n" +" adds r7, r4, 0x1\n" +" cmp r5, r6\n" +" bge _0804BEBA\n" +" ldr r2, _0804BEF8\n" +" mov r8, r2\n" +"_0804BE84:\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" ldr r2, _0804BEFC\n" +" add r2, sp\n" +" str r3, [r2]\n" +" bl GetTileSafe\n" +" ldrh r1, [r0]\n" +" mov r2, r8\n" +" ands r1, r2\n" +" movs r2, 0x1\n" +" orrs r1, r2\n" +" strh r1, [r0]\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" bl GetTileSafe\n" +" ldr r1, _0804BEE0\n" +" add r1, sp\n" +" ldrb r1, [r1]\n" +" strb r1, [r0, 0x9]\n" +" adds r5, 0x1\n" +" ldr r2, _0804BEFC\n" +" add r2, sp\n" +" ldr r3, [r2]\n" +" cmp r5, r6\n" +" blt _0804BE84\n" +"_0804BEBA:\n" +" adds r4, r7, 0\n" +" cmp r4, r3\n" +" blt _0804BE78\n" +"_0804BEC0:\n" +" ldr r3, _0804BEF4\n" +" add r3, sp\n" +" ldr r3, [r3]\n" +" ldr r4, _0804BEE0\n" +" add r4, sp\n" +" str r3, [r4]\n" +" b _0804BF88\n" +" .align 2, 0\n" +"_0804BED0: .4byte 0xffffe338\n" +"_0804BED4: .4byte 0x00001c28\n" +"_0804BED8: .4byte 0x00001c64\n" +"_0804BEDC: .4byte 0x00001cb8\n" +"_0804BEE0: .4byte 0x00001ca4\n" +"_0804BEE4: .4byte 0x00001ca8\n" +"_0804BEE8: .4byte 0x00001cb0\n" +"_0804BEEC: .4byte 0x00001cb4\n" +"_0804BEF0: .4byte 0x00001cac\n" +"_0804BEF4: .4byte 0x00001cbc\n" +"_0804BEF8: .4byte 0x0000fffc\n" +"_0804BEFC: .4byte 0x00001cc4\n" +"_0804BF00:\n" +" lsls r0, r2, 2\n" +" ldr r4, _0804C080\n" +" add r4, sp\n" +" ldr r4, [r4]\n" +" adds r0, r4, r0\n" +" ldr r2, [r0]\n" +" adds r0, r2, 0x1\n" +" ldr r5, _0804C084\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" ldr r3, [r5]\n" +" adds r6, r3, 0x1\n" +" mov r8, r6\n" +" ldr r4, _0804C088\n" +" add r4, sp\n" +" ldr r4, [r4]\n" +" lsls r1, r4, 2\n" +" ldr r5, _0804C080\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" adds r1, r5, r1\n" +" ldr r1, [r1]\n" +" subs r1, r2\n" +" subs r1, 0x3\n" +" ldr r6, _0804C08C\n" +" add r6, sp\n" +" ldr r6, [r6]\n" +" movs r4, 0xE6\n" +" lsls r4, 5\n" +" add r4, sp\n" +" ldr r4, [r4]\n" +" adds r2, r6, r4\n" +" ldr r4, [r2]\n" +" subs r4, r3\n" +" subs r4, 0x3\n" +" adds r1, r0, r1\n" +" bl DungeonRandRange\n" +" adds r5, r0, 0\n" +" add r4, r8\n" +" mov r0, r8\n" +" adds r1, r4, 0\n" +" bl DungeonRandRange\n" +" adds r4, r0, 0\n" +" strh r5, [r7]\n" +" adds r0, r5, 0x1\n" +" strh r0, [r7, 0x4]\n" +" strh r4, [r7, 0x2]\n" +" adds r0, r4, 0x1\n" +" strh r0, [r7, 0x6]\n" +" adds r0, r5, 0\n" +" adds r1, r4, 0\n" +" bl GetTileSafe\n" +" ldrh r1, [r0]\n" +" ldr r6, _0804C090\n" +" adds r2, r6, 0\n" +" ands r1, r2\n" +" movs r2, 0x1\n" +" orrs r1, r2\n" +" strh r1, [r0]\n" +" adds r0, r5, 0\n" +" adds r1, r4, 0\n" +" bl GetTileSafe\n" +" movs r1, 0xFF\n" +" strb r1, [r0, 0x9]\n" +"_0804BF88:\n" +" ldr r0, _0804C088\n" +" add r0, sp\n" +" ldr r2, [r0]\n" +" cmp r2, 0x5\n" +" bge _0804BF94\n" +" b _0804BDB2\n" +"_0804BF94:\n" +" movs r2, 0xE6\n" +" lsls r2, 5\n" +" add r2, sp\n" +" ldr r1, [r2]\n" +" adds r1, 0x4\n" +" str r1, [r2]\n" +" movs r3, 0x1\n" +" add r10, r3\n" +" mov r4, r10\n" +" cmp r4, 0x4\n" +" bge _0804BFAC\n" +" b _0804BD8A\n" +"_0804BFAC:\n" +" movs r2, 0x1\n" +" movs r1, 0x1\n" +" movs r3, 0xF\n" +" add r4, sp, 0x1C\n" +"_0804BFB4:\n" +" movs r5, 0\n" +" mov r10, r5\n" +" lsls r0, r3, 5\n" +" adds r0, r4\n" +"_0804BFBC:\n" +" strb r1, [r0]\n" +" strb r1, [r0, 0x1F]\n" +" adds r0, 0x20\n" +" movs r6, 0x1\n" +" add r10, r6\n" +" mov r5, r10\n" +" cmp r5, 0x2\n" +" ble _0804BFBC\n" +" movs r0, 0xF0\n" +" lsls r0, 1\n" +" adds r3, 0xF\n" +" adds r2, 0x1\n" +" cmp r2, 0x3\n" +" ble _0804BFB4\n" +" mov r10, r6\n" +" movs r5, 0x1\n" +" adds r4, r0, 0\n" +" mov r6, sp\n" +" adds r6, r4\n" +" adds r6, 0x8\n" +"_0804BFE4:\n" +" movs r2, 0\n" +" mov r1, r10\n" +" lsls r0, r1, 5\n" +" mov r3, r10\n" +" adds r3, 0x1\n" +" adds r1, r0, r6\n" +" add r0, sp\n" +" adds r0, 0x8\n" +"_0804BFF4:\n" +" strb r5, [r0, 0x16]\n" +" strb r5, [r1, 0x15]\n" +" adds r1, r4\n" +" adds r0, r4\n" +" adds r2, 0x1\n" +" cmp r2, 0x3\n" +" ble _0804BFF4\n" +" mov r10, r3\n" +" cmp r3, 0x2\n" +" ble _0804BFE4\n" +" ldr r5, _0804C094\n" +" add r5, sp\n" +" ldr r4, _0804C098\n" +" add r4, sp\n" +" str r4, [sp]\n" +" movs r0, 0x1\n" +" str r0, [sp, 0x4]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x5\n" +" movs r2, 0x4\n" +" adds r3, r5, 0\n" +" bl sub_804D8C8\n" +" str r4, [sp]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x5\n" +" movs r2, 0x4\n" +" adds r3, r5, 0\n" +" bl sub_804E590\n" +" ldr r0, _0804C09C\n" +" movs r2, 0\n" +" ldrsh r3, [r0, r2]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x5\n" +" movs r2, 0x4\n" +" bl sub_804EBC8\n" +" ldr r0, _0804C0A0\n" +" movs r4, 0\n" +" ldrsh r3, [r0, r4]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x5\n" +" movs r2, 0x4\n" +" bl sub_804EEE4\n" +" movs r5, 0xE5\n" +" lsls r5, 5\n" +" add r5, sp\n" +" ldr r5, [r5]\n" +" ldrb r3, [r5, 0x13]\n" +" add r0, sp, 0x8\n" +" movs r1, 0x5\n" +" movs r2, 0x4\n" +" bl sub_804CBEC\n" +" add r0, sp, 0x8\n" +" movs r1, 0x5\n" +" movs r2, 0x4\n" +" bl sub_804E03C\n" +" ldr r3, _0804C0A4\n" +" add sp, r3\n" +" pop {r3-r5}\n" +" mov r8, r3\n" +" mov r9, r4\n" +" mov r10, r5\n" +" pop {r4-r7}\n" +" pop {r0}\n" +" bx r0\n" +" .align 2, 0\n" +"_0804C080: .4byte 0x00001ca8\n" +"_0804C084: .4byte 0x00001cb4\n" +"_0804C088: .4byte 0x00001cb8\n" +"_0804C08C: .4byte 0x00001cb0\n" +"_0804C090: .4byte 0x0000fffc\n" +"_0804C094: .4byte 0x00001c28\n" +"_0804C098: .4byte 0x00001c64\n" +"_0804C09C: .4byte gUnknown_202F1B0\n" +"_0804C0A0: .4byte gUnknown_202F1B2\n" +"_0804C0A4: .4byte 0x00001cc8"); +} +#endif // NONMATCHING + +void sub_804C0A8(UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct UnkHugeSpStruct sp; + s32 unk7200[15]; + s32 unk7260[15]; + s32 x, y, unk; + + unk7200[0] = 0; + unk7200[1] = 11; + unk7200[2] = 22; + unk7200[3] = 33; + unk7200[4] = 44; + unk7200[5] = 56; + + unk7260[0] = 4; + unk7260[1] = 15; + + unk = 1; + x = 5, y = 1; + sub_804D084(&sp, x, y); + sub_804D154(&sp, x, y, unkPtr->unk1); + sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); + sub_804D5B0(&sp, x, y, unkPtr); + sub_804D8C8(&sp, x, y, unk7200, unk7260, unk); + sub_804E590(&sp, x, y, unk7200, unk7260); + sub_804EBC8(&sp, x, y, gUnknown_202F1B0); + sub_804EEE4(&sp, x, y, gUnknown_202F1B2); + sub_804CBEC(&sp, x, y, unkPtr->unk13); + sub_804E03C(&sp, x, y); +} + +void sub_804C190(UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct UnkHugeSpStruct sp; + s32 unk7200[15]; + s32 unk7260[15]; + s32 i, j, x, y; + + unk7200[0] = 11; + unk7200[1] = 22; + unk7200[2] = 33; + unk7200[3] = 44; + + unk7260[0] = 2; + unk7260[1] = 11; + unk7260[2] = 20; + unk7260[3] = 30; + + x = 3, y = 3; + sub_804D084(&sp, x, y); + for (i = 0; i < x; i++) { + for (j = 0; j < y; j++) { + sp.unk0[i][j].unk10 = 1; + } + } + sp.unk0[0][0].unk8 = 1; + sp.unk0[2][0].unk8 = 1; + sp.unk0[0][2].unk8 = 1; + sp.unk0[2][2].unk8 = 1; + + sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); + + sp.unk0[0][1].unk22 = 1; + sp.unk0[1][1].unk21 = 1; + sp.unk0[1][1].unk22 = 1; + sp.unk0[2][1].unk21 = 1; + sp.unk0[1][0].unk20 = 1; + sp.unk0[1][1].unk19 = 1; + sp.unk0[1][1].unk20 = 1; + sp.unk0[1][2].unk19 = 1; + sub_804D8C8(&sp, x, y, unk7200, unk7260, 1); + sub_804E590(&sp, x, y, unk7200, unk7260); + sub_804EBC8(&sp, x, y, gUnknown_202F1B0); + sub_804EEE4(&sp, x, y, gUnknown_202F1B2); + sub_804CBEC(&sp, x, y, unkPtr->unk13); + sub_804E03C(&sp, x, y); +} + +void sub_804C2F4(UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct UnkHugeSpStruct sp; + s32 unk7200[15]; + s32 unk7260[15]; + s32 i, j, x, y; + + unk7200[0] = 5; + unk7200[1] = 15; + unk7200[2] = 35; + unk7200[3] = 50; + + unk7260[0] = 2; + unk7260[1] = 11; + unk7260[2] = 20; + unk7260[3] = 30; + + x = 3, y = 3; + sub_804D084(&sp, x, y); + for (i = 0; i < x; i++) { + for (j = 0; j < y; j++) { + sp.unk0[i][j].unk10 = 1; + } + } + + sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); + for (j = 0; j < 3; j++) { + sp.unk0[0][j].unk22 = 1; + sp.unk0[1][j].unk21 = 1; + sp.unk0[1][j].unk22 = 1; + sp.unk0[2][j].unk21 = 1; + } + sub_804D8C8(&sp, x, y, unk7200, unk7260, 1); + sub_804C43C(1, 0, 1, sp.unk0); + sub_804C43C(1, 0, 2, sp.unk0); + sub_804E590(&sp, x, y, unk7200, unk7260); + sub_804EBC8(&sp, x, y, gUnknown_202F1B0); + sub_804EEE4(&sp, x, y, gUnknown_202F1B2); + sub_804CBEC(&sp, x, y, unkPtr->unk13); + sub_804E03C(&sp, x, y); +} + +void sub_804C43C(s32 a0, s32 a1, s32 a2, struct UnkHugeSpStructSubUnk0 sp[15][15]) +{ + s32 x, y; + s32 xStart = (sp[a0][a1].unk0.x < sp[a0][a1+a2].unk0.x) ? sp[a0][a1].unk0.x : sp[a0][a1+a2].unk0.x; + s32 yStart = sp[a0][a1].unk0.y; + s32 xMax = (sp[a0][a1].unk4.x > sp[a0][a1+a2].unk4.x) ? sp[a0][a1].unk4.x : sp[a0][a1+a2].unk4.x; + s32 yMax = sp[a0][a1 + a2].unk4.y; + u8 room = GetTile(sp[a0][a1].unk0.x, sp[a0][a1].unk0.y)->room; + + for (x = xStart; x < xMax; x++) { + for (y = yStart; y < yMax; y++) { + Tile *tile = GetTileSafe(x, y); + tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + tile->terrainType |= TERRAIN_TYPE_NORMAL; + tile->room = room; + } + } + + sp[a0][a1].unk0.x = xStart; + sp[a0][a1].unk4.x = xMax; + sp[a0][a1].unk0.y = yStart; + sp[a0][a1].unk4.y = yMax; + sp[a0][a1 + a2].unk18 = 1; + sp[a0][a1].unk18 = 1; + sp[a0][a1 + a2].unk11 = 0; + sp[a0][a1 + a2].unk17 = 1; +} + // From 2510f0343989510ddf9ebcf659f7a7e0fd8c4b9b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 7 Nov 2024 22:00:18 +0100 Subject: [PATCH 03/30] sub_804C9D0 --- asm/code_804AFAC.s | 849 ------------------------------------------- src/code_804AFAC_1.c | 420 +++++++++++++++------ 2 files changed, 310 insertions(+), 959 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 1438679b1..4239f3d66 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -6,855 +6,6 @@ .text - - thumb_func_start sub_804C53C -sub_804C53C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804C6F8 - add sp, r4 - mov r10, r2 - adds r7, r0, 0 - adds r6, r1, 0 - ldr r0, _0804C6FC - add r0, sp - ldr r1, _0804C700 - add r1, sp - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804D024 - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D084 - movs r2, 0 - cmp r2, r7 - bge _0804C594 -_0804C570: - adds r3, r2, 0x1 - cmp r6, 0 - ble _0804C58E - lsls r0, r2, 4 - subs r0, r2 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r1, r6, 0 -_0804C584: - strb r2, [r0, 0xA] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C584 -_0804C58E: - adds r2, r3, 0 - cmp r2, r7 - blt _0804C570 -_0804C594: - movs r2, 0x1 - subs r0, r7, 0x1 - mov r8, r0 - subs r1, r6, 0x1 - mov r9, r1 - mov r0, r10 - ldrb r0, [r0, 0xD] - mov r12, r0 - cmp r2, r8 - bge _0804C5D2 - mov r4, r9 - mov r5, r8 -_0804C5AC: - adds r3, r2, 0x1 - cmp r4, 0x1 - ble _0804C5CC - lsls r0, r2, 4 - subs r0, r2 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r0, 0x20 - subs r1, r4, 0x1 -_0804C5C2: - strb r2, [r0, 0x8] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C5C2 -_0804C5CC: - adds r2, r3, 0 - cmp r2, r5 - blt _0804C5AC -_0804C5D2: - ldr r3, _0804C6FC - add r3, sp - ldr r0, _0804C700 - add r0, sp - str r0, [sp] - mov r1, r12 - str r1, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D2D0 - movs r2, 0 - cmp r2, r8 - bge _0804C636 - movs r4, 0x1 - mov r0, r9 - lsls r5, r0, 5 - subs r1, r7, 0x2 - mov r12, r1 -_0804C5FA: - cmp r2, 0 - beq _0804C614 - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - mov r1, sp - adds r1, r0 - adds r1, 0x8 - strb r4, [r1, 0x16] - adds r0, r5, r0 - add r0, sp - adds r0, 0x8 - strb r4, [r0, 0x16] -_0804C614: - adds r3, r2, 0x1 - cmp r2, r12 - bge _0804C630 - lsls r0, r3, 4 - subs r0, r3 - lsls r0, 5 - mov r1, sp - adds r1, r0 - adds r1, 0x8 - strb r4, [r1, 0x15] - adds r0, r5, r0 - add r0, sp - adds r0, 0x8 - strb r4, [r0, 0x15] -_0804C630: - adds r2, r3, 0 - cmp r2, r8 - blt _0804C5FA -_0804C636: - movs r1, 0 - cmp r1, r9 - bge _0804C66A - movs r3, 0x1 - mov r2, r8 - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - add r2, sp, 0x8 - subs r5, r6, 0x2 - mov r4, r9 -_0804C650: - cmp r1, 0 - beq _0804C658 - strb r3, [r2, 0x13] - strb r3, [r0, 0x13] -_0804C658: - cmp r1, r5 - bge _0804C660 - strb r3, [r2, 0x14] - strb r3, [r0, 0x14] -_0804C660: - adds r0, 0x20 - adds r2, 0x20 - adds r1, 0x1 - cmp r1, r4 - blt _0804C650 -_0804C66A: - ldr r5, _0804C6FC - add r5, sp - ldr r4, _0804C700 - add r4, sp - str r4, [sp] - movs r0, 0 - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804D8C8 - str r4, [sp] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804E590 - mov r0, r10 - ldrb r3, [r0, 0x9] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804F0D0 - ldr r0, _0804C704 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EBC8 - ldr r0, _0804C708 - movs r2, 0 - ldrsh r3, [r0, r2] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EEE4 - mov r0, r10 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804CBEC - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804E03C - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D534 - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C6F8: .4byte 0xffffe360 -_0804C6FC: .4byte 0x00001c28 -_0804C700: .4byte 0x00001c64 -_0804C704: .4byte gUnknown_202F1B0 -_0804C708: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C53C - - thumb_func_start sub_804C70C -sub_804C70C: - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - adds r7, r0, 0 - mov r8, r1 - ldr r0, _0804C73C - ldr r0, [r0] - ldr r1, _0804C740 - adds r0, r1 - ldr r0, [r0] - ldr r1, [r0, 0x4] - lsls r0, r7, 2 - adds r0, r1 - ldr r0, [r0] - ldrb r5, [r0] - ldrb r6, [r0, 0x1] - cmp r5, 0 - beq _0804C736 - cmp r6, 0 - bne _0804C744 -_0804C736: - bl sub_804C918 - b _0804C782 - .align 2, 0 -_0804C73C: .4byte gDungeon -_0804C740: .4byte 0x00013568 -_0804C744: - cmp r7, 0x31 - bgt _0804C752 - adds r0, r7, 0 - bl sub_8051288 - movs r0, 0x1 - b _0804C784 -_0804C752: - adds r1, r5, 0x4 - movs r0, 0x38 - bl __divsi3 - adds r4, r0, 0 - cmp r4, 0x1 - bgt _0804C762 - movs r4, 0x1 -_0804C762: - adds r1, r6, 0x4 - movs r0, 0x20 - bl __divsi3 - adds r1, r0, 0 - cmp r1, 0x1 - bgt _0804C772 - movs r1, 0x1 -_0804C772: - str r7, [sp] - mov r0, r8 - str r0, [sp, 0x4] - adds r0, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl sub_804C790 -_0804C782: - movs r0, 0 -_0804C784: - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_804C70C - - thumb_func_start sub_804C790 -sub_804C790: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804C81C - add sp, r4 - adds r5, r0, 0 - adds r4, r1, 0 - ldr r0, _0804C820 - add r0, sp - str r2, [r0] - ldr r1, _0804C824 - add r1, sp - str r3, [r1] - movs r2, 0 - mov r10, r2 - mov r8, r2 - ldr r0, _0804C828 - add r0, sp - ldr r1, _0804C82C - add r1, sp - adds r2, r5, 0 - adds r3, r4, 0 - bl sub_804D024 - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - bl sub_804D084 - ldr r0, _0804C830 - add r0, sp - ldr r0, [r0] - movs r3, 0x1 - ldrsb r3, [r0, r3] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - bl sub_804D154 - mov r6, r8 - cmp r8, r5 - bge _0804C818 -_0804C7E8: - movs r1, 0 - mov r8, r1 - adds r2, r6, 0x1 - cmp r8, r4 - bge _0804C812 - lsls r0, r6, 4 - subs r0, r6 - movs r1, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x10 - mov r8, r4 -_0804C800: - strb r1, [r0, 0x1B] - adds r0, 0x20 - movs r3, 0x1 - negs r3, r3 - add r8, r3 - mov r3, r8 - cmp r3, 0 - bne _0804C800 - mov r8, r4 -_0804C812: - adds r6, r2, 0 - cmp r6, r5 - blt _0804C7E8 -_0804C818: - movs r7, 0 - b _0804C836 - .align 2, 0 -_0804C81C: .4byte 0xffffe350 -_0804C820: .4byte 0x00001ca8 -_0804C824: .4byte 0x00001cac -_0804C828: .4byte 0x00001c30 -_0804C82C: .4byte 0x00001c6c -_0804C830: .4byte 0x00001cd4 -_0804C834: - adds r7, 0x1 -_0804C836: - cmp r7, 0x3F - bgt _0804C864 - adds r0, r5, 0 - bl DungeonRandInt - adds r6, r0, 0 - adds r0, r4, 0 - bl DungeonRandInt - mov r8, r0 - mov r0, r8 - muls r0, r5 - adds r0, r6 - mov r10, r0 - lsls r0, r6, 4 - subs r0, r6 - add r0, r8 - lsls r0, 5 - add r0, sp - adds r0, 0x10 - ldrb r0, [r0, 0xA] - cmp r0, 0 - beq _0804C834 -_0804C864: - ldr r0, _0804C8FC - add r0, sp - mov r9, r0 - ldr r7, _0804C900 - add r7, sp - str r7, [sp] - mov r1, r10 - str r1, [sp, 0x4] - ldr r2, _0804C904 - add r2, sp - ldr r2, [r2] - str r2, [sp, 0x8] - ldr r3, _0804C908 - add r3, sp - ldr r3, [r3] - str r3, [sp, 0xC] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - mov r3, r9 - bl sub_8050F90 - cmp r5, 0x1 - bne _0804C898 - cmp r4, 0x1 - beq _0804C8D0 -_0804C898: - mov r0, r8 - str r0, [sp] - ldr r1, _0804C90C - add r1, sp - ldr r1, [r1] - str r1, [sp, 0x4] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - adds r3, r6, 0 - bl sub_804D5F0 - str r7, [sp] - movs r0, 0x1 - str r0, [sp, 0x4] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - mov r3, r9 - bl sub_804D8C8 - str r7, [sp] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - mov r3, r9 - bl sub_804E590 -_0804C8D0: - lsls r0, r6, 4 - subs r0, r6 - lsls r0, 5 - add r0, sp - adds r0, 0x10 - mov r2, r8 - lsls r1, r2, 5 - adds r0, r1 - ldr r3, _0804C910 - add r3, sp - ldr r1, [r3] - bl sub_8051438 - ldr r3, _0804C914 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C8FC: .4byte 0x00001c30 -_0804C900: .4byte 0x00001c6c -_0804C904: .4byte 0x00001ca8 -_0804C908: .4byte 0x00001cac -_0804C90C: .4byte 0x00001cd4 -_0804C910: .4byte 0x00001cd0 -_0804C914: .4byte 0x00001cb0 - thumb_func_end sub_804C790 - - thumb_func_start sub_804C918 -sub_804C918: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - ldr r4, _0804C9C4 - add sp, r4 - mov r0, sp - movs r1, 0x1 - movs r2, 0x1 - bl sub_804D084 - mov r0, sp - movs r3, 0 - movs r2, 0x2 - strh r2, [r0] - mov r1, sp - movs r0, 0x36 - strh r0, [r1, 0x4] - mov r0, sp - strh r2, [r0, 0x2] - movs r0, 0x1E - strh r0, [r1, 0x6] - mov r0, sp - movs r1, 0x1 - strb r1, [r0, 0xA] - strb r1, [r0, 0xB] - strb r3, [r0, 0x8] - movs r1, 0 - ldrsh r5, [r0, r1] - movs r2, 0x4 - ldrsh r0, [r0, r2] - cmp r5, r0 - bge _0804C9A6 - mov r6, sp -_0804C95C: - movs r0, 0x2 - ldrsh r4, [r6, r0] - movs r1, 0x6 - ldrsh r0, [r6, r1] - adds r7, r5, 0x1 - cmp r4, r0 - bge _0804C99C - movs r2, 0 - mov r9, r2 - ldr r0, _0804C9C8 - mov r8, r0 -_0804C972: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r1, [r0] - mov r2, r8 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - mov r1, r9 - strb r1, [r0, 0x9] - adds r4, 0x1 - movs r2, 0x6 - ldrsh r0, [r6, r2] - cmp r4, r0 - blt _0804C972 -_0804C99C: - adds r5, r7, 0 - movs r1, 0x4 - ldrsh r0, [r6, r1] - cmp r5, r0 - blt _0804C95C -_0804C9A6: - ldr r3, _0804C9CC - mov r0, sp - movs r1, 0x1 - movs r2, 0x1 - bl sub_804EEE4 - movs r3, 0xE1 - lsls r3, 5 - add sp, r3 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C9C4: .4byte 0xffffe3e0 -_0804C9C8: .4byte 0x0000fffc -_0804C9CC: .4byte 0x000003e7 - thumb_func_end sub_804C918 - - thumb_func_start sub_804C9D0 -sub_804C9D0: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804CBB4 - add sp, r4 - movs r0, 0 - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - str r0, [r1] - ldr r1, _0804CBB8 - add r1, sp - movs r2, 0x2 - str r2, [r1] - movs r0, 0x1C - str r0, [r1, 0x4] - movs r0, 0x36 - str r0, [r1, 0x8] - ldr r1, _0804CBBC - add r1, sp - str r2, [r1] - movs r0, 0x1E - str r0, [r1, 0x4] - add r0, sp, 0x8 - movs r1, 0x2 - movs r2, 0x1 - bl sub_804D084 - movs r0, 0 - ldr r2, _0804CBB8 - add r2, sp - ldr r3, _0804CBC0 - add r3, sp - str r2, [r3] - ldr r4, _0804CBBC - add r4, sp - ldr r1, _0804CBC4 - add r1, sp - str r4, [r1] -_0804CA22: - movs r7, 0 - lsls r2, r0, 2 - ldr r3, _0804CBC8 - add r3, sp - str r2, [r3] - adds r4, r0, 0x1 - ldr r1, _0804CBCC - add r1, sp - str r4, [r1] - lsls r0, 5 - ldr r2, _0804CBD0 - add r2, sp - str r0, [r2] -_0804CA3C: - lsls r0, r7, 2 - ldr r3, _0804CBC0 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r1, [r0] - adds r4, r1, 0x1 - mov r10, r4 - ldr r2, _0804CBC4 - add r2, sp - ldr r2, [r2] - ldr r3, _0804CBC8 - add r3, sp - ldr r3, [r3] - adds r0, r2, r3 - ldr r2, [r0] - adds r4, r2, 0x1 - ldr r0, _0804CBD4 - add r0, sp - str r4, [r0] - adds r3, r7, 0x1 - mov r9, r3 - lsls r0, r3, 2 - ldr r4, _0804CBC0 - add r4, sp - ldr r4, [r4] - adds r0, r4, r0 - ldr r4, [r0] - subs r4, r1 - subs r4, 0x3 - ldr r1, _0804CBCC - add r1, sp - ldr r1, [r1] - lsls r0, r1, 2 - ldr r3, _0804CBC4 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r5, [r0] - subs r5, r2 - subs r5, 0x3 - movs r0, 0xA - adds r1, r4, 0 - bl DungeonRandRange - mov r8, r0 - movs r0, 0x10 - adds r1, r5, 0 - bl DungeonRandRange - adds r6, r0, 0 - mov r0, r8 - subs r4, r0 - adds r0, r4, 0 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r10 - subs r5, r6 - adds r0, r5, 0 - bl DungeonRandInt - ldr r2, _0804CBD4 - add r2, sp - ldr r1, [r2] - adds r1, r0 - mov r10, r1 - mov r0, r8 - adds r3, r4, r0 - add r6, r10 - lsls r0, r7, 4 - subs r0, r7 - lsls r0, 5 - ldr r1, _0804CBD0 - add r1, sp - ldr r1, [r1] - adds r0, r1, r0 - add r0, sp - adds r0, 0x8 - movs r1, 0x1 - strb r1, [r0, 0xA] - strh r4, [r0] - strh r3, [r0, 0x4] - mov r2, r10 - strh r2, [r0, 0x2] - strh r6, [r0, 0x6] - mov r0, r9 - ldr r1, _0804CBD8 - add r1, sp - str r0, [r1] - movs r0, 0xE5 - lsls r0, 5 - add r0, sp - ldr r2, [r0] - adds r2, 0x1 - mov r9, r2 - cmp r4, r3 - bge _0804CB4E -_0804CB00: - mov r5, r10 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804CB48 - ldr r1, _0804CBDC - mov r8, r1 -_0804CB0C: - adds r0, r4, 0 - adds r1, r5, 0 - movs r2, 0xE6 - lsls r2, 5 - add r2, sp - str r3, [r2] - bl GetTileSafe - ldrh r1, [r0] - mov r2, r8 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileSafe - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - ldrb r1, [r1] - strb r1, [r0, 0x9] - adds r5, 0x1 - movs r2, 0xE6 - lsls r2, 5 - add r2, sp - ldr r3, [r2] - cmp r5, r6 - blt _0804CB0C -_0804CB48: - adds r4, r7, 0 - cmp r4, r3 - blt _0804CB00 -_0804CB4E: - mov r3, r9 - movs r4, 0xE5 - lsls r4, 5 - add r4, sp - str r3, [r4] - ldr r0, _0804CBD8 - add r0, sp - ldr r7, [r0] - cmp r7, 0x1 - bgt _0804CB64 - b _0804CA3C -_0804CB64: - ldr r1, _0804CBCC - add r1, sp - ldr r0, [r1] - cmp r0, 0 - bgt _0804CB70 - b _0804CA22 -_0804CB70: - add r0, sp, 0x8 - movs r2, 0 - movs r1, 0x1 - strb r1, [r0, 0x16] - ldr r0, _0804CBE0 - add r0, sp - strb r1, [r0] - ldr r3, _0804CBB8 - add r3, sp - ldr r0, _0804CBBC - add r0, sp - str r0, [sp] - str r2, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x2 - movs r2, 0x1 - bl sub_804D8C8 - ldr r3, _0804CBE4 - add r0, sp, 0x8 - movs r1, 0x2 - movs r2, 0x1 - bl sub_804EEE4 - ldr r3, _0804CBE8 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804CBB4: .4byte 0xffffe33c -_0804CBB8: .4byte 0x00001c28 -_0804CBBC: .4byte 0x00001c64 -_0804CBC0: .4byte 0x00001ca4 -_0804CBC4: .4byte 0x00001cac -_0804CBC8: .4byte 0x00001cb0 -_0804CBCC: .4byte 0x00001cbc -_0804CBD0: .4byte 0x00001cb4 -_0804CBD4: .4byte 0x00001ca8 -_0804CBD8: .4byte 0x00001cb8 -_0804CBDC: .4byte 0x0000fffc -_0804CBE0: .4byte 0x000001fd -_0804CBE4: .4byte 0x000003e7 -_0804CBE8: .4byte 0x00001cc4 - thumb_func_end sub_804C9D0 - thumb_func_start sub_804CBEC sub_804CBEC: push {r4-r7,lr} diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index bf5876ffb..a653a3f18 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -59,6 +59,12 @@ void sub_80506F0(s32 a0, UnkDungeonGlobal_unk1C574 *a1); void sub_804FF08(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); void sub_8050438(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); +struct FileFixedmapPosStruct +{ + u8 x; + u8 y; +}; + // Some weird-ass regswap prevents the function from being matched - https://decomp.me/scratch/9SUV3 #ifdef NONMATCHING void sub_804AFAC(void) @@ -969,12 +975,7 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) } } -// Note: 15 seems to determine the array size, give it a better name and a define. - - -// Size 480 = 32 * 15 - -struct UnkHugeSpStructSubUnk0 +struct GridCell { Position unk0; Position unk4; @@ -1004,46 +1005,42 @@ struct UnkHugeSpStructSubUnk0 u8 unk31; }; -// Size 7200, however this struct is usually put at sp+8, so 8 needs to be added to these fields(in decimal) -struct UnkHugeSpStruct -{ - struct UnkHugeSpStructSubUnk0 unk0[15][15]; -}; +#define GRID_CELL_LEN 15 void sub_804D024(s32 *a0, s32 *a1, s32 x, s32 y); -void sub_804D084(struct UnkHugeSpStruct *a0, s32 x, s32 y); -void sub_804E03C(struct UnkHugeSpStruct *a0, s32 x, s32 y); -void sub_804D534(struct UnkHugeSpStruct *a0, s32 x, s32 y); -void sub_804D154(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); -void sub_804D2D0(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); -void sub_804D8C8(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); -void sub_804E590(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 *a3, s32 *a4); -void sub_804D5B0(struct UnkHugeSpStruct *a0, s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr); -void sub_804F0D0(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); -void sub_804EBC8(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); -void sub_804EEE4(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); -void sub_804CBEC(struct UnkHugeSpStruct *a0, s32 x, s32 y, s32 a3); -void sub_804C43C(s32 a0, s32 a1, s32 a2, struct UnkHugeSpStructSubUnk0 sp[15][15]); +void sub_804D084(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y); +void sub_804E03C(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y); +void sub_804D534(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y); +void sub_804D154(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); +void sub_804D2D0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); +void sub_804D8C8(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); +void sub_804E590(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 *a3, s32 *a4); +void sub_804D5B0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr); +void sub_804F0D0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); +void sub_804EBC8(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); +void sub_804EEE4(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); +void sub_804CBEC(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); +void sub_804C43C(s32 a0, s32 a1, s32 a2, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); void sub_804B634(s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr) { - struct UnkHugeSpStruct sp; - s32 unk7200[15]; - s32 unk7260[15]; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 unk7200[GRID_CELL_LEN]; + s32 unk7260[GRID_CELL_LEN]; sub_804D024(unk7200, unk7260, x, y); - sub_804D084(&sp, x, y); - sub_804D154(&sp, x, y, unkPtr->unk1); - sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); - sub_804D5B0(&sp, x, y, unkPtr); - sub_804D8C8(&sp, x, y, unk7200, unk7260, 0); - sub_804E590(&sp, x, y, unk7200, unk7260); - sub_804F0D0(&sp, x, y, unkPtr->unk9); - sub_804EBC8(&sp, x, y, gUnknown_202F1B0); - sub_804EEE4(&sp, x, y, gUnknown_202F1B2); - sub_804CBEC(&sp, x, y, unkPtr->unk13); - sub_804E03C(&sp, x, y); - sub_804D534(&sp, x, y); + sub_804D084(grid, x, y); + sub_804D154(grid, x, y, unkPtr->unk1); + sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); + sub_804D5B0(grid, x, y, unkPtr); + sub_804D8C8(grid, x, y, unk7200, unk7260, 0); + sub_804E590(grid, x, y, unk7200, unk7260); + sub_804F0D0(grid, x, y, unkPtr->unk9); + sub_804EBC8(grid, x, y, gUnknown_202F1B0); + sub_804EEE4(grid, x, y, gUnknown_202F1B2); + sub_804CBEC(grid, x, y, unkPtr->unk13); + sub_804E03C(grid, x, y); + sub_804D534(grid, x, y); } // Decompile once data structure is better understood @@ -1051,7 +1048,7 @@ void sub_804B634(s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr) #ifdef NONMATCHING void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) { - struct UnkHugeSpStruct sp; + struct GridCell grid[15][15]; sp.unk7200[0] = 0; sp.unk7200[1] = 5; @@ -1067,7 +1064,7 @@ void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) sp.unk7260[3] = 25; sp.unk7260[4] = 30; - sub_804D084(&sp, 6, 4); + sub_804D084(grid, 6, 4); } #else NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) @@ -2235,9 +2232,9 @@ NAKED void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) void sub_804C0A8(UnkDungeonGlobal_unk1C574 *unkPtr) { - struct UnkHugeSpStruct sp; - s32 unk7200[15]; - s32 unk7260[15]; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 unk7200[GRID_CELL_LEN]; + s32 unk7260[GRID_CELL_LEN]; s32 x, y, unk; unk7200[0] = 0; @@ -2252,23 +2249,23 @@ void sub_804C0A8(UnkDungeonGlobal_unk1C574 *unkPtr) unk = 1; x = 5, y = 1; - sub_804D084(&sp, x, y); - sub_804D154(&sp, x, y, unkPtr->unk1); - sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); - sub_804D5B0(&sp, x, y, unkPtr); - sub_804D8C8(&sp, x, y, unk7200, unk7260, unk); - sub_804E590(&sp, x, y, unk7200, unk7260); - sub_804EBC8(&sp, x, y, gUnknown_202F1B0); - sub_804EEE4(&sp, x, y, gUnknown_202F1B2); - sub_804CBEC(&sp, x, y, unkPtr->unk13); - sub_804E03C(&sp, x, y); + sub_804D084(grid, x, y); + sub_804D154(grid, x, y, unkPtr->unk1); + sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); + sub_804D5B0(grid, x, y, unkPtr); + sub_804D8C8(grid, x, y, unk7200, unk7260, unk); + sub_804E590(grid, x, y, unk7200, unk7260); + sub_804EBC8(grid, x, y, gUnknown_202F1B0); + sub_804EEE4(grid, x, y, gUnknown_202F1B2); + sub_804CBEC(grid, x, y, unkPtr->unk13); + sub_804E03C(grid, x, y); } void sub_804C190(UnkDungeonGlobal_unk1C574 *unkPtr) { - struct UnkHugeSpStruct sp; - s32 unk7200[15]; - s32 unk7260[15]; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 unk7200[GRID_CELL_LEN]; + s32 unk7260[GRID_CELL_LEN]; s32 i, j, x, y; unk7200[0] = 11; @@ -2282,40 +2279,40 @@ void sub_804C190(UnkDungeonGlobal_unk1C574 *unkPtr) unk7260[3] = 30; x = 3, y = 3; - sub_804D084(&sp, x, y); + sub_804D084(grid, x, y); for (i = 0; i < x; i++) { for (j = 0; j < y; j++) { - sp.unk0[i][j].unk10 = 1; + grid[i][j].unk10 = 1; } } - sp.unk0[0][0].unk8 = 1; - sp.unk0[2][0].unk8 = 1; - sp.unk0[0][2].unk8 = 1; - sp.unk0[2][2].unk8 = 1; + grid[0][0].unk8 = 1; + grid[2][0].unk8 = 1; + grid[0][2].unk8 = 1; + grid[2][2].unk8 = 1; - sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); + sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); - sp.unk0[0][1].unk22 = 1; - sp.unk0[1][1].unk21 = 1; - sp.unk0[1][1].unk22 = 1; - sp.unk0[2][1].unk21 = 1; - sp.unk0[1][0].unk20 = 1; - sp.unk0[1][1].unk19 = 1; - sp.unk0[1][1].unk20 = 1; - sp.unk0[1][2].unk19 = 1; - sub_804D8C8(&sp, x, y, unk7200, unk7260, 1); - sub_804E590(&sp, x, y, unk7200, unk7260); - sub_804EBC8(&sp, x, y, gUnknown_202F1B0); - sub_804EEE4(&sp, x, y, gUnknown_202F1B2); - sub_804CBEC(&sp, x, y, unkPtr->unk13); - sub_804E03C(&sp, x, y); + grid[0][1].unk22 = 1; + grid[1][1].unk21 = 1; + grid[1][1].unk22 = 1; + grid[2][1].unk21 = 1; + grid[1][0].unk20 = 1; + grid[1][1].unk19 = 1; + grid[1][1].unk20 = 1; + grid[1][2].unk19 = 1; + sub_804D8C8(grid, x, y, unk7200, unk7260, 1); + sub_804E590(grid, x, y, unk7200, unk7260); + sub_804EBC8(grid, x, y, gUnknown_202F1B0); + sub_804EEE4(grid, x, y, gUnknown_202F1B2); + sub_804CBEC(grid, x, y, unkPtr->unk13); + sub_804E03C(grid, x, y); } void sub_804C2F4(UnkDungeonGlobal_unk1C574 *unkPtr) { - struct UnkHugeSpStruct sp; - s32 unk7200[15]; - s32 unk7260[15]; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 unk7200[GRID_CELL_LEN]; + s32 unk7260[GRID_CELL_LEN]; s32 i, j, x, y; unk7200[0] = 5; @@ -2329,38 +2326,38 @@ void sub_804C2F4(UnkDungeonGlobal_unk1C574 *unkPtr) unk7260[3] = 30; x = 3, y = 3; - sub_804D084(&sp, x, y); + sub_804D084(grid, x, y); for (i = 0; i < x; i++) { for (j = 0; j < y; j++) { - sp.unk0[i][j].unk10 = 1; + grid[i][j].unk10 = 1; } } - sub_804D2D0(&sp, x, y, unk7200, unk7260, unkPtr->unkD); + sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); for (j = 0; j < 3; j++) { - sp.unk0[0][j].unk22 = 1; - sp.unk0[1][j].unk21 = 1; - sp.unk0[1][j].unk22 = 1; - sp.unk0[2][j].unk21 = 1; + grid[0][j].unk22 = 1; + grid[1][j].unk21 = 1; + grid[1][j].unk22 = 1; + grid[2][j].unk21 = 1; } - sub_804D8C8(&sp, x, y, unk7200, unk7260, 1); - sub_804C43C(1, 0, 1, sp.unk0); - sub_804C43C(1, 0, 2, sp.unk0); - sub_804E590(&sp, x, y, unk7200, unk7260); - sub_804EBC8(&sp, x, y, gUnknown_202F1B0); - sub_804EEE4(&sp, x, y, gUnknown_202F1B2); - sub_804CBEC(&sp, x, y, unkPtr->unk13); - sub_804E03C(&sp, x, y); + sub_804D8C8(grid, x, y, unk7200, unk7260, 1); + sub_804C43C(1, 0, 1, grid); + sub_804C43C(1, 0, 2, grid); + sub_804E590(grid, x, y, unk7200, unk7260); + sub_804EBC8(grid, x, y, gUnknown_202F1B0); + sub_804EEE4(grid, x, y, gUnknown_202F1B2); + sub_804CBEC(grid, x, y, unkPtr->unk13); + sub_804E03C(grid, x, y); } -void sub_804C43C(s32 a0, s32 a1, s32 a2, struct UnkHugeSpStructSubUnk0 sp[15][15]) +void sub_804C43C(s32 a0, s32 a1, s32 a2, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]) { s32 x, y; - s32 xStart = (sp[a0][a1].unk0.x < sp[a0][a1+a2].unk0.x) ? sp[a0][a1].unk0.x : sp[a0][a1+a2].unk0.x; - s32 yStart = sp[a0][a1].unk0.y; - s32 xMax = (sp[a0][a1].unk4.x > sp[a0][a1+a2].unk4.x) ? sp[a0][a1].unk4.x : sp[a0][a1+a2].unk4.x; - s32 yMax = sp[a0][a1 + a2].unk4.y; - u8 room = GetTile(sp[a0][a1].unk0.x, sp[a0][a1].unk0.y)->room; + s32 xStart = (grid[a0][a1].unk0.x < grid[a0][a1+a2].unk0.x) ? grid[a0][a1].unk0.x : grid[a0][a1+a2].unk0.x; + s32 yStart = grid[a0][a1].unk0.y; + s32 xMax = (grid[a0][a1].unk4.x > grid[a0][a1+a2].unk4.x) ? grid[a0][a1].unk4.x : grid[a0][a1+a2].unk4.x; + s32 yMax = grid[a0][a1 + a2].unk4.y; + u8 room = GetTile(grid[a0][a1].unk0.x, grid[a0][a1].unk0.y)->room; for (x = xStart; x < xMax; x++) { for (y = yStart; y < yMax; y++) { @@ -2371,14 +2368,217 @@ void sub_804C43C(s32 a0, s32 a1, s32 a2, struct UnkHugeSpStructSubUnk0 sp[15][15 } } - sp[a0][a1].unk0.x = xStart; - sp[a0][a1].unk4.x = xMax; - sp[a0][a1].unk0.y = yStart; - sp[a0][a1].unk4.y = yMax; - sp[a0][a1 + a2].unk18 = 1; - sp[a0][a1].unk18 = 1; - sp[a0][a1 + a2].unk11 = 0; - sp[a0][a1 + a2].unk17 = 1; + grid[a0][a1].unk0.x = xStart; + grid[a0][a1].unk4.x = xMax; + grid[a0][a1].unk0.y = yStart; + grid[a0][a1].unk4.y = yMax; + grid[a0][a1 + a2].unk18 = 1; + grid[a0][a1].unk18 = 1; + grid[a0][a1 + a2].unk11 = 0; + grid[a0][a1 + a2].unk17 = 1; +} + +void sub_804C53C(s32 x_, s32 y_, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 unk7200[GRID_CELL_LEN]; + s32 unk7260[GRID_CELL_LEN]; + s32 i, j; + s32 x = x_; + s32 y = y_; + + sub_804D024(unk7200, unk7260, x, y); + sub_804D084(grid, x, y); + for (i = 0; i < x; i++) { + for (j = 0; j < y; j++) { + grid[i][j].unk10 = 1; + } + } + + for (i = 1; i < x - 1; i++) { + for (j = 1; j < y - 1; j++) { + grid[i][j].unk8 = 1; + } + } + + sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); + for (i = 0; i < x - 1; i++) { + if (i != 0) { + grid[i][0].unk22 = 1; + grid[i][y-1].unk22 = 1; + } + if (i < x - 2) { + grid[i+1][0].unk21 = 1; + grid[i+1][y-1].unk21 = 1; + } + } + + for (j = 0; j < y - 1; j++) { + if (j != 0) { + grid[0][j].unk19 = 1; + grid[x-1][j].unk19 = 1; + } + if (j < y - 2) { + grid[0][j].unk20 = 1; + grid[x-1][j].unk20 = 1; + } + } + + sub_804D8C8(grid, x, y, unk7200, unk7260, 0); + sub_804E590(grid, x, y, unk7200, unk7260); + sub_804F0D0(grid, x, y, unkPtr->unk9); + sub_804EBC8(grid, x, y, gUnknown_202F1B0); + sub_804EEE4(grid, x, y, gUnknown_202F1B2); + sub_804CBEC(grid, x, y, unkPtr->unk13); + sub_804E03C(grid, x, y); + sub_804D534(grid, x, y); +} + +void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); +extern void sub_8051288(s32 a0); + +bool8 sub_804C70C(s32 a0, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct FileFixedmapPosStruct **fileData = (void *) gDungeon->unk13568->data; + s32 x1 = fileData[a0]->x; + s32 y1 = fileData[a0]->y; + s32 x2, y2; + + if (x1 == 0 || y1 == 0) { + sub_804C918(); + return FALSE; + } + else if (a0 < 50) { + sub_8051288(a0); + return TRUE; + } + else { + x2 = DUNGEON_MAX_SIZE_X / (x1 + 4); + if (x2 <= 1) + x2 = 1; + y2 = DUNGEON_MAX_SIZE_Y / (y1 + 4); + if (y2 <= 1) + y2 = 1; + sub_804C790(x2, y2, x1, y1, a0, unkPtr); + return FALSE; + } +} + +void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x1, s32 y1, s32 *a3, s32 *a4, s32 a5, s32 x2, s32 y2); +void sub_804D5F0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 x2, s32 y2, UnkDungeonGlobal_unk1C574 *unkPtr); +void sub_8051438(struct GridCell *cell, s32 a1); + +void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + s32 tries; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 unk7200[GRID_CELL_LEN]; + s32 unk7260[GRID_CELL_LEN]; + s32 r10 = 0; + s32 x3 = 0, y3 = 0; + + sub_804D024(unk7200, unk7260, x1, y1); + sub_804D084(grid, x1, y1); + sub_804D154(grid, x1, y1, unkPtr->unk1); + for (x3 = 0; x3 < x1; x3++) { + for (y3 = 0; y3 < y1; y3++) { + grid[x3][y3].unk27 = 1; + } + } + + for (tries = 0; tries < 64; tries++) { + x3 = DungeonRandInt(x1); + y3 = DungeonRandInt(y1); + r10 = y3 * x1 + x3; + if (grid[x3][y3].unk10) + break; + } + sub_8050F90(grid, x1, y1, unk7200, unk7260, r10, x2, y2); + if (x1 != 1 || y1 != 1) { + sub_804D5F0(grid, x1, y1, x3, y3, unkPtr); + sub_804D8C8(grid, x1, y1, unk7200, unk7260, 1); + sub_804E590(grid, x1, y1, unk7200, unk7260); + } + sub_8051438(&grid[x3][y3], a4); +} + +void sub_804C918(void) +{ + s32 i, j; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + + sub_804D084(grid, 1, 1); + grid[0][0].unk0.x = 2; + grid[0][0].unk4.x = DUNGEON_MAX_SIZE_X - 2; + grid[0][0].unk0.y = 2; + grid[0][0].unk4.y = DUNGEON_MAX_SIZE_Y - 2; + grid[0][0].unk10 = 1; + grid[0][0].unk11 = 1; + grid[0][0].unk8 = 0; + for (i = grid[0][0].unk0.x; i < grid[0][0].unk4.x; i++) { + for (j = grid[0][0].unk0.y; j < grid[0][0].unk4.y; j++) { + Tile *tile = GetTileSafe(i, j); + tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + tile->terrainType |= TERRAIN_TYPE_NORMAL; + // Unnecessary call again + GetTileSafe(i, j)->room = 0; + } + } + sub_804EEE4(grid, 1, 1, 999); +} + +void sub_804C9D0(void) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 currRoomId = 0; + s32 x, y; + + listX[0] = 2; + listX[1] = 28; + listX[2] = 54; + listY[0] = 2; + listY[1] = 30; + sub_804D084(grid, 2, 1); + + for (y = 0; y < 1; y++) { + for (x = 0; x < 2; x++) { + s32 currX, currY; + s32 minX = listX[x] + 1; + s32 minY = listY[y] + 1; + s32 rangeX = listX[x + 1] - listX[x] - 3; + s32 rangeY = listY[y + 1] - listY[y] - 3; + s32 roomSizeX = DungeonRandRange(10, rangeX); + s32 roomSizeY = DungeonRandRange(16, rangeY); + s32 startX = DungeonRandInt(rangeX - roomSizeX) + minX; + s32 startY = DungeonRandInt(rangeY - roomSizeY) + minY; + s32 endX = startX + roomSizeX; + s32 endY = startY + roomSizeY; + + grid[x][y].unk10 = 1; + grid[x][y].unk0.x = startX; + grid[x][y].unk4.x = endX; + grid[x][y].unk0.y = startY; + grid[x][y].unk4.y = endY; + + for (currX = startX; currX < endX; currX++) { + for (currY = startY; currY < endY; currY++) { + Tile *tile = GetTileSafe(currX, currY); + tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + tile->terrainType |= TERRAIN_TYPE_NORMAL; + // Unnecessary call again + GetTileSafe(currX, currY)->room = currRoomId; + } + } + currRoomId++; + } + } + + grid[0][0].unk22 = 1; + grid[1][0].unk21 = 1; + sub_804D8C8(grid, 2, 1, listX, listY, 0); + sub_804EEE4(grid, 2, 1, 999); } // From 2a678ca06c055f94512a111b61285f1965ffcad3 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 7 Nov 2024 23:28:16 +0100 Subject: [PATCH 04/30] start documenting dungeon generation --- asm/code_804AFAC.s | 54 +++--- include/global.h | 3 + src/code_804AFAC_1.c | 438 +++++++++++++++++++++++-------------------- 3 files changed, 263 insertions(+), 232 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 4239f3d66..c186dedb9 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -6,8 +6,8 @@ .text - thumb_func_start sub_804CBEC -sub_804CBEC: + thumb_func_start GenerateExtraHallways +GenerateExtraHallways: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -552,7 +552,7 @@ _0804D006: _0804D018: .4byte 0x0000fffc _0804D01C: .4byte gAdjacentTileOffsets _0804D020: .4byte gUnknown_202F1AE - thumb_func_end sub_804CBEC + thumb_func_end GenerateExtraHallways thumb_func_start sub_804D024 sub_804D024: @@ -607,8 +607,8 @@ _0804D072: bx r0 thumb_func_end sub_804D024 - thumb_func_start sub_804D084 -sub_804D084: + thumb_func_start InitDungeonGrid +InitDungeonGrid: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -720,10 +720,10 @@ _0804D144: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804D084 + thumb_func_end InitDungeonGrid - thumb_func_start sub_804D154 -sub_804D154: + thumb_func_start AssignRooms +AssignRooms: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -933,10 +933,10 @@ _0804D2BC: bx r0 .align 2, 0 _0804D2CC: .4byte gUnknown_202F1AD - thumb_func_end sub_804D154 + thumb_func_end AssignRooms - thumb_func_start sub_804D2D0 -sub_804D2D0: + thumb_func_start CreateRoomsAndAnchors +CreateRoomsAndAnchors: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -1257,7 +1257,7 @@ _0804D520: bx r0 .align 2, 0 _0804D530: .4byte 0x0000fffc - thumb_func_end sub_804D2D0 + thumb_func_end CreateRoomsAndAnchors thumb_func_start sub_804D534 sub_804D534: @@ -1772,8 +1772,8 @@ _0804D8B8: bx r0 thumb_func_end sub_804D5F0 - thumb_func_start sub_804D8C8 -sub_804D8C8: + thumb_func_start CreateGridCellConnections +CreateGridCellConnections: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -2801,10 +2801,10 @@ _0804E026: bx r0 .align 2, 0 _0804E038: .4byte 0x0000fffc - thumb_func_end sub_804D8C8 + thumb_func_end CreateGridCellConnections - thumb_func_start sub_804E03C -sub_804E03C: + thumb_func_start GenerateRoomImperfections +GenerateRoomImperfections: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -3217,7 +3217,7 @@ _0804E318: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804E03C + thumb_func_end GenerateRoomImperfections thumb_func_start sub_804E328 sub_804E328: @@ -3557,8 +3557,8 @@ _0804E57E: bx r0 thumb_func_end sub_804E328 - thumb_func_start sub_804E590 -sub_804E590: + thumb_func_start EnsureConnectedGrid +EnsureConnectedGrid: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -4096,7 +4096,7 @@ _0804E98A: _0804E99C: .4byte 0x0000fffc _0804E9A0: .4byte 0x0000fffe _0804E9A4: .4byte 0x0000fffd - thumb_func_end sub_804E590 + thumb_func_end EnsureConnectedGrid thumb_func_start sub_804E9A8 sub_804E9A8: @@ -4381,8 +4381,8 @@ _0804EBC0: .4byte 0x00010884 _0804EBC4: .4byte 0x00010886 thumb_func_end sub_804EB30 - thumb_func_start sub_804EBC8 -sub_804EBC8: + thumb_func_start GenerateKecleonShop +GenerateKecleonShop: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -4799,10 +4799,10 @@ _0804EED4: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804EBC8 + thumb_func_end GenerateKecleonShop - thumb_func_start sub_804EEE4 -sub_804EEE4: + thumb_func_start GenerateMonsterHouse +GenerateMonsterHouse: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -5062,7 +5062,7 @@ _0804F0C0: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804EEE4 + thumb_func_end GenerateMonsterHouse thumb_func_start sub_804F0D0 sub_804F0D0: diff --git a/include/global.h b/include/global.h index e833a5847..42de541c6 100644 --- a/include/global.h +++ b/include/global.h @@ -39,4 +39,7 @@ #define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0])) +#define min(a, b) ((a) < (b) ? (a) : (b)) +#define max(a, b) ((a) > (b) ? (a) : (b)) + #endif // GUARD_GLOBAL_H diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index a653a3f18..84058ac79 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -51,9 +51,9 @@ bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); void sub_804B634(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); void sub_804B72C(UnkDungeonGlobal_unk1C574 *a0); void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0); -void sub_804C0A8(UnkDungeonGlobal_unk1C574 *a0); -void sub_804C190(UnkDungeonGlobal_unk1C574 *a0); -void sub_804C2F4(UnkDungeonGlobal_unk1C574 *a0); +void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *a0); +void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0); +void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0); void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); void sub_80506F0(s32 a0, UnkDungeonGlobal_unk1C574 *a1); void sub_804FF08(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); @@ -191,14 +191,14 @@ void sub_804AFAC(void) gDungeon->unk3A08 = 1; break; case 6: - sub_804C0A8(unkPtr); + GenerateLineFloor(unkPtr); r10 = TRUE; break; case 7: - sub_804C190(unkPtr); + GenerateCrossFloor(unkPtr); break; case 9: - sub_804C2F4(unkPtr); + GenerateBeetleFloor(unkPtr); break; case 10: sub_804B634(x, y, unkPtr); @@ -656,18 +656,18 @@ void NAKED sub_804AFAC(void) "_0804B2C8: .4byte 0x00003a08\n" "_0804B2CC:\n" " mov r0, r8\n" -" bl sub_804C0A8\n" +" bl GenerateLineFloor\n" "_0804B2D2:\n" " movs r0, 0x1\n" " mov r10, r0\n" " b _0804B2F6\n" "_0804B2D8:\n" " mov r0, r8\n" -" bl sub_804C190\n" +" bl GenerateCrossFloor\n" " b _0804B2F6\n" "_0804B2E0:\n" " mov r0, r8\n" -" bl sub_804C2F4\n" +" bl GenerateBeetleFloor\n" " b _0804B2F6\n" "_0804B2E8:\n" " adds r0, r5, 0\n" @@ -1008,39 +1008,39 @@ struct GridCell #define GRID_CELL_LEN 15 void sub_804D024(s32 *a0, s32 *a1, s32 x, s32 y); -void sub_804D084(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y); -void sub_804E03C(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y); +void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); +void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); void sub_804D534(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y); -void sub_804D154(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); -void sub_804D2D0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); -void sub_804D8C8(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 *a3, s32 *a4, s32 a5); -void sub_804E590(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 *a3, s32 *a4); +void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 roomsNumber); +void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY, u32 roomFlags); +void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); +void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY); void sub_804D5B0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr); void sub_804F0D0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); -void sub_804EBC8(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); -void sub_804EEE4(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); -void sub_804CBEC(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); -void sub_804C43C(s32 a0, s32 a1, s32 a2, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); +void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); +void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); +void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 numExtraHallways); +static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); -void sub_804B634(s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr) +void sub_804B634(s32 sizeX, s32 sizeY, UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; - s32 unk7200[GRID_CELL_LEN]; - s32 unk7260[GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; - sub_804D024(unk7200, unk7260, x, y); - sub_804D084(grid, x, y); - sub_804D154(grid, x, y, unkPtr->unk1); - sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); - sub_804D5B0(grid, x, y, unkPtr); - sub_804D8C8(grid, x, y, unk7200, unk7260, 0); - sub_804E590(grid, x, y, unk7200, unk7260); - sub_804F0D0(grid, x, y, unkPtr->unk9); - sub_804EBC8(grid, x, y, gUnknown_202F1B0); - sub_804EEE4(grid, x, y, gUnknown_202F1B2); - sub_804CBEC(grid, x, y, unkPtr->unk13); - sub_804E03C(grid, x, y); - sub_804D534(grid, x, y); + sub_804D024(listX, listY, sizeX, sizeY); + InitDungeonGrid(grid, sizeX, sizeY); + AssignRooms(grid, sizeX, sizeY, unkPtr->unk1); + CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + sub_804D5B0(grid, sizeX, sizeY, unkPtr); + CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); + EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + sub_804F0D0(grid, sizeX, sizeY, unkPtr->unk9); + GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, sizeX, sizeY); + sub_804D534(grid, sizeX, sizeY); } // Decompile once data structure is better understood @@ -1050,21 +1050,21 @@ void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[15][15]; - sp.unk7200[0] = 0; - sp.unk7200[1] = 5; - sp.unk7200[3] = 28; - sp.unk7200[5] = 51 - sp.unk7200[6] = 56; - sp.unk7200[2] = 16; - sp.unk7200[4] = 29; + sp.listX[0] = 0; + sp.listX[1] = 5; + sp.listX[3] = 28; + sp.listX[5] = 51 + sp.listX[6] = 56; + sp.listX[2] = 16; + sp.listX[4] = 29; - sp.unk7260[0] = 2; - sp.unk7260[1] = 7; - sp.unk7260[2] = 16; - sp.unk7260[3] = 25; - sp.unk7260[4] = 30; + sp.listY[0] = 2; + sp.listY[1] = 7; + sp.listY[2] = 16; + sp.listY[3] = 25; + sp.listY[4] = 30; - sub_804D084(grid, 6, 4); + InitDungeonGrid(grid, 6, 4); } #else NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) @@ -1111,7 +1111,7 @@ NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) " add r0, sp, 0x8\n" " movs r1, 0x6\n" " movs r2, 0x4\n" -" bl sub_804D084\n" +" bl InitDungeonGrid\n" " mov r2, sp\n" " adds r2, 0x3B\n" " ldr r3, _0804B9B8\n" @@ -1614,27 +1614,27 @@ NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) " movs r1, 0x6\n" " movs r2, 0x4\n" " adds r3, r5, 0\n" -" bl sub_804D8C8\n" +" bl CreateGridCellConnections\n" " str r4, [sp]\n" " add r0, sp, 0x8\n" " movs r1, 0x6\n" " movs r2, 0x4\n" " adds r3, r5, 0\n" -" bl sub_804E590\n" +" bl EnsureConnectedGrid\n" " ldr r0, _0804BC78\n" " movs r5, 0\n" " ldrsh r3, [r0, r5]\n" " add r0, sp, 0x8\n" " movs r1, 0x6\n" " movs r2, 0x4\n" -" bl sub_804EBC8\n" +" bl GenerateKecleonShop\n" " ldr r0, _0804BC7C\n" " movs r1, 0\n" " ldrsh r3, [r0, r1]\n" " add r0, sp, 0x8\n" " movs r1, 0x6\n" " movs r2, 0x4\n" -" bl sub_804EEE4\n" +" bl GenerateMonsterHouse\n" " movs r2, 0xE5\n" " lsls r2, 5\n" " add r2, sp\n" @@ -1643,11 +1643,11 @@ NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) " add r0, sp, 0x8\n" " movs r1, 0x6\n" " movs r2, 0x4\n" -" bl sub_804CBEC\n" +" bl GenerateExtraHallways\n" " add r0, sp, 0x8\n" " movs r1, 0x6\n" " movs r2, 0x4\n" -" bl sub_804E03C\n" +" bl GenerateRoomImperfections\n" " movs r3, 0xE7\n" " lsls r3, 5\n" " add sp, r3\n" @@ -1748,7 +1748,7 @@ NAKED void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) " add r0, sp, 0x8\n" " movs r1, 0x5\n" " movs r2, 0x4\n" -" bl sub_804D084\n" +" bl InitDungeonGrid\n" " add r6, sp, 0x70\n" " add r1, sp, 0x68\n" " add r0, sp, 0x8\n" @@ -2173,27 +2173,27 @@ NAKED void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) " movs r1, 0x5\n" " movs r2, 0x4\n" " adds r3, r5, 0\n" -" bl sub_804D8C8\n" +" bl CreateGridCellConnections\n" " str r4, [sp]\n" " add r0, sp, 0x8\n" " movs r1, 0x5\n" " movs r2, 0x4\n" " adds r3, r5, 0\n" -" bl sub_804E590\n" +" bl EnsureConnectedGrid\n" " ldr r0, _0804C09C\n" " movs r2, 0\n" " ldrsh r3, [r0, r2]\n" " add r0, sp, 0x8\n" " movs r1, 0x5\n" " movs r2, 0x4\n" -" bl sub_804EBC8\n" +" bl GenerateKecleonShop\n" " ldr r0, _0804C0A0\n" " movs r4, 0\n" " ldrsh r3, [r0, r4]\n" " add r0, sp, 0x8\n" " movs r1, 0x5\n" " movs r2, 0x4\n" -" bl sub_804EEE4\n" +" bl GenerateMonsterHouse\n" " movs r5, 0xE5\n" " lsls r5, 5\n" " add r5, sp\n" @@ -2202,11 +2202,11 @@ NAKED void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) " add r0, sp, 0x8\n" " movs r1, 0x5\n" " movs r2, 0x4\n" -" bl sub_804CBEC\n" +" bl GenerateExtraHallways\n" " add r0, sp, 0x8\n" " movs r1, 0x5\n" " movs r2, 0x4\n" -" bl sub_804E03C\n" +" bl GenerateRoomImperfections\n" " ldr r3, _0804C0A4\n" " add sp, r3\n" " pop {r3-r5}\n" @@ -2230,165 +2230,193 @@ NAKED void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) } #endif // NONMATCHING -void sub_804C0A8(UnkDungeonGlobal_unk1C574 *unkPtr) +// GenerateLineFloor - Generates a floor layout with 5 grid cells in a horizontal line. +void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; - s32 unk7200[GRID_CELL_LEN]; - s32 unk7260[GRID_CELL_LEN]; - s32 x, y, unk; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 sizeX, sizeY; + bool8 disableRoomMerging; - unk7200[0] = 0; - unk7200[1] = 11; - unk7200[2] = 22; - unk7200[3] = 33; - unk7200[4] = 44; - unk7200[5] = 56; + listX[0] = 0; + listX[1] = 11; + listX[2] = 22; + listX[3] = 33; + listX[4] = 44; + listX[5] = 56; - unk7260[0] = 4; - unk7260[1] = 15; + listY[0] = 4; + listY[1] = 15; - unk = 1; - x = 5, y = 1; - sub_804D084(grid, x, y); - sub_804D154(grid, x, y, unkPtr->unk1); - sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); - sub_804D5B0(grid, x, y, unkPtr); - sub_804D8C8(grid, x, y, unk7200, unk7260, unk); - sub_804E590(grid, x, y, unk7200, unk7260); - sub_804EBC8(grid, x, y, gUnknown_202F1B0); - sub_804EEE4(grid, x, y, gUnknown_202F1B2); - sub_804CBEC(grid, x, y, unkPtr->unk13); - sub_804E03C(grid, x, y); + disableRoomMerging = 1; + sizeX = 5, sizeY = 1; + InitDungeonGrid(grid, sizeX, sizeY); + + AssignRooms(grid, sizeX, sizeY, unkPtr->unk1); + CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + + sub_804D5B0(grid, sizeX, sizeY, unkPtr); + CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, disableRoomMerging); + + EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + + GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + + GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, sizeX, sizeY); } -void sub_804C190(UnkDungeonGlobal_unk1C574 *unkPtr) +// GenerateCrossFloor - Generates a floor layout with 5 rooms arranged in a "plus" or "cross" configuration. +void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; - s32 unk7200[GRID_CELL_LEN]; - s32 unk7260[GRID_CELL_LEN]; - s32 i, j, x, y; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 x, y, sizeX, sizeY; - unk7200[0] = 11; - unk7200[1] = 22; - unk7200[2] = 33; - unk7200[3] = 44; + listX[0] = 11; + listX[1] = 22; + listX[2] = 33; + listX[3] = 44; - unk7260[0] = 2; - unk7260[1] = 11; - unk7260[2] = 20; - unk7260[3] = 30; + listY[0] = 2; + listY[1] = 11; + listY[2] = 20; + listY[3] = 30; - x = 3, y = 3; - sub_804D084(grid, x, y); - for (i = 0; i < x; i++) { - for (j = 0; j < y; j++) { - grid[i][j].unk10 = 1; - } - } - grid[0][0].unk8 = 1; - grid[2][0].unk8 = 1; - grid[0][2].unk8 = 1; - grid[2][2].unk8 = 1; + sizeX = 3, sizeY = 3; + InitDungeonGrid(grid, sizeX, sizeY); - sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); - - grid[0][1].unk22 = 1; - grid[1][1].unk21 = 1; - grid[1][1].unk22 = 1; - grid[2][1].unk21 = 1; - grid[1][0].unk20 = 1; - grid[1][1].unk19 = 1; - grid[1][1].unk20 = 1; - grid[1][2].unk19 = 1; - sub_804D8C8(grid, x, y, unk7200, unk7260, 1); - sub_804E590(grid, x, y, unk7200, unk7260); - sub_804EBC8(grid, x, y, gUnknown_202F1B0); - sub_804EEE4(grid, x, y, gUnknown_202F1B2); - sub_804CBEC(grid, x, y, unkPtr->unk13); - sub_804E03C(grid, x, y); -} - -void sub_804C2F4(UnkDungeonGlobal_unk1C574 *unkPtr) -{ - struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; - s32 unk7200[GRID_CELL_LEN]; - s32 unk7260[GRID_CELL_LEN]; - s32 i, j, x, y; - - unk7200[0] = 5; - unk7200[1] = 15; - unk7200[2] = 35; - unk7200[3] = 50; - - unk7260[0] = 2; - unk7260[1] = 11; - unk7260[2] = 20; - unk7260[3] = 30; - - x = 3, y = 3; - sub_804D084(grid, x, y); - for (i = 0; i < x; i++) { - for (j = 0; j < y; j++) { - grid[i][j].unk10 = 1; + // Set all cells as rooms + for (x = 0; x < sizeX; x++) { + for (y = 0; y < sizeY; y++) { + grid[x][y].unk10 = TRUE; } } - sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); - for (j = 0; j < 3; j++) { - grid[0][j].unk22 = 1; - grid[1][j].unk21 = 1; - grid[1][j].unk22 = 1; - grid[2][j].unk21 = 1; - } - sub_804D8C8(grid, x, y, unk7200, unk7260, 1); - sub_804C43C(1, 0, 1, grid); - sub_804C43C(1, 0, 2, grid); - sub_804E590(grid, x, y, unk7200, unk7260); - sub_804EBC8(grid, x, y, gUnknown_202F1B0); - sub_804EEE4(grid, x, y, gUnknown_202F1B2); - sub_804CBEC(grid, x, y, unkPtr->unk13); - sub_804E03C(grid, x, y); + // Invalidate the corners + grid[0][0].unk8 = TRUE; + grid[2][0].unk8 = TRUE; + grid[0][2].unk8 = TRUE; + grid[2][2].unk8 = TRUE; + + CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + + grid[0][1].unk22 = TRUE; + grid[1][1].unk21 = TRUE; + grid[1][1].unk22 = TRUE; + grid[2][1].unk21 = TRUE; + grid[1][0].unk20 = TRUE; + grid[1][1].unk19 = TRUE; + grid[1][1].unk20 = TRUE; + grid[1][2].unk19 = TRUE; + CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, TRUE); + + EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + + GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + + GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, sizeX, sizeY); } -void sub_804C43C(s32 a0, s32 a1, s32 a2, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]) +// GenerateBeetleFloor - Generates a floor layout in a "beetle" shape, with a +// 3x3 grid of rooms, a merged center column, and hallways along each row +void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 x, y, sizeX, sizeY; + + listX[0] = 5; + listX[1] = 15; + listX[2] = 35; + listX[3] = 50; + + listY[0] = 2; + listY[1] = 11; + listY[2] = 20; + listY[3] = 30; + + sizeX = 3, sizeY = 3; + InitDungeonGrid(grid, sizeX, sizeY); + // Set all cells as rooms + for (x = 0; x < sizeX; x++) { + for (y = 0; y < sizeY; y++) { + grid[x][y].unk10 = TRUE; + } + } + + CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + + // Connect rooms in the same row together + for (y = 0; y < 3; y++) { + grid[0][y].unk22 = TRUE; + grid[1][y].unk21 = TRUE; + grid[1][y].unk22 = TRUE; + grid[2][y].unk21 = TRUE; + } + CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, TRUE); + + // Merge the center column into one large room + MergeRoomsVertically(1, 0, 1, grid); + MergeRoomsVertically(1, 0, 2, grid); + + EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + + GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + + GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, sizeX, sizeY); +} + +// MergeRoomsVertically - Merges two vertically stacked rooms into one larger room. +static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]) { s32 x, y; - s32 xStart = (grid[a0][a1].unk0.x < grid[a0][a1+a2].unk0.x) ? grid[a0][a1].unk0.x : grid[a0][a1+a2].unk0.x; - s32 yStart = grid[a0][a1].unk0.y; - s32 xMax = (grid[a0][a1].unk4.x > grid[a0][a1+a2].unk4.x) ? grid[a0][a1].unk4.x : grid[a0][a1+a2].unk4.x; - s32 yMax = grid[a0][a1 + a2].unk4.y; - u8 room = GetTile(grid[a0][a1].unk0.x, grid[a0][a1].unk0.y)->room; + s32 xStart = min(grid[roomX][room_y1].unk0.x, grid[roomX][room_y1+room_dy].unk0.x); + s32 yStart = grid[roomX][room_y1].unk0.y; + s32 xEnd = max(grid[roomX][room_y1].unk4.x, grid[roomX][room_y1+room_dy].unk4.x); + s32 yEnd = grid[roomX][room_y1 + room_dy].unk4.y; - for (x = xStart; x < xMax; x++) { - for (y = yStart; y < yMax; y++) { + // Carve out the new larger room, retaining the index of the first room + u8 roomId = GetTile(grid[roomX][room_y1].unk0.x, grid[roomX][room_y1].unk0.y)->room; + + for (x = xStart; x < xEnd; x++) { + for (y = yStart; y < yEnd; y++) { Tile *tile = GetTileSafe(x, y); tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); tile->terrainType |= TERRAIN_TYPE_NORMAL; - tile->room = room; + tile->room = roomId; } } - grid[a0][a1].unk0.x = xStart; - grid[a0][a1].unk4.x = xMax; - grid[a0][a1].unk0.y = yStart; - grid[a0][a1].unk4.y = yMax; - grid[a0][a1 + a2].unk18 = 1; - grid[a0][a1].unk18 = 1; - grid[a0][a1 + a2].unk11 = 0; - grid[a0][a1 + a2].unk17 = 1; + grid[roomX][room_y1].unk0.x = xStart; + grid[roomX][room_y1].unk4.x = xEnd; + grid[roomX][room_y1].unk0.y = yStart; + grid[roomX][room_y1].unk4.y = yEnd; + grid[roomX][room_y1 + room_dy].unk18 = TRUE; + grid[roomX][room_y1].unk18 = TRUE; + grid[roomX][room_y1 + room_dy].unk11 = FALSE; + grid[roomX][room_y1 + room_dy].unk17 = TRUE; } void sub_804C53C(s32 x_, s32 y_, UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; - s32 unk7200[GRID_CELL_LEN]; - s32 unk7260[GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; s32 i, j; s32 x = x_; s32 y = y_; - sub_804D024(unk7200, unk7260, x, y); - sub_804D084(grid, x, y); + sub_804D024(listX, listY, x, y); + InitDungeonGrid(grid, x, y); for (i = 0; i < x; i++) { for (j = 0; j < y; j++) { grid[i][j].unk10 = 1; @@ -2401,7 +2429,7 @@ void sub_804C53C(s32 x_, s32 y_, UnkDungeonGlobal_unk1C574 *unkPtr) } } - sub_804D2D0(grid, x, y, unk7200, unk7260, unkPtr->unkD); + CreateRoomsAndAnchors(grid, x, y, listX, listY, unkPtr->unkD); for (i = 0; i < x - 1; i++) { if (i != 0) { grid[i][0].unk22 = 1; @@ -2424,13 +2452,13 @@ void sub_804C53C(s32 x_, s32 y_, UnkDungeonGlobal_unk1C574 *unkPtr) } } - sub_804D8C8(grid, x, y, unk7200, unk7260, 0); - sub_804E590(grid, x, y, unk7200, unk7260); + CreateGridCellConnections(grid, x, y, listX, listY, FALSE); + EnsureConnectedGrid(grid, x, y, listX, listY); sub_804F0D0(grid, x, y, unkPtr->unk9); - sub_804EBC8(grid, x, y, gUnknown_202F1B0); - sub_804EEE4(grid, x, y, gUnknown_202F1B2); - sub_804CBEC(grid, x, y, unkPtr->unk13); - sub_804E03C(grid, x, y); + GenerateKecleonShop(grid, x, y, gUnknown_202F1B0); + GenerateMonsterHouse(grid, x, y, gUnknown_202F1B2); + GenerateExtraHallways(grid, x, y, unkPtr->unk13); + GenerateRoomImperfections(grid, x, y); sub_804D534(grid, x, y); } @@ -2472,14 +2500,14 @@ void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C5 { s32 tries; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; - s32 unk7200[GRID_CELL_LEN]; - s32 unk7260[GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; s32 r10 = 0; s32 x3 = 0, y3 = 0; - sub_804D024(unk7200, unk7260, x1, y1); - sub_804D084(grid, x1, y1); - sub_804D154(grid, x1, y1, unkPtr->unk1); + sub_804D024(listX, listY, x1, y1); + InitDungeonGrid(grid, x1, y1); + AssignRooms(grid, x1, y1, unkPtr->unk1); for (x3 = 0; x3 < x1; x3++) { for (y3 = 0; y3 < y1; y3++) { grid[x3][y3].unk27 = 1; @@ -2493,11 +2521,11 @@ void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C5 if (grid[x3][y3].unk10) break; } - sub_8050F90(grid, x1, y1, unk7200, unk7260, r10, x2, y2); + sub_8050F90(grid, x1, y1, listX, listY, r10, x2, y2); if (x1 != 1 || y1 != 1) { sub_804D5F0(grid, x1, y1, x3, y3, unkPtr); - sub_804D8C8(grid, x1, y1, unk7200, unk7260, 1); - sub_804E590(grid, x1, y1, unk7200, unk7260); + CreateGridCellConnections(grid, x1, y1, listX, listY, TRUE); + EnsureConnectedGrid(grid, x1, y1, listX, listY); } sub_8051438(&grid[x3][y3], a4); } @@ -2507,7 +2535,7 @@ void sub_804C918(void) s32 i, j; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; - sub_804D084(grid, 1, 1); + InitDungeonGrid(grid, 1, 1); grid[0][0].unk0.x = 2; grid[0][0].unk4.x = DUNGEON_MAX_SIZE_X - 2; grid[0][0].unk0.y = 2; @@ -2524,7 +2552,7 @@ void sub_804C918(void) GetTileSafe(i, j)->room = 0; } } - sub_804EEE4(grid, 1, 1, 999); + GenerateMonsterHouse(grid, 1, 1, 999); } void sub_804C9D0(void) @@ -2540,7 +2568,7 @@ void sub_804C9D0(void) listX[2] = 54; listY[0] = 2; listY[1] = 30; - sub_804D084(grid, 2, 1); + InitDungeonGrid(grid, 2, 1); for (y = 0; y < 1; y++) { for (x = 0; x < 2; x++) { @@ -2577,8 +2605,8 @@ void sub_804C9D0(void) grid[0][0].unk22 = 1; grid[1][0].unk21 = 1; - sub_804D8C8(grid, 2, 1, listX, listY, 0); - sub_804EEE4(grid, 2, 1, 999); + CreateGridCellConnections(grid, 2, 1, listX, listY, FALSE); + GenerateMonsterHouse(grid, 2, 1, 999); } // From cf6e42ae19ac7e536daf750efbc603a3cff3013a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 8 Nov 2024 11:15:52 +0100 Subject: [PATCH 05/30] GenerateExtraHallways --- asm/code_804AFAC.s | 566 +--------------------------------- include/constants/direction.h | 1 + src/code_804AFAC_1.c | 481 +++++++++++++++++++++++------ 3 files changed, 392 insertions(+), 656 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index c186dedb9..a6c499ff7 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -6,556 +6,8 @@ .text - thumb_func_start GenerateExtraHallways -GenerateExtraHallways: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - str r3, [sp, 0xC] - cmp r3, 0 - bne _0804CC06 - b _0804D006 -_0804CC06: - movs r5, 0 - cmp r5, r3 - blt _0804CC0E - b _0804D006 -_0804CC0E: - ldr r0, [sp, 0x4] - bl DungeonRandInt - mov r9, r0 - ldr r0, [sp, 0x8] - bl DungeonRandInt - mov r10, r0 - lsls r0, 5 - mov r2, r9 - lsls r1, r2, 4 - subs r1, r2 - lsls r1, 5 - ldr r3, [sp] - adds r1, r3 - adds r4, r0, r1 - ldrb r0, [r4, 0xA] - adds r5, 0x1 - str r5, [sp, 0x18] - cmp r0, 0 - bne _0804CC3A - b _0804CFFC -_0804CC3A: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _0804CC42 - b _0804CFFC -_0804CC42: - ldrb r0, [r4, 0x8] - cmp r0, 0 - beq _0804CC4A - b _0804CFFC -_0804CC4A: - ldrb r0, [r4, 0x10] - cmp r0, 0 - beq _0804CC52 - b _0804CFFC -_0804CC52: - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x4 - ldrsh r1, [r4, r2] - bl DungeonRandRange - adds r7, r0, 0 - movs r3, 0x2 - ldrsh r0, [r4, r3] - movs r2, 0x6 - ldrsh r1, [r4, r2] - bl DungeonRandRange - adds r6, r0, 0 - movs r0, 0x4 - bl DungeonRandInt - lsls r0, 1 - mov r8, r0 - ldr r1, [sp, 0x8] - subs r1, 0x1 - movs r3, 0x2 - str r3, [sp, 0x10] - ldr r0, [sp, 0x4] - subs r0, 0x1 -_0804CC84: - mov r2, r8 - cmp r2, 0 - bne _0804CC92 - cmp r10, r1 - blt _0804CC92 - movs r3, 0x2 - mov r8, r3 -_0804CC92: - mov r2, r8 - cmp r2, 0x2 - bne _0804CCA0 - cmp r9, r0 - blt _0804CCA0 - movs r3, 0x4 - mov r8, r3 -_0804CCA0: - mov r2, r8 - cmp r2, 0x4 - bne _0804CCB0 - mov r3, r10 - cmp r3, 0 - bgt _0804CCB0 - movs r2, 0x6 - mov r8, r2 -_0804CCB0: - mov r3, r8 - cmp r3, 0x6 - bne _0804CCC0 - mov r2, r9 - cmp r2, 0 - bgt _0804CCC0 - movs r3, 0 - mov r8, r3 -_0804CCC0: - ldr r2, [sp, 0x10] - subs r2, 0x1 - str r2, [sp, 0x10] - cmp r2, 0 - bge _0804CC84 - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrb r5, [r0, 0x9] - ldr r1, _0804CCE0 - mov r3, r8 - lsls r0, r3, 2 - adds r4, r0, r1 - b _0804CCF0 - .align 2, 0 -_0804CCE0: .4byte gAdjacentTileOffsets -_0804CCE4: - movs r1, 0 - ldrsh r0, [r4, r1] - adds r7, r0 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r6, r0 -_0804CCF0: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r5, r0 - beq _0804CCE4 - ldr r1, _0804CD08 - mov r3, r8 - lsls r0, r3, 2 - adds r4, r0, r1 - b _0804CD18 - .align 2, 0 -_0804CD08: .4byte gAdjacentTileOffsets -_0804CD0C: - movs r1, 0 - ldrsh r0, [r4, r1] - adds r7, r0 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r6, r0 -_0804CD18: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - beq _0804CD0C - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x2 - bne _0804CD40 - b _0804CFFC -_0804CD40: - movs r3, 0 - subs r2, r7, 0x2 - adds r4, r7, 0x2 - b _0804CD4A -_0804CD48: - adds r2, 0x1 -_0804CD4A: - cmp r2, r4 - bgt _0804CD6C - subs r0, r6, 0x2 - adds r1, r6, 0x2 - b _0804CD56 -_0804CD54: - adds r0, 0x1 -_0804CD56: - cmp r0, r1 - bgt _0804CD68 - cmp r2, 0x37 - bhi _0804CD66 - cmp r0, 0 - blt _0804CD66 - cmp r0, 0x1F - ble _0804CD54 -_0804CD66: - movs r3, 0x1 -_0804CD68: - cmp r3, 0 - beq _0804CD48 -_0804CD6C: - cmp r3, 0 - beq _0804CD72 - b _0804CFFC -_0804CD72: - ldr r2, _0804CDD4 - mov r1, r8 - adds r1, 0x2 - movs r4, 0x6 - ands r1, r4 - lsls r1, 2 - adds r1, r2 - movs r3, 0 - ldrsh r0, [r1, r3] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - ldr r2, [sp, 0x1C] - cmp r0, 0x1 - bne _0804CDA2 - b _0804CFFC -_0804CDA2: - mov r1, r8 - subs r1, 0x2 - ands r1, r4 - lsls r1, 2 - adds r1, r2 - movs r2, 0 - ldrsh r0, [r1, r2] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CDC8 - b _0804CFFC -_0804CDC8: - movs r0, 0x3 - bl DungeonRandInt - adds r0, 0x3 - str r0, [sp, 0x10] - b _0804CFD4 - .align 2, 0 -_0804CDD4: .4byte gAdjacentTileOffsets -_0804CDD8: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _0804CDEC - b _0804CFFC -_0804CDEC: - movs r0, 0x1 - str r0, [sp, 0x14] - adds r4, r7, 0x1 - adds r0, r4, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - mov r0, r10 - ands r0, r1 - mov r9, r4 - cmp r0, 0x1 - bne _0804CE32 - adds r5, r6, 0x1 - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTile - ldrh r0, [r0] - mov r4, r10 - ands r4, r0 - cmp r4, 0x1 - bne _0804CE32 - adds r0, r7, 0 - adds r1, r5, 0 - bl GetTile - ldrh r0, [r0] - mov r1, r10 - ands r0, r1 - eors r0, r4 - negs r1, r0 - orrs r1, r0 - lsrs r1, 31 - str r1, [sp, 0x14] -_0804CE32: - mov r0, r9 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CE70 - subs r4, r6, 0x1 - mov r0, r9 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CE70 - adds r0, r7, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CE70 - movs r2, 0 - str r2, [sp, 0x14] -_0804CE70: - subs r4, r7, 0x1 - adds r0, r4, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r2, 0x3 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEB6 - adds r5, r6, 0x1 - adds r0, r4, 0 - adds r1, r5, 0 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEB6 - adds r0, r7, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEB6 - movs r3, 0 - str r3, [sp, 0x14] -_0804CEB6: - adds r0, r4, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r2, 0x3 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEFA - subs r5, r6, 0x1 - adds r0, r4, 0 - adds r1, r5, 0 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEFA - adds r0, r7, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEFA - movs r0, 0 - str r0, [sp, 0x14] -_0804CEFA: - ldr r1, [sp, 0x14] - cmp r1, 0 - beq _0804CF16 - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTileSafe - ldrh r1, [r0] - ldr r3, _0804D018 - adds r2, r3, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] -_0804CF16: - ldr r2, _0804D01C - movs r0, 0x2 - add r0, r8 - mov r9, r0 - movs r1, 0x6 - mov r10, r1 - mov r1, r9 - mov r3, r10 - ands r1, r3 - lsls r1, 2 - adds r1, r2 - movs r3, 0 - ldrsh r0, [r1, r3] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - ldr r2, [sp, 0x1C] - cmp r0, 0x1 - beq _0804CFFC - mov r4, r8 - subs r4, 0x2 - adds r1, r4, 0 - mov r0, r10 - ands r1, r0 - lsls r1, 2 - adds r1, r2 - movs r2, 0 - ldrsh r0, [r1, r2] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - beq _0804CFFC - ldr r0, [sp, 0x10] - subs r0, 0x1 - str r0, [sp, 0x10] - cmp r0, 0 - bne _0804CFC0 - movs r0, 0x3 - bl DungeonRandInt - adds r0, 0x3 - str r0, [sp, 0x10] - movs r0, 0x64 - bl DungeonRandInt - mov r8, r4 - cmp r0, 0x31 - bgt _0804CF96 - mov r8, r9 -_0804CF96: - mov r1, r8 - mov r2, r10 - ands r1, r2 - mov r8, r1 - cmp r7, 0x1F - ble _0804CFAE - ldr r0, _0804D020 - ldrb r0, [r0] - cmp r0, 0x1 - bne _0804CFAE - cmp r1, 0x2 - beq _0804CFFC -_0804CFAE: - cmp r7, 0x2F - ble _0804CFC0 - ldr r0, _0804D020 - ldrb r0, [r0] - cmp r0, 0x2 - bne _0804CFC0 - mov r3, r8 - cmp r3, 0x2 - beq _0804CFFC -_0804CFC0: - ldr r0, _0804D01C - mov r2, r8 - lsls r1, r2, 2 - adds r1, r0 - movs r3, 0 - ldrsh r0, [r1, r3] - adds r7, r0 - movs r2, 0x2 - ldrsh r0, [r1, r2] - adds r6, r0 -_0804CFD4: - cmp r7, 0x1 - ble _0804CFFC - cmp r6, 0x1 - ble _0804CFFC - cmp r7, 0x36 - bgt _0804CFFC - cmp r6, 0x1E - bgt _0804CFFC - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r3, 0x3 - mov r10, r3 - mov r0, r10 - ands r0, r1 - cmp r0, 0x1 - beq _0804CFFC - b _0804CDD8 -_0804CFFC: - ldr r5, [sp, 0x18] - ldr r0, [sp, 0xC] - cmp r5, r0 - bge _0804D006 - b _0804CC0E -_0804D006: - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804D018: .4byte 0x0000fffc -_0804D01C: .4byte gAdjacentTileOffsets -_0804D020: .4byte gUnknown_202F1AE - thumb_func_end GenerateExtraHallways - - thumb_func_start sub_804D024 -sub_804D024: + thumb_func_start GetGridPositions +GetGridPositions: push {r4-r7,lr} mov r7, r8 push {r7} @@ -605,7 +57,7 @@ _0804D072: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804D024 + thumb_func_end GetGridPositions thumb_func_start InitDungeonGrid InitDungeonGrid: @@ -1259,8 +711,8 @@ _0804D520: _0804D530: .4byte 0x0000fffc thumb_func_end CreateRoomsAndAnchors - thumb_func_start sub_804D534 -sub_804D534: + thumb_func_start GenerateSecondaryStructures +GenerateSecondaryStructures: push {r4-r7,lr} mov r7, r9 mov r6, r8 @@ -1326,7 +778,7 @@ _0804D5A0: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804D534 + thumb_func_end GenerateSecondaryStructures thumb_func_start sub_804D5B0 sub_804D5B0: @@ -5064,8 +4516,8 @@ _0804F0C0: bx r0 thumb_func_end GenerateMonsterHouse - thumb_func_start sub_804F0D0 -sub_804F0D0: + thumb_func_start GenerateMazeRoom +GenerateMazeRoom: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -5288,7 +4740,7 @@ _0804F266: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804F0D0 + thumb_func_end GenerateMazeRoom thumb_func_start sub_804F278 sub_804F278: diff --git a/include/constants/direction.h b/include/constants/direction.h index 7c5cec5c2..73fbdea0e 100644 --- a/include/constants/direction.h +++ b/include/constants/direction.h @@ -2,6 +2,7 @@ #define GUARD_CONSTANTS_DIRECTION_H #define DIRECTION_MASK 7 +#define DIRECTION_MASK_CARDINAL 6 // Only South, Easy, North and West enum Direction { diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 84058ac79..1c62d8ebf 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -3,6 +3,7 @@ #include "tile_types.h" #include "dungeon_map_access.h" #include "dungeon_random.h" +#include "constants/direction.h" #include "structs/str_dungeon.h" #include "structs/map.h" @@ -37,23 +38,26 @@ extern void sub_804FD30(void); extern void sub_804FD30(void); extern void sub_80518F0(void); extern void sub_804FCCC(void); -extern void sub_804C918(void); +extern void GenerateOneRoomMonsterHouseFloor(void); extern void sub_804FBE8(void); extern void sub_804FC74(void); extern void sub_804E9DC(void); -extern void sub_804C9D0(void); +extern void GenerateTwoRoomsWithMonsterHouseFloor(void); extern u8 sub_8043D10(); extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); +extern const Position gAdjacentTileOffsets[]; + void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); -void sub_804B634(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); +void GenerateStandardFloor(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); void sub_804B72C(UnkDungeonGlobal_unk1C574 *a0); void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0); void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0); +void GenerateOuterRoomsFloor(s32 sizeX_, s32 sizeY_, UnkDungeonGlobal_unk1C574 *unkPtr); void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); void sub_80506F0(s32 a0, UnkDungeonGlobal_unk1C574 *a1); void sub_804FF08(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); @@ -160,22 +164,22 @@ void sub_804AFAC(void) case 1: y = DungeonRandInt(2) + 2; gUnknown_202F1AE = 1; - sub_804B634(4, y, unkPtr); + GenerateStandardFloor(4, y, unkPtr); r10 = TRUE; break; case 11: y = DungeonRandInt(2) + 2; gUnknown_202F1AE = 2; - sub_804B634(4, y, unkPtr); + GenerateStandardFloor(4, y, unkPtr); r10 = TRUE; break; case 0: default: - sub_804B634(x, y, unkPtr); + GenerateStandardFloor(x, y, unkPtr); r10 = TRUE; break; case 2: - sub_804C918(); + GenerateOneRoomMonsterHouseFloor(); gDungeon->unk3A08 = 1; break; case 3: @@ -187,7 +191,7 @@ void sub_804AFAC(void) r10 = TRUE; break; case 5: - sub_804C9D0(); + GenerateTwoRoomsWithMonsterHouseFloor(); gDungeon->unk3A08 = 1; break; case 6: @@ -201,7 +205,7 @@ void sub_804AFAC(void) GenerateBeetleFloor(unkPtr); break; case 10: - sub_804B634(x, y, unkPtr); + GenerateOuterRoomsFloor(x, y, unkPtr); r10 = TRUE; break; } @@ -247,7 +251,7 @@ void sub_804AFAC(void) if (j == 10) { gUnknown_202F1D8.x = -1; gUnknown_202F1D8.y = -1; - sub_804C918(); + GenerateOneRoomMonsterHouseFloor(); gDungeon->unk3A08 = 1; } sub_804E9DC(); @@ -271,7 +275,7 @@ void sub_804AFAC(void) gUnknown_202F1D8.x = -1; gUnknown_202F1D8.y = -1; sub_804FD30(); - sub_804C918(); + GenerateOneRoomMonsterHouseFloor(); gDungeon->unk3A08 = 1; sub_804E9DC(); sub_804FF08(unkPtr, FALSE); @@ -592,7 +596,7 @@ void NAKED sub_804AFAC(void) " movs r0, 0x4\n" " adds r1, r4, 0\n" " mov r2, r8\n" -" bl sub_804B634\n" +" bl GenerateStandardFloor\n" " b _0804B2AA\n" " .align 2, 0\n" "_0804B24C: .4byte gUnknown_202F1AE\n" @@ -606,7 +610,7 @@ void NAKED sub_804AFAC(void) " movs r0, 0x4\n" " adds r1, r4, 0\n" " mov r2, r8\n" -" bl sub_804B634\n" +" bl GenerateStandardFloor\n" " movs r6, 0x1\n" " mov r10, r6\n" " b _0804B2F6\n" @@ -616,10 +620,10 @@ void NAKED sub_804AFAC(void) " adds r0, r5, 0\n" " adds r1, r4, 0\n" " mov r2, r8\n" -" bl sub_804B634\n" +" bl GenerateStandardFloor\n" " b _0804B2D2\n" "_0804B280:\n" -" bl sub_804C918\n" +" bl GenerateOneRoomMonsterHouseFloor\n" " ldr r0, _0804B290\n" " ldr r0, [r0]\n" " ldr r1, _0804B294\n" @@ -642,7 +646,7 @@ void NAKED sub_804AFAC(void) " mov r10, r3\n" " b _0804B2F6\n" "_0804B2B0:\n" -" bl sub_804C9D0\n" +" bl GenerateTwoRoomsWithMonsterHouseFloor\n" " ldr r0, _0804B2C4\n" " ldr r0, [r0]\n" " ldr r6, _0804B2C8\n" @@ -673,7 +677,7 @@ void NAKED sub_804AFAC(void) " adds r0, r5, 0\n" " adds r1, r4, 0\n" " mov r2, r8\n" -" bl sub_804C53C\n" +" bl GenerateOuterRoomsFloor\n" " movs r1, 0x1\n" " mov r10, r1\n" "_0804B2F6:\n" @@ -755,7 +759,7 @@ void NAKED sub_804AFAC(void) " movs r0, 0x1\n" " negs r0, r0\n" " strh r0, [r1, 0x2]\n" -" bl sub_804C918\n" +" bl GenerateOneRoomMonsterHouseFloor\n" " ldr r0, _0804B4C0\n" " ldr r0, [r0]\n" " ldr r1, _0804B4C4\n" @@ -848,7 +852,7 @@ void NAKED sub_804AFAC(void) " negs r0, r0\n" " strh r0, [r1, 0x2]\n" " bl sub_804FD30\n" -" bl sub_804C918\n" +" bl GenerateOneRoomMonsterHouseFloor\n" " ldr r0, _0804B4C0\n" " ldr r0, [r0]\n" " ldr r1, _0804B4C4\n" @@ -977,8 +981,8 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) struct GridCell { - Position unk0; - Position unk4; + Position start; + Position end; u8 unk8; u8 unk9; u8 unk10; @@ -1007,40 +1011,59 @@ struct GridCell #define GRID_CELL_LEN 15 -void sub_804D024(s32 *a0, s32 *a1, s32 x, s32 y); +void GetGridPositions(s32 *listX, s32 *listY, s32 sizeX, s32 sizeY); void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); -void sub_804D534(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y); +void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 roomsNumber); void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY, u32 roomFlags); void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY); void sub_804D5B0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr); -void sub_804F0D0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 a3); +void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 numExtraHallways); static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); -void sub_804B634(s32 sizeX, s32 sizeY, UnkDungeonGlobal_unk1C574 *unkPtr) +/* + * GenerateStandardFloor - Generates a standard, typical floor layout. + * + * Overview: + * 1. Determine the grid based on sizeX, sizeY + * 2. Assign and create rooms and hallway anchors to each grid cell + * 3. Assign and create connections between grid cells (these are traditional hallways connecting the map together) + * 4. Fix any unconnected grid cells by adding more connections or removing their rooms/hallway anchors + * 5. Generate special rooms like a Maze Room (unused in vanilla?), Kecleon Shop, or Monster House + * 6. Create additional "extra hallways" with random walks outside of existing rooms + * 7. Finalize extra room details with imperfections (unused in vanilla?), and structures with secondary terrain + */ +void GenerateStandardFloor(s32 sizeX, s32 sizeY, UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; - sub_804D024(listX, listY, sizeX, sizeY); + GetGridPositions(listX, listY, sizeX, sizeY); + InitDungeonGrid(grid, sizeX, sizeY); + AssignRooms(grid, sizeX, sizeY, unkPtr->unk1); + CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + sub_804D5B0(grid, sizeX, sizeY, unkPtr); CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); + EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); - sub_804F0D0(grid, sizeX, sizeY, unkPtr->unk9); + + GenerateMazeRoom(grid, sizeX, sizeY, unkPtr->unk9); GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); GenerateRoomImperfections(grid, sizeX, sizeY); - sub_804D534(grid, sizeX, sizeY); + GenerateSecondaryStructures(grid, sizeX, sizeY); } // Decompile once data structure is better understood @@ -2379,13 +2402,13 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]) { s32 x, y; - s32 xStart = min(grid[roomX][room_y1].unk0.x, grid[roomX][room_y1+room_dy].unk0.x); - s32 yStart = grid[roomX][room_y1].unk0.y; - s32 xEnd = max(grid[roomX][room_y1].unk4.x, grid[roomX][room_y1+room_dy].unk4.x); - s32 yEnd = grid[roomX][room_y1 + room_dy].unk4.y; + s32 xStart = min(grid[roomX][room_y1].start.x, grid[roomX][room_y1+room_dy].start.x); + s32 yStart = grid[roomX][room_y1].start.y; + s32 xEnd = max(grid[roomX][room_y1].end.x, grid[roomX][room_y1+room_dy].end.x); + s32 yEnd = grid[roomX][room_y1 + room_dy].end.y; // Carve out the new larger room, retaining the index of the first room - u8 roomId = GetTile(grid[roomX][room_y1].unk0.x, grid[roomX][room_y1].unk0.y)->room; + u8 roomId = GetTile(grid[roomX][room_y1].start.x, grid[roomX][room_y1].start.y)->room; for (x = xStart; x < xEnd; x++) { for (y = yStart; y < yEnd; y++) { @@ -2396,70 +2419,94 @@ static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct Gri } } - grid[roomX][room_y1].unk0.x = xStart; - grid[roomX][room_y1].unk4.x = xEnd; - grid[roomX][room_y1].unk0.y = yStart; - grid[roomX][room_y1].unk4.y = yEnd; + grid[roomX][room_y1].start.x = xStart; + grid[roomX][room_y1].end.x = xEnd; + grid[roomX][room_y1].start.y = yStart; + grid[roomX][room_y1].end.y = yEnd; grid[roomX][room_y1 + room_dy].unk18 = TRUE; grid[roomX][room_y1].unk18 = TRUE; grid[roomX][room_y1 + room_dy].unk11 = FALSE; grid[roomX][room_y1 + room_dy].unk17 = TRUE; } -void sub_804C53C(s32 x_, s32 y_, UnkDungeonGlobal_unk1C574 *unkPtr) +// GenerateOuterRoomsFloor - Generates a floor layout with a ring of rooms and nothing on the interior. +// This layout is bugged and will not properly connect rooms for sizeX < 3. +void GenerateOuterRoomsFloor(s32 sizeX_, s32 sizeY_, UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; - s32 i, j; - s32 x = x_; - s32 y = y_; + s32 x, y; + s32 sizeX = sizeX_; + s32 sizeY = sizeY_; - sub_804D024(listX, listY, x, y); - InitDungeonGrid(grid, x, y); - for (i = 0; i < x; i++) { - for (j = 0; j < y; j++) { - grid[i][j].unk10 = 1; + GetGridPositions(listX, listY, sizeX, sizeY); + InitDungeonGrid(grid, sizeX, sizeY); + + // Make all cells rooms + for (x = 0; x < sizeX; x++) { + for (y = 0; y < sizeY; y++) { + grid[x][y].unk10 = TRUE; } } - for (i = 1; i < x - 1; i++) { - for (j = 1; j < y - 1; j++) { - grid[i][j].unk8 = 1; + // Invalidate all interior cells + for (x = 1; x < sizeX - 1; x++) { + for (y = 1; y < sizeY - 1; y++) { + grid[x][y].unk8 = TRUE; } } - CreateRoomsAndAnchors(grid, x, y, listX, listY, unkPtr->unkD); - for (i = 0; i < x - 1; i++) { - if (i != 0) { - grid[i][0].unk22 = 1; - grid[i][y-1].unk22 = 1; + CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + + // Maybe Todo: Add EpicYoshiMaster's fixed implementation of this function + + // The original implementation fails for sizeX <= 2, as one of the branches + // is never taken, and the other branch does not provide a backup connection, leaving the two sides unconnected. + // Additionally, there is a minor issue for top/bottom connections which results in hallways being connected from the bottom + // instead of from the top, but this does not affect the connectivity of the map. + for (x = 0; x < sizeX - 1; x++) { + if (x != 0) { + grid[x][0].unk22 = TRUE; + grid[x][sizeY-1].unk22 = TRUE; } - if (i < x - 2) { - grid[i+1][0].unk21 = 1; - grid[i+1][y-1].unk21 = 1; + + // Bug: if sizeX <= 2, this branch will never be run. + // Additionally, because the branch above this has no meaningful hallways produced for + // sizeX == 1, no connections will be made between columns here. + // This results in an unconnected map for sizeX <= 2. + if (x < sizeX - 2) { + grid[x+1][0].unk21 = TRUE; + grid[x+1][sizeY-1].unk21 = TRUE; } } - for (j = 0; j < y - 1; j++) { - if (j != 0) { - grid[0][j].unk19 = 1; - grid[x-1][j].unk19 = 1; + for (y = 0; y < sizeY - 1; y++) { + if (y != 0) { + grid[0][y].unk19 = TRUE; + grid[sizeX-1][y].unk19 = TRUE; } - if (j < y - 2) { - grid[0][j].unk20 = 1; - grid[x-1][j].unk20 = 1; + + // This connection ends up not being set for the bottom row, but this is fine because the other + // connection to this room is still correct. The result is that hallways here will be using the opposing end + // of the grid cell boundary for their turns compared to top/bottom hallways between other rows. + if (y < sizeY - 2) { + grid[0][y].unk20 = TRUE; + grid[sizeX-1][y].unk20 = TRUE; } } - CreateGridCellConnections(grid, x, y, listX, listY, FALSE); - EnsureConnectedGrid(grid, x, y, listX, listY); - sub_804F0D0(grid, x, y, unkPtr->unk9); - GenerateKecleonShop(grid, x, y, gUnknown_202F1B0); - GenerateMonsterHouse(grid, x, y, gUnknown_202F1B2); - GenerateExtraHallways(grid, x, y, unkPtr->unk13); - GenerateRoomImperfections(grid, x, y); - sub_804D534(grid, x, y); + CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); + + EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + + GenerateMazeRoom(grid, sizeX, sizeY, unkPtr->unk9); + GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + + GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, sizeX, sizeY); + GenerateSecondaryStructures(grid, sizeX, sizeY); } void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); @@ -2473,7 +2520,7 @@ bool8 sub_804C70C(s32 a0, UnkDungeonGlobal_unk1C574 *unkPtr) s32 x2, y2; if (x1 == 0 || y1 == 0) { - sub_804C918(); + GenerateOneRoomMonsterHouseFloor(); return FALSE; } else if (a0 < 50) { @@ -2505,7 +2552,7 @@ void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C5 s32 r10 = 0; s32 x3 = 0, y3 = 0; - sub_804D024(listX, listY, x1, y1); + GetGridPositions(listX, listY, x1, y1); InitDungeonGrid(grid, x1, y1); AssignRooms(grid, x1, y1, unkPtr->unk1); for (x3 = 0; x3 < x1; x3++) { @@ -2530,36 +2577,45 @@ void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C5 sub_8051438(&grid[x3][y3], a4); } -void sub_804C918(void) +/* + * GenerateOneRoomMonsterHouseFloor - Generates a floor layout with just one large room which is a Monster House. + * This generator is used as a fallback in the event generation fails too many times. + */ +void GenerateOneRoomMonsterHouseFloor(void) { - s32 i, j; + s32 x, y; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; InitDungeonGrid(grid, 1, 1); - grid[0][0].unk0.x = 2; - grid[0][0].unk4.x = DUNGEON_MAX_SIZE_X - 2; - grid[0][0].unk0.y = 2; - grid[0][0].unk4.y = DUNGEON_MAX_SIZE_Y - 2; - grid[0][0].unk10 = 1; - grid[0][0].unk11 = 1; - grid[0][0].unk8 = 0; - for (i = grid[0][0].unk0.x; i < grid[0][0].unk4.x; i++) { - for (j = grid[0][0].unk0.y; j < grid[0][0].unk4.y; j++) { - Tile *tile = GetTileSafe(i, j); + + grid[0][0].start.x = 2; + grid[0][0].end.x = DUNGEON_MAX_SIZE_X - 2; + grid[0][0].start.y = 2; + grid[0][0].end.y = DUNGEON_MAX_SIZE_Y - 2; + grid[0][0].unk10 = TRUE; + grid[0][0].unk11 = TRUE; + grid[0][0].unk8 = FALSE; + + for (x = grid[0][0].start.x; x < grid[0][0].end.x; x++) { + for (y = grid[0][0].start.y; y < grid[0][0].end.y; y++) { + Tile *tile = GetTileSafe(x, y); tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); tile->terrainType |= TERRAIN_TYPE_NORMAL; // Unnecessary call again - GetTileSafe(i, j)->room = 0; + GetTileSafe(x, y)->room = 0; } } GenerateMonsterHouse(grid, 1, 1, 999); } -void sub_804C9D0(void) +// GenerateTwoRoomsWithMonsterHouseFloor - Generates a floor layout with two rooms (left and right), with one being a Monster House. +void GenerateTwoRoomsWithMonsterHouseFloor(void) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; + const s32 sizeX = 2; + const s32 sizeY = 1; s32 currRoomId = 0; s32 x, y; @@ -2568,10 +2624,10 @@ void sub_804C9D0(void) listX[2] = 54; listY[0] = 2; listY[1] = 30; - InitDungeonGrid(grid, 2, 1); + InitDungeonGrid(grid, sizeX, sizeY); - for (y = 0; y < 1; y++) { - for (x = 0; x < 2; x++) { + for (y = 0; y < sizeY; y++) { + for (x = 0; x < sizeX; x++) { s32 currX, currY; s32 minX = listX[x] + 1; s32 minY = listY[y] + 1; @@ -2585,10 +2641,10 @@ void sub_804C9D0(void) s32 endY = startY + roomSizeY; grid[x][y].unk10 = 1; - grid[x][y].unk0.x = startX; - grid[x][y].unk4.x = endX; - grid[x][y].unk0.y = startY; - grid[x][y].unk4.y = endY; + grid[x][y].start.x = startX; + grid[x][y].end.x = endX; + grid[x][y].start.y = startY; + grid[x][y].end.y = endY; for (currX = startX; currX < endX; currX++) { for (currY = startY; currY < endY; currY++) { @@ -2603,10 +2659,237 @@ void sub_804C9D0(void) } } - grid[0][0].unk22 = 1; - grid[1][0].unk21 = 1; - CreateGridCellConnections(grid, 2, 1, listX, listY, FALSE); - GenerateMonsterHouse(grid, 2, 1, 999); + grid[0][0].unk22 = TRUE; + grid[1][0].unk21 = TRUE; + + CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); + GenerateMonsterHouse(grid, sizeX, sizeY, 999); +} + +/* + * GenerateExtraHallways - Generate extra hallways on the floor via a series of random walks. + * + * These paths are often visibly dead-end hallways, or hallways which loop on themselves. + * + * Each walk begin at a random tile in a random room, leaving in a random cardinal direction, tunneling + * through obstacles until it reaches open terrain, is out of bounds, or reaches an impassable obstruction. + * + * For each hallway the following steps are done: + * + * 1. Select a room, tile, and cardinal direction (specific conditions documented below) + * + * 2. Walk from the tile in that direction until we are out of the room, and reach an obstacle (could traverse hallways on the way) + * + * 3. Check we're safe to proceed (not at map borders, counterclockwise/clockwise tiles are not open) + * + * Begin our random-length walk strides: + * + * 4. Check we're safe to proceed (not at borders, not open tile, not impassable wall, will not make a 2x2 open square) + * + * 5. Place Open Terrain at this tile + * + * 6. Check we're safe to proceed (counterclockwise/clockwise tiles are not open) + * + * 7. Check if we've reached the end of the current stride (steps at 0), if so, turn left or right at random and start a new stride. + * + * 8. Move in the current direction. + * + * Repeat 4-8 until a check fails. + */ +void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 numExtraHallways) +{ + s32 i, j; + + if (numExtraHallways == 0) + return; + + for (i = 0; i < numExtraHallways; i++) { + s32 currX, currY; + s32 direction; + u8 roomId; + bool8 invalid; + s32 checkX, checkY, checkX2, checkY2; + s32 xLoop, yLoop; + // Select a random grid cell + s32 x = DungeonRandInt(sizeX); + s32 y = DungeonRandInt(sizeY); + + // To generate extra hallways the cell must be: + // - a room + // - connected + // - valid + // - not a maze room + if (!grid[x][y].unk10 || !grid[x][y].unk11 || grid[x][y].unk8 || grid[x][y].unk16) continue; + + // Choose a random tile in the room + currX = DungeonRandRange(grid[x][y].start.x, grid[x][y].end.x); + currY = DungeonRandRange(grid[x][y].start.y, grid[x][y].end.y); + + // Choose a random cardinal direction + direction = DungeonRandInt(4) * 2; + + // If invalid, rotate counter-clockwise until one works + for (j = 0; j < 3; j++) { + if (direction == DIRECTION_SOUTH && y >= sizeY - 1) { + direction = DIRECTION_EAST; + } + + if (direction == DIRECTION_EAST && x >= sizeX - 1) { + direction = DIRECTION_NORTH; + } + + if (direction == DIRECTION_NORTH && y <= 0) { + direction = DIRECTION_WEST; + } + + if (direction == DIRECTION_WEST && x <= 0) { + direction = DIRECTION_SOUTH; + } + } + + roomId = GetTile(currX, currY)->room; + // Walk in the random direction until out of the room + while (1) { + if (roomId != GetTile(currX, currY)->room) + break; + // gAdjacentTileOffsets gives us the proper (x,y) offset to move one tile in the given direction. + currX += gAdjacentTileOffsets[direction].x; + currY += gAdjacentTileOffsets[direction].y; + } + + // Keep walking until an obstacle is encountered + while (1) { + if ((GetTile(currX, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) != TERRAIN_TYPE_NORMAL) + break; + + currX += gAdjacentTileOffsets[direction].x; + currY += gAdjacentTileOffsets[direction].y; + } + + // Abort if we reached secondary terrain + if ((GetTile(currX, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_SECONDARY) + continue; + + // Check that the current tile is at least 2 away from the map border + invalid = FALSE; + for (xLoop = currX - 2; xLoop <= currX + 2; xLoop++) { + for (yLoop = currY - 2; yLoop <= currY + 2; yLoop++) { + if (xLoop < 0 || xLoop >= DUNGEON_MAX_SIZE_X || yLoop < 0 || yLoop >= DUNGEON_MAX_SIZE_Y) { + invalid = TRUE; + break; + } + } + + if (invalid) break; + } + + if (invalid) continue; + + // Make sure the direction 90 degrees counterclockwise isn't an open tile + checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; + checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; + if ((GetTile(currX + checkX, currY + checkY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + continue; + + // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile + checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; + checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; + if ((GetTile(currX + checkX2, currY + checkY2)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + continue; + + // Number of steps to walk in one direction before turning + j = DungeonRandInt(3) + 3; + while (TRUE) { + s32 checkX, checkY, checkX2, checkY2; + bool8 willNotMakeSquare; + // Check for stopping conditions: + // - Out of bounds or on the 1-tile border of impassable walls + // - Reached an open tile + // - Reached an impassable wall + // - Would result in carving out a 2x2 square (not a hallway at that point) + + if (currX <= 1 || currY <= 1 || currX >= DUNGEON_MAX_SIZE_X - 1 || currY >= DUNGEON_MAX_SIZE_Y - 1) break; + if ((GetTile(currX, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) break; + if (GetTile(currX, currY)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) break; + + willNotMakeSquare = TRUE; + + // Check Bottom to Right + if (((GetTile(currX + 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX + 1, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + { + willNotMakeSquare = FALSE; + } + + // Check Top to Right + if (((GetTile(currX + 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX + 1, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + { + willNotMakeSquare = FALSE; + } + + // Check Bottom to Left + if (((GetTile(currX - 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX - 1, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + { + willNotMakeSquare = FALSE; + } + + // Check Top to Left + if (((GetTile(currX - 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX - 1, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && + ((GetTile(currX, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + { + willNotMakeSquare = FALSE; + } + + // If TRUE, make the tile open, it will not produce a 2x2 opening + // If FALSE, it will abort from neighbor checks so we don't break here + if (willNotMakeSquare) { + Tile *tile = GetTileSafe(currX, currY); + tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + tile->terrainType |= TERRAIN_TYPE_NORMAL; + } + + // Make sure the direction 90 degrees counterclockwise isn't an open tile + checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; + checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; + if ((GetTile(currX + checkX, currY + checkY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + break; + + // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile + checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; + checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; + if ((GetTile(currX + checkX2, currY + checkY2)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + break; + + j--; + if (j == 0) { + j = DungeonRandInt(3) + 3; + + // Turn left or right with an equal chance + if (DungeonRandInt(100) < 50) { + direction += 2; + } + else { + direction -= 2; + } + + // If we'd step into an invalid grid cell, stop + // (We don't always utilize the entire floor space) + direction &= DIRECTION_MASK_CARDINAL; + if (currX >= 32 && gUnknown_202F1AE == 1 && direction == DIRECTION_EAST) break; + if (currX >= 48 && gUnknown_202F1AE == 2 && direction == DIRECTION_EAST) break; + } + + // Move in the current direction + currX += gAdjacentTileOffsets[direction].x; + currY += gAdjacentTileOffsets[direction].y; + } + } } // From 76d710229ed1f69e5ef5fa93de06117160c01e34 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 8 Nov 2024 14:29:12 +0100 Subject: [PATCH 06/30] AssignRooms --- asm/code_804AFAC.s | 381 ------------------------------------------ include/global.h | 7 + src/code_804AFAC_1.c | 385 +++++++++++++++++++++++++++++++------------ 3 files changed, 288 insertions(+), 485 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index a6c499ff7..0dad9dcae 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -6,387 +6,6 @@ .text - thumb_func_start GetGridPositions -GetGridPositions: - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r7, r0, 0 - mov r8, r1 - adds r5, r2, 0 - adds r6, r3, 0 - movs r4, 0 - cmp r4, r5 - bge _0804D04E - movs r0, 0x38 - adds r1, r5, 0 - bl __divsi3 - adds r2, r7, 0 - adds r1, r5, 0 -_0804D044: - stm r2!, {r4} - adds r4, r0 - subs r1, 0x1 - cmp r1, 0 - bne _0804D044 -_0804D04E: - lsls r0, r5, 2 - adds r0, r7 - str r4, [r0] - movs r4, 0 - lsls r5, r6, 2 - cmp r4, r6 - bge _0804D072 - movs r0, 0x20 - adds r1, r6, 0 - bl __divsi3 - mov r2, r8 - adds r1, r6, 0 -_0804D068: - stm r2!, {r4} - adds r4, r0 - subs r1, 0x1 - cmp r1, 0 - bne _0804D068 -_0804D072: - mov r1, r8 - adds r0, r5, r1 - str r4, [r0] - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GetGridPositions - - thumb_func_start InitDungeonGrid -InitDungeonGrid: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - mov r8, r0 - adds r5, r1, 0 - mov r9, r2 - movs r2, 0 - cmp r2, r5 - bge _0804D144 - lsrs r0, r5, 31 - adds r0, r5, r0 - asrs r0, 1 - str r0, [sp] - movs r3, 0 -_0804D0A6: - adds r0, r2, 0x1 - mov r10, r0 - mov r4, r9 - cmp r4, 0 - ble _0804D13E - ldr r6, _0804D0D8 - ldrb r6, [r6] - str r6, [sp, 0x4] - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - mov r4, r8 - adds r1, r0, r4 - movs r7, 0 - movs r6, 0x1 - mov r12, r6 - mov r4, r9 -_0804D0C8: - ldr r0, [sp, 0x4] - cmp r0, 0x1 - bne _0804D0DC - ldr r6, [sp] - cmp r2, r6 - blt _0804D0DC - strb r0, [r1, 0x8] - b _0804D102 - .align 2, 0 -_0804D0D8: .4byte gUnknown_202F1AE -_0804D0DC: - ldr r6, _0804D0FC - ldrb r0, [r6] - cmp r0, 0x2 - bne _0804D100 - lsls r0, r5, 1 - adds r0, r5 - cmp r0, 0 - bge _0804D0EE - adds r0, 0x3 -_0804D0EE: - asrs r0, 2 - cmp r2, r0 - blt _0804D100 - mov r0, r12 - strb r0, [r1, 0x8] - b _0804D102 - .align 2, 0 -_0804D0FC: .4byte gUnknown_202F1AE -_0804D100: - strb r3, [r1, 0x8] -_0804D102: - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, r8 - adds r0, r7, r0 - mov r6, r12 - strb r6, [r0, 0xA] - strb r3, [r0, 0xB] - strb r3, [r0, 0xF] - strb r3, [r0, 0xE] - strb r3, [r0, 0xC] - strb r3, [r0, 0x16] - strb r3, [r0, 0x15] - strb r3, [r0, 0x14] - strb r3, [r0, 0x13] - strb r3, [r0, 0x1A] - strb r3, [r0, 0x19] - strb r3, [r0, 0x18] - strb r3, [r0, 0x17] - strb r3, [r0, 0x9] - strb r3, [r0, 0x11] - strb r3, [r0, 0x10] - strb r3, [r0, 0x12] - strb r3, [r0, 0x1C] - strb r3, [r0, 0x1D] - adds r1, 0x20 - adds r7, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _0804D0C8 -_0804D13E: - mov r2, r10 - cmp r2, r5 - blt _0804D0A6 -_0804D144: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end InitDungeonGrid - - thumb_func_start AssignRooms -AssignRooms: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x114 - str r0, [sp, 0x100] - mov r9, r1 - mov r8, r2 - adds r4, r3, 0 - movs r0, 0x3 - bl DungeonRandInt - adds r3, r0, 0 - cmp r4, 0 - bge _0804D17E - negs r4, r4 - b _0804D180 -_0804D178: - movs r0, 0x1 - strb r0, [r4, 0xA] - b _0804D2B6 -_0804D17E: - adds r4, r3 -_0804D180: - movs r3, 0 - mov r0, r8 - mov r2, r9 - muls r2, r0 - cmp r3, r4 - bge _0804D19A - movs r1, 0x1 -_0804D18E: - mov r5, sp - adds r0, r5, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, r4 - blt _0804D18E -_0804D19A: - cmp r3, 0xFF - bgt _0804D1AC - movs r1, 0 -_0804D1A0: - mov r6, sp - adds r0, r6, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, 0xFF - ble _0804D1A0 -_0804D1AC: - adds r5, r2, 0 - movs r6, 0x3F -_0804D1B0: - adds r0, r5, 0 - bl DungeonRandInt - adds r4, r0, 0 - adds r0, r5, 0 - bl DungeonRandInt - mov r1, sp - adds r2, r1, r4 - ldrb r3, [r2] - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - subs r6, 0x1 - cmp r6, 0 - bge _0804D1B0 - movs r3, 0 - ldr r0, _0804D24C - str r3, [r0] - movs r7, 0 - mov r12, r0 - cmp r7, r9 - bge _0804D262 -_0804D1E0: - movs r5, 0 - adds r4, r7, 0x1 - str r4, [sp, 0x104] - cmp r5, r8 - bge _0804D25C - lsls r2, r7, 4 - subs r2, r7 - lsls r2, 5 - ldr r6, [sp, 0x100] - adds r0, r2, r6 - mov r1, r9 - movs r4, 0x1 - ands r1, r4 - str r1, [sp, 0x110] - mov r1, r9 - subs r1, 0x1 - adds r0, 0x20 - mov r10, r0 - adds r0, r6, 0 - adds r0, 0x8 - adds r2, r0 - lsrs r0, r1, 31 - adds r1, r0 - asrs r1, 1 -_0804D210: - ldrb r4, [r2] - cmp r4, 0 - bne _0804D254 - mov r6, r12 - ldr r0, [r6] - cmp r0, 0x1F - ble _0804D220 - strb r4, [r2, 0x2] -_0804D220: - mov r6, sp - adds r0, r6, r3 - ldrb r0, [r0] - cmp r0, 0 - beq _0804D250 - movs r0, 0x1 - strb r0, [r2, 0x2] - mov r6, r12 - ldr r0, [r6] - adds r0, 0x1 - str r0, [r6] - ldr r0, [sp, 0x110] - cmp r0, 0 - beq _0804D252 - cmp r7, r1 - bne _0804D252 - cmp r5, 0x1 - bne _0804D252 - mov r6, r10 - strb r4, [r6, 0xA] - b _0804D252 - .align 2, 0 -_0804D24C: .4byte gUnknown_202F1CC -_0804D250: - strb r0, [r2, 0x2] -_0804D252: - adds r3, 0x1 -_0804D254: - adds r2, 0x20 - adds r5, 0x1 - cmp r5, r8 - blt _0804D210 -_0804D25C: - ldr r7, [sp, 0x104] - cmp r7, r9 - blt _0804D1E0 -_0804D262: - mov r1, r12 - ldr r0, [r1] - cmp r0, 0x1 - bgt _0804D2BC - movs r1, 0 - movs r2, 0 -_0804D26E: - movs r7, 0 - cmp r2, r9 - bge _0804D2AC - movs r6, 0 -_0804D276: - movs r5, 0 - cmp r5, r8 - bge _0804D2A4 - lsls r0, r6, 5 - ldr r3, [sp, 0x100] - adds r4, r0, r3 -_0804D282: - ldrb r0, [r4, 0x8] - cmp r0, 0 - bne _0804D29C - movs r0, 0x64 - str r1, [sp, 0x108] - str r2, [sp, 0x10C] - bl DungeonRandInt - ldr r1, [sp, 0x108] - ldr r2, [sp, 0x10C] - cmp r0, 0x3B - bgt _0804D29C - b _0804D178 -_0804D29C: - adds r4, 0x20 - adds r5, 0x1 - cmp r5, r8 - blt _0804D282 -_0804D2A4: - adds r6, 0xF - adds r7, 0x1 - cmp r7, r9 - blt _0804D276 -_0804D2AC: - cmp r2, 0 - bne _0804D2B6 - adds r1, 0x1 - cmp r1, 0xC7 - ble _0804D26E -_0804D2B6: - ldr r1, _0804D2CC - movs r0, 0 - strb r0, [r1] -_0804D2BC: - add sp, 0x114 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804D2CC: .4byte gUnknown_202F1AD - thumb_func_end AssignRooms - thumb_func_start CreateRoomsAndAnchors CreateRoomsAndAnchors: push {r4-r7,lr} diff --git a/include/global.h b/include/global.h index 42de541c6..c9f7791a2 100644 --- a/include/global.h +++ b/include/global.h @@ -39,6 +39,13 @@ #define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0])) +#define SWAP(a, b, temp) \ +{ \ + temp = a; \ + a = b; \ + b = temp; \ +} + #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 1c62d8ebf..993c7d5ab 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -22,6 +22,7 @@ extern s16 gUnknown_202F1B0; extern s16 gUnknown_202F1B2; extern s32 gUnknown_202F1C8; extern s32 gUnknown_202F1D0; +extern s32 gUnknown_202F1CC; extern Position gUnknown_202F1D8; struct UnkStruct_202F1B8 @@ -69,6 +70,17 @@ struct FileFixedmapPosStruct u8 y; }; +static inline void SetTerrainNormal(Tile *tile) +{ + tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + tile->terrainType |= TERRAIN_TYPE_NORMAL; +} + +static inline u32 GetTerrain(Tile *tile) +{ + return tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); +} + // Some weird-ass regswap prevents the function from being matched - https://decomp.me/scratch/9SUV3 #ifdef NONMATCHING void sub_804AFAC(void) @@ -258,7 +270,7 @@ void sub_804AFAC(void) if (r10) { sub_80506F0(1, unkPtr); } - r4 = (DungeonRandInt(100) < unkPtr->unk19); + r4 = (DungeonRandInt(100) < unkPtr->connectedToTop); sub_804FF08(unkPtr, r4); sub_8050438(unkPtr, r4); sub_804FBE8(); @@ -960,15 +972,15 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) Tile *tile = GetTileSafe(x, y); tile->terrainType &= ~(TERRAIN_TYPE_UNK_2); - if (tile->room == CORRIDOR_ROOM && ((tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) { - if (x > 0 && ((GetTile(x - 1, y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if (tile->room == CORRIDOR_ROOM && (GetTerrain(tile) == TERRAIN_TYPE_NORMAL)) { + if (x > 0 && (GetTerrain(GetTile(x - 1, y)) == TERRAIN_TYPE_NORMAL)) unkCount++; - if (y > 0 && ((GetTile(x, y - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if (y > 0 && (GetTerrain(GetTile(x, y - 1)) == TERRAIN_TYPE_NORMAL)) unkCount++; - if (x < DUNGEON_MAX_SIZE_X - 2 && ((GetTile(x + 1, y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if (x < DUNGEON_MAX_SIZE_X - 2 && (GetTerrain(GetTile(x + 1, y)) == TERRAIN_TYPE_NORMAL)) unkCount++; // BUG: It should check for y and not x. Not sure if it has any effect, because this function is called only once with maxY equal to DUNGEON_MAX_SIZE_Y - if (x < DUNGEON_MAX_SIZE_Y - 2 && ((GetTile(x, y + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if (x < DUNGEON_MAX_SIZE_Y - 2 && (GetTerrain(GetTile(x, y + 1)) == TERRAIN_TYPE_NORMAL)) unkCount++; if (unkCount > 2) { @@ -983,30 +995,30 @@ struct GridCell { Position start; Position end; - u8 unk8; - u8 unk9; - u8 unk10; - u8 unk11; - u8 unk12; - u8 unk13; - u8 unk14; - u8 unk15; - u8 unk16; - u8 unk17; - u8 unk18; - u8 unk19; - u8 unk20; - u8 unk21; - u8 unk22; - u8 unk23; - u8 unk24; - u8 unk25; - u8 unk26; - u8 unk27; - u8 unk28; - u8 unk29; - u8 unk30; - u8 unk31; + bool8 isInvalid; + bool8 unk9; + bool8 isRoom; + bool8 isConnected; + bool8 unk12; + bool8 unk13; + bool8 unk14; + bool8 unk15; + bool8 isMazeRoom; + bool8 hasBeenMerged; + bool8 isMerged; + bool8 connectedToTop; + bool8 connectedToBottom; + bool8 connectedToLeft; + bool8 connectedToRight; + bool8 unk23; + bool8 unk24; + bool8 unk25; + bool8 unk26; + bool8 unk27; + bool8 unk28; + bool8 unk29; + bool8 unk30; + bool8 unk31; }; #define GRID_CELL_LEN 15 @@ -2315,26 +2327,26 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) // Set all cells as rooms for (x = 0; x < sizeX; x++) { for (y = 0; y < sizeY; y++) { - grid[x][y].unk10 = TRUE; + grid[x][y].isRoom = TRUE; } } // Invalidate the corners - grid[0][0].unk8 = TRUE; - grid[2][0].unk8 = TRUE; - grid[0][2].unk8 = TRUE; - grid[2][2].unk8 = TRUE; + grid[0][0].isInvalid = TRUE; + grid[2][0].isInvalid = TRUE; + grid[0][2].isInvalid = TRUE; + grid[2][2].isInvalid = TRUE; CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); - grid[0][1].unk22 = TRUE; - grid[1][1].unk21 = TRUE; - grid[1][1].unk22 = TRUE; - grid[2][1].unk21 = TRUE; - grid[1][0].unk20 = TRUE; - grid[1][1].unk19 = TRUE; - grid[1][1].unk20 = TRUE; - grid[1][2].unk19 = TRUE; + grid[0][1].connectedToRight = TRUE; + grid[1][1].connectedToLeft = TRUE; + grid[1][1].connectedToRight = TRUE; + grid[2][1].connectedToLeft = TRUE; + grid[1][0].connectedToBottom = TRUE; + grid[1][1].connectedToTop = TRUE; + grid[1][1].connectedToBottom = TRUE; + grid[1][2].connectedToTop = TRUE; CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, TRUE); EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); @@ -2370,7 +2382,7 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) // Set all cells as rooms for (x = 0; x < sizeX; x++) { for (y = 0; y < sizeY; y++) { - grid[x][y].unk10 = TRUE; + grid[x][y].isRoom = TRUE; } } @@ -2378,10 +2390,10 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) // Connect rooms in the same row together for (y = 0; y < 3; y++) { - grid[0][y].unk22 = TRUE; - grid[1][y].unk21 = TRUE; - grid[1][y].unk22 = TRUE; - grid[2][y].unk21 = TRUE; + grid[0][y].connectedToRight = TRUE; + grid[1][y].connectedToLeft = TRUE; + grid[1][y].connectedToRight = TRUE; + grid[2][y].connectedToLeft = TRUE; } CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, TRUE); @@ -2413,8 +2425,7 @@ static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct Gri for (x = xStart; x < xEnd; x++) { for (y = yStart; y < yEnd; y++) { Tile *tile = GetTileSafe(x, y); - tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - tile->terrainType |= TERRAIN_TYPE_NORMAL; + SetTerrainNormal(tile); tile->room = roomId; } } @@ -2423,10 +2434,11 @@ static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct Gri grid[roomX][room_y1].end.x = xEnd; grid[roomX][room_y1].start.y = yStart; grid[roomX][room_y1].end.y = yEnd; - grid[roomX][room_y1 + room_dy].unk18 = TRUE; - grid[roomX][room_y1].unk18 = TRUE; - grid[roomX][room_y1 + room_dy].unk11 = FALSE; - grid[roomX][room_y1 + room_dy].unk17 = TRUE; + + grid[roomX][room_y1 + room_dy].isMerged = TRUE; + grid[roomX][room_y1].isMerged = TRUE; + grid[roomX][room_y1 + room_dy].isConnected = FALSE; + grid[roomX][room_y1 + room_dy].hasBeenMerged = TRUE; } // GenerateOuterRoomsFloor - Generates a floor layout with a ring of rooms and nothing on the interior. @@ -2446,14 +2458,14 @@ void GenerateOuterRoomsFloor(s32 sizeX_, s32 sizeY_, UnkDungeonGlobal_unk1C574 * // Make all cells rooms for (x = 0; x < sizeX; x++) { for (y = 0; y < sizeY; y++) { - grid[x][y].unk10 = TRUE; + grid[x][y].isRoom = TRUE; } } // Invalidate all interior cells for (x = 1; x < sizeX - 1; x++) { for (y = 1; y < sizeY - 1; y++) { - grid[x][y].unk8 = TRUE; + grid[x][y].isInvalid = TRUE; } } @@ -2467,8 +2479,8 @@ void GenerateOuterRoomsFloor(s32 sizeX_, s32 sizeY_, UnkDungeonGlobal_unk1C574 * // instead of from the top, but this does not affect the connectivity of the map. for (x = 0; x < sizeX - 1; x++) { if (x != 0) { - grid[x][0].unk22 = TRUE; - grid[x][sizeY-1].unk22 = TRUE; + grid[x][0].connectedToRight = TRUE; + grid[x][sizeY-1].connectedToRight = TRUE; } // Bug: if sizeX <= 2, this branch will never be run. @@ -2476,23 +2488,23 @@ void GenerateOuterRoomsFloor(s32 sizeX_, s32 sizeY_, UnkDungeonGlobal_unk1C574 * // sizeX == 1, no connections will be made between columns here. // This results in an unconnected map for sizeX <= 2. if (x < sizeX - 2) { - grid[x+1][0].unk21 = TRUE; - grid[x+1][sizeY-1].unk21 = TRUE; + grid[x+1][0].connectedToLeft = TRUE; + grid[x+1][sizeY-1].connectedToLeft = TRUE; } } for (y = 0; y < sizeY - 1; y++) { if (y != 0) { - grid[0][y].unk19 = TRUE; - grid[sizeX-1][y].unk19 = TRUE; + grid[0][y].connectedToTop = TRUE; + grid[sizeX-1][y].connectedToTop = TRUE; } // This connection ends up not being set for the bottom row, but this is fine because the other // connection to this room is still correct. The result is that hallways here will be using the opposing end // of the grid cell boundary for their turns compared to top/bottom hallways between other rows. if (y < sizeY - 2) { - grid[0][y].unk20 = TRUE; - grid[sizeX-1][y].unk20 = TRUE; + grid[0][y].connectedToBottom = TRUE; + grid[sizeX-1][y].connectedToBottom = TRUE; } } @@ -2565,7 +2577,7 @@ void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C5 x3 = DungeonRandInt(x1); y3 = DungeonRandInt(y1); r10 = y3 * x1 + x3; - if (grid[x3][y3].unk10) + if (grid[x3][y3].isRoom) break; } sub_8050F90(grid, x1, y1, listX, listY, r10, x2, y2); @@ -2592,16 +2604,14 @@ void GenerateOneRoomMonsterHouseFloor(void) grid[0][0].end.x = DUNGEON_MAX_SIZE_X - 2; grid[0][0].start.y = 2; grid[0][0].end.y = DUNGEON_MAX_SIZE_Y - 2; - grid[0][0].unk10 = TRUE; - grid[0][0].unk11 = TRUE; - grid[0][0].unk8 = FALSE; + + grid[0][0].isRoom = TRUE; + grid[0][0].isConnected = TRUE; + grid[0][0].isInvalid = FALSE; for (x = grid[0][0].start.x; x < grid[0][0].end.x; x++) { for (y = grid[0][0].start.y; y < grid[0][0].end.y; y++) { - Tile *tile = GetTileSafe(x, y); - tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - tile->terrainType |= TERRAIN_TYPE_NORMAL; - // Unnecessary call again + SetTerrainNormal(GetTileSafe(x, y)); GetTileSafe(x, y)->room = 0; } } @@ -2640,7 +2650,7 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) s32 endX = startX + roomSizeX; s32 endY = startY + roomSizeY; - grid[x][y].unk10 = 1; + grid[x][y].isRoom = TRUE; grid[x][y].start.x = startX; grid[x][y].end.x = endX; grid[x][y].start.y = startY; @@ -2648,10 +2658,7 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) for (currX = startX; currX < endX; currX++) { for (currY = startY; currY < endY; currY++) { - Tile *tile = GetTileSafe(currX, currY); - tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - tile->terrainType |= TERRAIN_TYPE_NORMAL; - // Unnecessary call again + SetTerrainNormal(GetTileSafe(currX, currY)); GetTileSafe(currX, currY)->room = currRoomId; } } @@ -2659,8 +2666,8 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) } } - grid[0][0].unk22 = TRUE; - grid[1][0].unk21 = TRUE; + grid[0][0].connectedToRight = TRUE; + grid[1][0].connectedToLeft = TRUE; CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); GenerateMonsterHouse(grid, sizeX, sizeY, 999); @@ -2719,7 +2726,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // - connected // - valid // - not a maze room - if (!grid[x][y].unk10 || !grid[x][y].unk11 || grid[x][y].unk8 || grid[x][y].unk16) continue; + if (!grid[x][y].isRoom || !grid[x][y].isConnected || grid[x][y].isInvalid || grid[x][y].isMazeRoom) continue; // Choose a random tile in the room currX = DungeonRandRange(grid[x][y].start.x, grid[x][y].end.x); @@ -2759,7 +2766,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // Keep walking until an obstacle is encountered while (1) { - if ((GetTile(currX, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) != TERRAIN_TYPE_NORMAL) + if (GetTerrain(GetTile(currX, currY)) != TERRAIN_TYPE_NORMAL) break; currX += gAdjacentTileOffsets[direction].x; @@ -2767,7 +2774,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s } // Abort if we reached secondary terrain - if ((GetTile(currX, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_SECONDARY) + if (GetTerrain(GetTile(currX, currY)) == TERRAIN_TYPE_SECONDARY) continue; // Check that the current tile is at least 2 away from the map border @@ -2788,13 +2795,13 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // Make sure the direction 90 degrees counterclockwise isn't an open tile checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; - if ((GetTile(currX + checkX, currY + checkY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrain(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) continue; // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; - if ((GetTile(currX + checkX2, currY + checkY2)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrain(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) continue; // Number of steps to walk in one direction before turning @@ -2808,40 +2815,43 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // - Reached an impassable wall // - Would result in carving out a 2x2 square (not a hallway at that point) - if (currX <= 1 || currY <= 1 || currX >= DUNGEON_MAX_SIZE_X - 1 || currY >= DUNGEON_MAX_SIZE_Y - 1) break; - if ((GetTile(currX, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) break; - if (GetTile(currX, currY)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) break; + if (currX <= 1 || currY <= 1 || currX >= DUNGEON_MAX_SIZE_X - 1 || currY >= DUNGEON_MAX_SIZE_Y - 1) + break; + if (GetTerrain(GetTile(currX, currY)) == TERRAIN_TYPE_NORMAL) + break; + if (GetTile(currX, currY)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) + break; willNotMakeSquare = TRUE; // Check Bottom to Right - if (((GetTile(currX + 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX + 1, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrain(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX + 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } // Check Top to Right - if (((GetTile(currX + 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX + 1, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrain(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX + 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } // Check Bottom to Left - if (((GetTile(currX - 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX - 1, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX, currY + 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrain(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX - 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } // Check Top to Left - if (((GetTile(currX - 1, currY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX - 1, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) && - ((GetTile(currX, currY - 1)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrain(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX - 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrain(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } @@ -2849,21 +2859,19 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // If TRUE, make the tile open, it will not produce a 2x2 opening // If FALSE, it will abort from neighbor checks so we don't break here if (willNotMakeSquare) { - Tile *tile = GetTileSafe(currX, currY); - tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - tile->terrainType |= TERRAIN_TYPE_NORMAL; + SetTerrainNormal(GetTileSafe(currX, currY)); } // Make sure the direction 90 degrees counterclockwise isn't an open tile checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; - if ((GetTile(currX + checkX, currY + checkY)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrain(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) break; // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; - if ((GetTile(currX + checkX2, currY + checkY2)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrain(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) break; j--; @@ -2892,4 +2900,173 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s } } +// GetGridPositions - Determines the starting positions of grid cells based on the given floor grid dimensions +void GetGridPositions(s32 *listX, s32 *listY, s32 sizeX, s32 sizeY) +{ + s32 i, sum; + + for (i = 0, sum = 0; i < sizeX; i++) { + listX[i] = sum; + sum += DUNGEON_MAX_SIZE_X / sizeX; + } + listX[sizeX] = sum; + + for (i = 0, sum = 0; i < sizeY; i++) { + listY[i] = sum; + sum += DUNGEON_MAX_SIZE_Y / sizeY; + } + listY[sizeY] = sum; +} + +/* + * InitDungeonGrid - Initializes the default state of the dungeon grid + * + * The dungeon grid is an array of grid cells stored in column-major order + * (to give contiguous storage to cells with the same x value), with a fixed column size of 15. + */ +void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY) +{ + s32 x, y; + + for (x = 0; x < sizeX; x++) { + for (y = 0; y < sizeY; y++) { + if (gUnknown_202F1AE == 1 && x >= sizeX / 2) { + grid[x][y].isInvalid = TRUE; + } + else if (gUnknown_202F1AE == 2 && x >= (sizeX * 3) / 4) { + grid[x][y].isInvalid = TRUE; + } + else { + grid[x][y].isInvalid = FALSE; + } + + grid[x][y].isRoom = TRUE; + grid[x][y].isConnected = FALSE; + grid[x][y].unk15 = FALSE; + grid[x][y].unk14 = FALSE; + grid[x][y].unk12 = FALSE; + grid[x][y].connectedToRight = FALSE; + grid[x][y].connectedToLeft = FALSE; + grid[x][y].connectedToBottom = FALSE; + grid[x][y].connectedToTop = FALSE; + grid[x][y].unk26 = FALSE; + grid[x][y].unk25 = FALSE; + grid[x][y].unk24 = FALSE; + grid[x][y].unk23 = FALSE; + grid[x][y].unk9 = FALSE; + grid[x][y].hasBeenMerged = FALSE; + grid[x][y].isMazeRoom = FALSE; + grid[x][y].isMerged = FALSE; + grid[x][y].unk28 = FALSE; + grid[x][y].unk29 = FALSE; + } + } +} + +/* + * AssignRooms - Randomly selects a subset of grid cells to become rooms + * + * If number_of_rooms is positive, number_of_rooms + [0..2] will become rooms + * If the selected cells for rooms are invalid, less rooms will be generated. + * The number of rooms assigned will always be at least 2 and always <= MAX_ROOM_COUNT (32). + * + * Any cells which aren't marked as rooms will become hallway anchors (those single 1x1 "rooms") + * which will be connected as hallways later, to "anchor" hallway generation + * + * Primarily Modifies: grid to assign certain grid cells to have isRoom TRUE. + */ +void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 roomsNumber) +{ + bool8 randomRoomBits[256]; + s32 i, nShuffles; + s32 x, y; + s32 attempts; + s32 maxRooms; + // Extra Rooms + i = DungeonRandInt(3); + + // A negative # for room count requests an exact number of rooms + if (roomsNumber < 0) { + roomsNumber = -roomsNumber; + } + else { + roomsNumber += i; + } + + for (i = 0; i < roomsNumber; i++) { + randomRoomBits[i] = TRUE; + } + for (; i < 256; i++) { + randomRoomBits[i] = FALSE; + } + + // Shuffle around the acceptable rooms + maxRooms = sizeX * sizeY; + + for (nShuffles = 0; nShuffles < 64; nShuffles++) { + bool8 temp; + s32 a = DungeonRandInt(maxRooms); + s32 b = DungeonRandInt(maxRooms); + + SWAP(randomRoomBits[a], randomRoomBits[b], temp); + } + + // Counter for randomRoomBits + i = 0; + gUnknown_202F1CC = 0; + for (x = 0; x < sizeX; x++) { + for (y = 0; y < sizeY; y++) { + if (grid[x][y].isInvalid) + continue; + + // There are too many rooms, remove + if (gUnknown_202F1CC >= MAX_ROOM_COUNT) { + grid[x][y].isRoom = FALSE; + } + + // Using the randomly shuffled bits, create or remove the room + if (randomRoomBits[i]) { + grid[x][y].isRoom = TRUE; + gUnknown_202F1CC++; + + // Don't make a room at (x_mid, 1) + if (sizeX % 2 != 0 && x == (sizeX - 1) / 2 && y == 1 ) { + grid[x][y].isRoom = FALSE; + } + } + else { + grid[x][y].isRoom = FALSE; + } + + i++; + } + } + + // We have at least 2 rooms, we're done. + if (gUnknown_202F1CC >= 2) + return; + + for (attempts = 0; attempts < 200; attempts++) { + bool8 enoughRooms = FALSE; + for (x = 0; x < sizeX; x++) { + for (y = 0; y < sizeY; y++) { + if (grid[x][y].isInvalid) + continue; + + if (DungeonRandInt(100) < 60) { + grid[x][y].isRoom = TRUE; + enoughRooms = TRUE; + // This goto is needed to match, it's used to break from two nested loops. + goto LOOP_BREAK; + } + } + } + LOOP_BREAK: + if (enoughRooms) + break; + } + + gUnknown_202F1AD = FALSE; +} + // From 2a5e97ca89e2c60c3c1bdf233eddfd86b0d140a2 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 8 Nov 2024 22:40:16 +0100 Subject: [PATCH 07/30] GenerateCrossroadsFloor --- asm/code_804AFAC.s | 437 +--------------- src/code_804AFAC_1.c | 1179 +++++++++++++++++------------------------- 2 files changed, 486 insertions(+), 1130 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 0dad9dcae..a651805c4 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -6,433 +6,8 @@ .text - thumb_func_start CreateRoomsAndAnchors -CreateRoomsAndAnchors: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x38 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - str r3, [sp, 0xC] - movs r0, 0 - str r0, [sp, 0x10] - movs r1, 0 - str r1, [sp, 0x14] - cmp r1, r2 - blt _0804D2F2 - b _0804D520 -_0804D2F2: - movs r2, 0 - mov r10, r2 - ldr r3, [sp, 0x14] - adds r3, 0x1 - str r3, [sp, 0x28] - ldr r4, [sp, 0x4] - cmp r10, r4 - blt _0804D304 - b _0804D514 -_0804D304: - ldr r5, [sp, 0x14] - lsls r5, 5 - str r5, [sp, 0x1C] -_0804D30A: - mov r1, r10 - lsls r0, r1, 2 - ldr r2, [sp, 0xC] - adds r0, r2 - ldr r3, [r0] - adds r4, r3, 0x2 - mov r9, r4 - ldr r5, [sp, 0x14] - lsls r1, r5, 2 - ldr r2, [sp, 0x58] - adds r1, r2 - ldr r2, [r1] - adds r4, r2, 0x2 - str r4, [sp, 0x18] - ldr r0, [r0, 0x4] - subs r0, r3 - subs r4, r0, 0x4 - ldr r0, [r1, 0x4] - subs r0, r2 - subs r0, 0x3 - mov r8, r0 - mov r5, r10 - lsls r1, r5, 4 - subs r0, r1, r5 - lsls r0, 5 - ldr r2, [sp] - adds r0, r2 - ldr r3, [sp, 0x1C] - adds r7, r3, r0 - ldrb r0, [r7, 0x8] - str r1, [sp, 0x2C] - adds r5, 0x1 - str r5, [sp, 0x24] - cmp r0, 0 - beq _0804D352 - b _0804D508 -_0804D352: - ldrb r0, [r7, 0xA] - cmp r0, 0 - bne _0804D35A - b _0804D48C -_0804D35A: - movs r0, 0x5 - adds r1, r4, 0 - bl DungeonRandRange - adds r6, r0, 0 - movs r0, 0x4 - mov r1, r8 - bl DungeonRandRange - adds r5, r0, 0 - movs r1, 0x1 - adds r0, r6, 0 - orrs r0, r1 - cmp r0, r4 - bge _0804D37A - adds r6, r0, 0 -_0804D37A: - adds r0, r5, 0 - orrs r0, r1 - cmp r0, r8 - bge _0804D384 - adds r5, r0, 0 -_0804D384: - lsls r0, r5, 1 - adds r0, r5 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - cmp r6, r0 - ble _0804D394 - adds r6, r0, 0 -_0804D394: - lsls r0, r6, 1 - adds r0, r6 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - cmp r5, r0 - ble _0804D3A4 - adds r5, r0, 0 -_0804D3A4: - subs r0, r4, r6 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r9 - mov r1, r8 - subs r0, r1, r5 - bl DungeonRandInt - ldr r2, [sp, 0x18] - adds r0, r2 - mov r8, r0 - adds r3, r4, r6 - adds r6, r0, r5 - strh r4, [r7] - strh r3, [r7, 0x4] - mov r5, r8 - strh r5, [r7, 0x2] - strh r6, [r7, 0x6] - ldr r0, [sp, 0x10] - adds r0, 0x1 - str r0, [sp, 0x20] - cmp r4, r3 - bge _0804D412 -_0804D3D4: - mov r5, r8 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804D40C - ldr r1, _0804D484 - mov r9, r1 -_0804D3E0: - adds r0, r4, 0 - adds r1, r5, 0 - str r3, [sp, 0x34] - bl GetTileSafe - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileSafe - mov r1, sp - ldrb r1, [r1, 0x10] - strb r1, [r0, 0x9] - adds r5, 0x1 - ldr r3, [sp, 0x34] - cmp r5, r6 - blt _0804D3E0 -_0804D40C: - adds r4, r7, 0 - cmp r4, r3 - blt _0804D3D4 -_0804D412: - movs r5, 0x1 - movs r0, 0x64 - bl DungeonRandInt - movs r1, 0 - cmp r0, 0x4F - bgt _0804D422 - movs r1, 0x1 -_0804D422: - adds r4, r1, 0 - ldr r0, _0804D488 - ldr r0, [r0] - cmp r0, 0 - bne _0804D42E - movs r4, 0 -_0804D42E: - movs r0, 0x4 - ldr r2, [sp, 0x5C] - ands r0, r2 - cmp r0, 0 - bne _0804D43A - movs r5, 0 -_0804D43A: - cmp r5, 0 - beq _0804D466 - cmp r4, 0 - beq _0804D44E - movs r0, 0x64 - bl DungeonRandInt - cmp r0, 0x31 - ble _0804D466 - movs r4, 0 -_0804D44E: - cmp r5, 0 - beq _0804D466 - ldr r3, [sp, 0x2C] - mov r5, r10 - subs r0, r3, r5 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - ldr r2, [sp, 0x1C] - adds r0, r2, r0 - movs r1, 0x1 - strb r1, [r0, 0x1C] -_0804D466: - cmp r4, 0 - beq _0804D47E - ldr r3, [sp, 0x2C] - mov r4, r10 - subs r0, r3, r4 - lsls r0, 5 - ldr r5, [sp] - adds r0, r5 - ldr r1, [sp, 0x1C] - adds r0, r1, r0 - movs r1, 0x1 - strb r1, [r0, 0x1D] -_0804D47E: - ldr r2, [sp, 0x20] - str r2, [sp, 0x10] - b _0804D508 - .align 2, 0 -_0804D484: .4byte 0x0000fffc -_0804D488: .4byte gUnknown_202F1C8 -_0804D48C: - movs r1, 0x2 - movs r3, 0x4 - movs r6, 0x2 - movs r2, 0x4 - mov r5, r10 - cmp r5, 0 - bne _0804D49C - movs r1, 0x1 -_0804D49C: - ldr r0, [sp, 0x14] - cmp r0, 0 - bne _0804D4A4 - movs r6, 0x1 -_0804D4A4: - ldr r0, [sp, 0x4] - subs r0, 0x1 - cmp r10, r0 - bne _0804D4AE - movs r3, 0x2 -_0804D4AE: - ldr r0, [sp, 0x8] - subs r0, 0x1 - ldr r5, [sp, 0x14] - cmp r5, r0 - bne _0804D4BA - movs r2, 0x2 -_0804D4BA: - mov r5, r9 - adds r0, r5, r1 - adds r1, r5, r4 - subs r1, r3 - str r2, [sp, 0x30] - bl DungeonRandRange - adds r5, r0, 0 - ldr r1, [sp, 0x18] - adds r0, r1, r6 - add r1, r8 - ldr r2, [sp, 0x30] - subs r1, r2 - bl DungeonRandRange - adds r4, r0, 0 - strh r5, [r7] - adds r0, r5, 0x1 - strh r0, [r7, 0x4] - strh r4, [r7, 0x2] - adds r0, r4, 0x1 - strh r0, [r7, 0x6] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r1, [r0] - ldr r3, _0804D530 - adds r2, r3, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0xFE - strb r1, [r0, 0x9] -_0804D508: - ldr r4, [sp, 0x24] - mov r10, r4 - ldr r5, [sp, 0x4] - cmp r10, r5 - bge _0804D514 - b _0804D30A -_0804D514: - ldr r0, [sp, 0x28] - str r0, [sp, 0x14] - ldr r1, [sp, 0x8] - cmp r0, r1 - bge _0804D520 - b _0804D2F2 -_0804D520: - add sp, 0x38 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804D530: .4byte 0x0000fffc - thumb_func_end CreateRoomsAndAnchors - - thumb_func_start GenerateSecondaryStructures -GenerateSecondaryStructures: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - adds r3, r0, 0 - adds r7, r1, 0 - mov r9, r2 - movs r1, 0 - cmp r1, r9 - bge _0804D5A0 -_0804D54A: - adds r0, r1, 0x1 - mov r8, r0 - cmp r7, 0 - ble _0804D59A - lsls r1, 5 - adds r0, r1, 0 - adds r0, 0x8 - adds r4, r3, r0 - adds r5, r3, r1 - adds r6, r7, 0 -_0804D55E: - ldrb r0, [r4] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0x6] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0x2] - cmp r0, 0 - beq _0804D58C - ldrb r0, [r4, 0x14] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0x15] - cmp r0, 0 - beq _0804D58C - adds r0, r5, 0 - str r3, [sp] - bl sub_804F694 - ldr r3, [sp] -_0804D58C: - movs r0, 0xF0 - lsls r0, 1 - adds r4, r0 - adds r5, r0 - subs r6, 0x1 - cmp r6, 0 - bne _0804D55E -_0804D59A: - mov r1, r8 - cmp r1, r9 - blt _0804D54A -_0804D5A0: - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GenerateSecondaryStructures - - thumb_func_start sub_804D5B0 -sub_804D5B0: - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x8 - mov r9, r0 - adds r4, r1, 0 - adds r5, r2, 0 - adds r6, r3, 0 - adds r0, r4, 0 - bl DungeonRandInt - mov r8, r0 - adds r0, r5, 0 - bl DungeonRandInt - str r0, [sp] - str r6, [sp, 0x4] - mov r0, r9 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804D5F0 - add sp, 0x8 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_804D5B0 - - thumb_func_start sub_804D5F0 -sub_804D5F0: + thumb_func_start AssignGridCellConnections +AssignGridCellConnections: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -841,7 +416,7 @@ _0804D8B8: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804D5F0 + thumb_func_end AssignGridCellConnections thumb_func_start CreateGridCellConnections CreateGridCellConnections: @@ -4922,8 +4497,8 @@ _0804F686: bx r1 thumb_func_end sub_804F61C - thumb_func_start sub_804F694 -sub_804F694: + thumb_func_start GenerateSecondaryStructure +GenerateSecondaryStructure: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -5572,6 +5147,6 @@ _0804FBD6: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804F694 + thumb_func_end GenerateSecondaryStructure .align 2,0 diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 993c7d5ab..257dade6e 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -54,11 +54,11 @@ void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); void GenerateStandardFloor(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); void sub_804B72C(UnkDungeonGlobal_unk1C574 *a0); -void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0); +void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0); -void GenerateOuterRoomsFloor(s32 sizeX_, s32 sizeY_, UnkDungeonGlobal_unk1C574 *unkPtr); +void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr); void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); void sub_80506F0(s32 a0, UnkDungeonGlobal_unk1C574 *a1); void sub_804FF08(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); @@ -199,7 +199,7 @@ void sub_804AFAC(void) r10 = TRUE; break; case 4: - sub_804BC80(unkPtr); + GenerateCrossroadsFloor(unkPtr); r10 = TRUE; break; case 5: @@ -652,7 +652,7 @@ void NAKED sub_804AFAC(void) " b _0804B2F6\n" "_0804B2A4:\n" " mov r0, r8\n" -" bl sub_804BC80\n" +" bl GenerateCrossroadsFloor\n" "_0804B2AA:\n" " movs r3, 0x1\n" " mov r10, r3\n" @@ -1001,7 +1001,7 @@ struct GridCell bool8 isConnected; bool8 unk12; bool8 unk13; - bool8 unk14; + bool8 isMonsterHouse; bool8 unk15; bool8 isMazeRoom; bool8 hasBeenMerged; @@ -1015,34 +1015,35 @@ struct GridCell bool8 unk25; bool8 unk26; bool8 unk27; - bool8 unk28; - bool8 unk29; + bool8 flagImperfect; + bool8 flagSecondaryStructure; bool8 unk30; bool8 unk31; }; #define GRID_CELL_LEN 15 -void GetGridPositions(s32 *listX, s32 *listY, s32 sizeX, s32 sizeY); -void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); -void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); -void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY); -void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 roomsNumber); -void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY, u32 roomFlags); -void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); -void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 *listX, s32 *listY); -void sub_804D5B0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, UnkDungeonGlobal_unk1C574 *unkPtr); -void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); -void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); -void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 chance); -void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 numExtraHallways); -static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); +void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); +void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber); +void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); +void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); +void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY); +static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr); +void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr); +void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); +static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); /* * GenerateStandardFloor - Generates a standard, typical floor layout. * * Overview: - * 1. Determine the grid based on sizeX, sizeY + * 1. Determine the grid based on gridSizeX, gridSizeY * 2. Assign and create rooms and hallway anchors to each grid cell * 3. Assign and create connections between grid cells (these are traditional hallways connecting the map together) * 4. Fix any unconnected grid cells by adding more connections or removing their rooms/hallway anchors @@ -1050,32 +1051,32 @@ static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct Gri * 6. Create additional "extra hallways" with random walks outside of existing rooms * 7. Finalize extra room details with imperfections (unused in vanilla?), and structures with secondary terrain */ -void GenerateStandardFloor(s32 sizeX, s32 sizeY, UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; - GetGridPositions(listX, listY, sizeX, sizeY); + GetGridPositions(listX, listY, gridSizeX, gridSizeY); - InitDungeonGrid(grid, sizeX, sizeY); + InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, sizeX, sizeY, unkPtr->unk1); + AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->unk1); - CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); - sub_804D5B0(grid, sizeX, sizeY, unkPtr); - CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); - EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateMazeRoom(grid, sizeX, sizeY, unkPtr->unk9); - GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->unk9); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); - GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); - GenerateRoomImperfections(grid, sizeX, sizeY); - GenerateSecondaryStructures(grid, sizeX, sizeY); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); + GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } // Decompile once data structure is better understood @@ -1638,7 +1639,7 @@ NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) " lsls r4, 5\n" " add r4, sp\n" " ldr r3, [r4]\n" -" bl sub_804D5B0\n" +" bl AssignRandomGridCellConnections\n" " ldr r5, _0804BC70\n" " add r5, sp\n" " ldr r4, _0804BC74\n" @@ -1735,535 +1736,140 @@ NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) } #endif // NONMATCHING -#ifdef NONMATCHING -void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) +/* + * GenerateCrossroadsFloor - Generates a floor layout with hallways on the inside and rooms on the outside, with empty corners. + * + * Also nicknamed "Ladder Layout" by some. + */ +void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *unkPtr) { + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 x, y; + s32 currRoomIndex; + s32 gridSizeX = 5; + s32 gridSizeY = 4; + // These are needed to match. Perhaps they wanted the code to be clear that outside = rooms, and inside = hallways. + bool8 outerIsRoom = TRUE; + bool8 innerIsRoom = FALSE; + listX[0] = 0; + listX[1] = 11; + listX[2] = 22; + listX[3] = 33; + listX[4] = 44; + listX[5] = 56; + + listY[0] = 1; + listY[1] = 9; + listY[2] = 16; + listY[3] = 23; + listY[4] = 31; + + InitDungeonGrid(grid, gridSizeX, gridSizeY); + + // Mark the outer ring as rooms + for (x = 0; x < gridSizeX; x++) { + grid[x][0].isRoom = outerIsRoom; + grid[x][gridSizeY - 1].isRoom = outerIsRoom; + } + + for (y = 0; y < gridSizeY; y++) { + grid[0][y].isRoom = outerIsRoom; + grid[gridSizeX - 1][y].isRoom = outerIsRoom; + } + + // Mark the inner cells as hallways + for (x = 1; x < gridSizeX - 1; x++) { + for (y = 1; y < gridSizeY - 1; y++) { + grid[x][y].isRoom = innerIsRoom; + } + } + + // Invalidate the corners + grid[0][0].isInvalid = TRUE; + grid[4][0].isInvalid = TRUE; + grid[0][3].isInvalid = TRUE; + grid[4][3].isInvalid = TRUE; + + currRoomIndex = 0; + for (y = 0; y < gridSizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + if (grid[x][y].isInvalid) + continue; + + if (grid[x][y].isRoom) { + // Room + s32 curX, curY; + s32 minX = listX[x] + 2; + s32 minY = listY[y] + 2; + s32 rangeX = listX[x + 1] - listX[x] - 3; + s32 rangeY = listY[y + 1] - listY[y] - 3; + + s32 room_size_x = DungeonRandRange(5, rangeX); + s32 room_size_y = DungeonRandRange(4, rangeY); + s32 startX = DungeonRandInt(rangeX - room_size_x) + minX; + s32 startY = DungeonRandInt(rangeY - room_size_y) + minY; + s32 endX = startX + room_size_x; + s32 endY = startY + room_size_y; + + grid[x][y].start.x = startX; + grid[x][y].end.x = endX; + grid[x][y].start.y = startY; + grid[x][y].end.y = endY; + for (curX = startX; curX < endX; curX++) { + for (curY = startY; curY < endY; curY++) { + SetTerrainNormal(GetTileSafe(curX, curY)); + GetTileSafe(curX, curY)->room = currRoomIndex; + } + } + + currRoomIndex += 1; + } + else { + // Hallway Anchor + s32 minX = listX[x] + 1; + s32 minY = listY[y] + 1; + s32 rangeX = listX[x + 1] - listX[x] - 3; + s32 rangeY = listY[y + 1] - listY[y] - 3; + s32 startX = DungeonRandRange(minX, minX + rangeX); + s32 startY = DungeonRandRange(minY, minY + rangeY); + + grid[x][y].start.x = startX; + grid[x][y].end.x = startX + 1; + grid[x][y].start.y = startY; + grid[x][y].end.y = startY + 1; + + SetTerrainNormal(GetTileSafe(startX, startY)); + GetTileSafe(startX, startY)->room = CORRIDOR_ROOM; + } + } + } + + for (x = 1; x < 5 - 1; x++) { + for (y = 0; y < 4 - 1; y++) { + grid[x][y].connectedToBottom = TRUE; + grid[x][y + 1].connectedToTop = TRUE; + } + } + + for (y = 1; y < 4 - 1; y++) { + for (x = 0; x < 5 - 1; x++) { + grid[x][y].connectedToRight = TRUE; + grid[x + 1][y].connectedToLeft = TRUE; + } + } + + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); + + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } -#else -NAKED void sub_804BC80(UnkDungeonGlobal_unk1C574 *a0) -{ - asm_unified("push {r4-r7,lr}\n" -" mov r7, r10\n" -" mov r6, r9\n" -" mov r5, r8\n" -" push {r5-r7}\n" -" ldr r4, _0804BED0\n" -" add sp, r4\n" -" movs r1, 0xE5\n" -" lsls r1, 5\n" -" add r1, sp\n" -" str r0, [r1]\n" -" movs r4, 0x1\n" -" movs r5, 0\n" -" ldr r1, _0804BED4\n" -" add r1, sp\n" -" str r5, [r1]\n" -" movs r0, 0xB\n" -" str r0, [r1, 0x4]\n" -" movs r0, 0x16\n" -" str r0, [r1, 0x8]\n" -" movs r0, 0x21\n" -" str r0, [r1, 0xC]\n" -" movs r0, 0x2C\n" -" str r0, [r1, 0x10]\n" -" movs r0, 0x38\n" -" str r0, [r1, 0x14]\n" -" ldr r1, _0804BED8\n" -" add r1, sp\n" -" str r4, [r1]\n" -" movs r0, 0x9\n" -" str r0, [r1, 0x4]\n" -" movs r0, 0x10\n" -" str r0, [r1, 0x8]\n" -" movs r0, 0x17\n" -" str r0, [r1, 0xC]\n" -" movs r0, 0x1F\n" -" str r0, [r1, 0x10]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x5\n" -" movs r2, 0x4\n" -" bl InitDungeonGrid\n" -" add r6, sp, 0x70\n" -" add r1, sp, 0x68\n" -" add r0, sp, 0x8\n" -" movs r3, 0xF0\n" -" lsls r3, 1\n" -" movs r2, 0x5\n" -"_0804BCE0:\n" -" strb r4, [r0, 0xA]\n" -" strb r4, [r1, 0xA]\n" -" adds r1, r3\n" -" adds r0, r3\n" -" subs r2, 0x1\n" -" cmp r2, 0\n" -" bne _0804BCE0\n" -" movs r3, 0x5\n" -" subs r3, 0x1\n" -" movs r2, 0x4\n" -" cmp r2, 0\n" -" beq _0804BD1A\n" -" lsls r0, r3, 4\n" -" subs r0, r3\n" -" lsls r0, 5\n" -" add r0, sp\n" -" adds r0, 0x8\n" -" add r1, sp, 0x8\n" -" mov r10, r2\n" -"_0804BD06:\n" -" strb r4, [r1, 0xA]\n" -" strb r4, [r0, 0xA]\n" -" adds r0, 0x20\n" -" adds r1, 0x20\n" -" movs r2, 0x1\n" -" negs r2, r2\n" -" add r10, r2\n" -" mov r2, r10\n" -" cmp r2, 0\n" -" bne _0804BD06\n" -"_0804BD1A:\n" -" movs r2, 0x1\n" -" cmp r2, r3\n" -" bge _0804BD58\n" -" movs r1, 0x3\n" -"_0804BD22:\n" -" adds r4, r2, 0x1\n" -" ldr r0, _0804BEDC\n" -" add r0, sp\n" -" str r4, [r0]\n" -" cmp r1, 0x1\n" -" ble _0804BD4E\n" -" lsls r0, r2, 4\n" -" subs r0, r2\n" -" lsls r0, 5\n" -" add r0, sp\n" -" adds r0, 0x8\n" -" adds r0, 0x20\n" -" subs r2, r1, 0x1\n" -" mov r10, r2\n" -"_0804BD3E:\n" -" strb r5, [r0, 0xA]\n" -" adds r0, 0x20\n" -" movs r4, 0x1\n" -" negs r4, r4\n" -" add r10, r4\n" -" mov r2, r10\n" -" cmp r2, 0\n" -" bne _0804BD3E\n" -"_0804BD4E:\n" -" ldr r4, _0804BEDC\n" -" add r4, sp\n" -" ldr r2, [r4]\n" -" cmp r2, r3\n" -" blt _0804BD22\n" -"_0804BD58:\n" -" add r0, sp, 0x8\n" -" movs r1, 0x1\n" -" strb r1, [r0, 0x8]\n" -" movs r0, 0xF2\n" -" lsls r0, 3\n" -" add r0, sp\n" -" strb r1, [r0]\n" -" strb r1, [r6]\n" -" movs r0, 0xFE\n" -" lsls r0, 3\n" -" add r0, sp\n" -" strb r1, [r0]\n" -" movs r5, 0\n" -" ldr r6, _0804BEE0\n" -" add r6, sp\n" -" str r5, [r6]\n" -" mov r10, r5\n" -" cmp r5, 0x4\n" -" blt _0804BD80\n" -" b _0804BFAC\n" -"_0804BD80:\n" -" movs r0, 0x4\n" -" movs r1, 0xE6\n" -" lsls r1, 5\n" -" add r1, sp\n" -" str r0, [r1]\n" -"_0804BD8A:\n" -" movs r2, 0\n" -" cmp r2, 0x5\n" -" blt _0804BD92\n" -" b _0804BF94\n" -"_0804BD92:\n" -" ldr r3, _0804BED4\n" -" add r3, sp\n" -" ldr r4, _0804BEE4\n" -" add r4, sp\n" -" str r3, [r4]\n" -" ldr r5, _0804BED8\n" -" add r5, sp\n" -" ldr r6, _0804BEE8\n" -" add r6, sp\n" -" str r5, [r6]\n" -" mov r1, r10\n" -" lsls r0, r1, 2\n" -" adds r0, r5, r0\n" -" ldr r3, _0804BEEC\n" -" add r3, sp\n" -" str r0, [r3]\n" -"_0804BDB2:\n" -" lsls r0, r2, 4\n" -" subs r0, r2\n" -" add r0, r10\n" -" lsls r0, 5\n" -" mov r7, sp\n" -" adds r7, r0\n" -" adds r7, 0x8\n" -" ldrb r0, [r7, 0x8]\n" -" adds r4, r2, 0x1\n" -" ldr r5, _0804BEDC\n" -" add r5, sp\n" -" str r4, [r5]\n" -" cmp r0, 0\n" -" beq _0804BDD0\n" -" b _0804BF88\n" -"_0804BDD0:\n" -" ldrb r0, [r7, 0xA]\n" -" cmp r0, 0\n" -" bne _0804BDD8\n" -" b _0804BF00\n" -"_0804BDD8:\n" -" lsls r0, r2, 2\n" -" ldr r6, _0804BEE4\n" -" add r6, sp\n" -" ldr r6, [r6]\n" -" adds r0, r6, r0\n" -" ldr r1, [r0]\n" -" adds r0, r1, 0x2\n" -" mov r9, r0\n" -" ldr r3, _0804BEEC\n" -" add r3, sp\n" -" ldr r3, [r3]\n" -" ldr r2, [r3]\n" -" adds r4, r2, 0x2\n" -" ldr r5, _0804BEF0\n" -" add r5, sp\n" -" str r4, [r5]\n" -" ldr r6, _0804BEDC\n" -" add r6, sp\n" -" ldr r6, [r6]\n" -" lsls r0, r6, 2\n" -" ldr r3, _0804BEE4\n" -" add r3, sp\n" -" ldr r3, [r3]\n" -" adds r0, r3, r0\n" -" ldr r4, [r0]\n" -" subs r4, r1\n" -" subs r4, 0x3\n" -" ldr r5, _0804BEE8\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" movs r6, 0xE6\n" -" lsls r6, 5\n" -" add r6, sp\n" -" ldr r6, [r6]\n" -" adds r0, r5, r6\n" -" ldr r5, [r0]\n" -" subs r5, r2\n" -" subs r5, 0x3\n" -" movs r0, 0x5\n" -" adds r1, r4, 0\n" -" bl DungeonRandRange\n" -" mov r8, r0\n" -" movs r0, 0x4\n" -" adds r1, r5, 0\n" -" bl DungeonRandRange\n" -" adds r6, r0, 0\n" -" mov r0, r8\n" -" subs r4, r0\n" -" adds r0, r4, 0\n" -" bl DungeonRandInt\n" -" adds r4, r0, 0\n" -" add r4, r9\n" -" subs r5, r6\n" -" adds r0, r5, 0\n" -" bl DungeonRandInt\n" -" ldr r2, _0804BEF0\n" -" add r2, sp\n" -" ldr r1, [r2]\n" -" adds r1, r0\n" -" mov r9, r1\n" -" mov r5, r8\n" -" adds r3, r4, r5\n" -" add r6, r9\n" -" strh r4, [r7]\n" -" strh r3, [r7, 0x4]\n" -" strh r1, [r7, 0x2]\n" -" strh r6, [r7, 0x6]\n" -" ldr r1, _0804BEE0\n" -" add r1, sp\n" -" ldr r0, [r1]\n" -" adds r0, 0x1\n" -" ldr r1, _0804BEF4\n" -" add r1, sp\n" -" str r0, [r1]\n" -" cmp r4, r3\n" -" bge _0804BEC0\n" -"_0804BE78:\n" -" mov r5, r9\n" -" adds r7, r4, 0x1\n" -" cmp r5, r6\n" -" bge _0804BEBA\n" -" ldr r2, _0804BEF8\n" -" mov r8, r2\n" -"_0804BE84:\n" -" adds r0, r4, 0\n" -" adds r1, r5, 0\n" -" ldr r2, _0804BEFC\n" -" add r2, sp\n" -" str r3, [r2]\n" -" bl GetTileSafe\n" -" ldrh r1, [r0]\n" -" mov r2, r8\n" -" ands r1, r2\n" -" movs r2, 0x1\n" -" orrs r1, r2\n" -" strh r1, [r0]\n" -" adds r0, r4, 0\n" -" adds r1, r5, 0\n" -" bl GetTileSafe\n" -" ldr r1, _0804BEE0\n" -" add r1, sp\n" -" ldrb r1, [r1]\n" -" strb r1, [r0, 0x9]\n" -" adds r5, 0x1\n" -" ldr r2, _0804BEFC\n" -" add r2, sp\n" -" ldr r3, [r2]\n" -" cmp r5, r6\n" -" blt _0804BE84\n" -"_0804BEBA:\n" -" adds r4, r7, 0\n" -" cmp r4, r3\n" -" blt _0804BE78\n" -"_0804BEC0:\n" -" ldr r3, _0804BEF4\n" -" add r3, sp\n" -" ldr r3, [r3]\n" -" ldr r4, _0804BEE0\n" -" add r4, sp\n" -" str r3, [r4]\n" -" b _0804BF88\n" -" .align 2, 0\n" -"_0804BED0: .4byte 0xffffe338\n" -"_0804BED4: .4byte 0x00001c28\n" -"_0804BED8: .4byte 0x00001c64\n" -"_0804BEDC: .4byte 0x00001cb8\n" -"_0804BEE0: .4byte 0x00001ca4\n" -"_0804BEE4: .4byte 0x00001ca8\n" -"_0804BEE8: .4byte 0x00001cb0\n" -"_0804BEEC: .4byte 0x00001cb4\n" -"_0804BEF0: .4byte 0x00001cac\n" -"_0804BEF4: .4byte 0x00001cbc\n" -"_0804BEF8: .4byte 0x0000fffc\n" -"_0804BEFC: .4byte 0x00001cc4\n" -"_0804BF00:\n" -" lsls r0, r2, 2\n" -" ldr r4, _0804C080\n" -" add r4, sp\n" -" ldr r4, [r4]\n" -" adds r0, r4, r0\n" -" ldr r2, [r0]\n" -" adds r0, r2, 0x1\n" -" ldr r5, _0804C084\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" ldr r3, [r5]\n" -" adds r6, r3, 0x1\n" -" mov r8, r6\n" -" ldr r4, _0804C088\n" -" add r4, sp\n" -" ldr r4, [r4]\n" -" lsls r1, r4, 2\n" -" ldr r5, _0804C080\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" adds r1, r5, r1\n" -" ldr r1, [r1]\n" -" subs r1, r2\n" -" subs r1, 0x3\n" -" ldr r6, _0804C08C\n" -" add r6, sp\n" -" ldr r6, [r6]\n" -" movs r4, 0xE6\n" -" lsls r4, 5\n" -" add r4, sp\n" -" ldr r4, [r4]\n" -" adds r2, r6, r4\n" -" ldr r4, [r2]\n" -" subs r4, r3\n" -" subs r4, 0x3\n" -" adds r1, r0, r1\n" -" bl DungeonRandRange\n" -" adds r5, r0, 0\n" -" add r4, r8\n" -" mov r0, r8\n" -" adds r1, r4, 0\n" -" bl DungeonRandRange\n" -" adds r4, r0, 0\n" -" strh r5, [r7]\n" -" adds r0, r5, 0x1\n" -" strh r0, [r7, 0x4]\n" -" strh r4, [r7, 0x2]\n" -" adds r0, r4, 0x1\n" -" strh r0, [r7, 0x6]\n" -" adds r0, r5, 0\n" -" adds r1, r4, 0\n" -" bl GetTileSafe\n" -" ldrh r1, [r0]\n" -" ldr r6, _0804C090\n" -" adds r2, r6, 0\n" -" ands r1, r2\n" -" movs r2, 0x1\n" -" orrs r1, r2\n" -" strh r1, [r0]\n" -" adds r0, r5, 0\n" -" adds r1, r4, 0\n" -" bl GetTileSafe\n" -" movs r1, 0xFF\n" -" strb r1, [r0, 0x9]\n" -"_0804BF88:\n" -" ldr r0, _0804C088\n" -" add r0, sp\n" -" ldr r2, [r0]\n" -" cmp r2, 0x5\n" -" bge _0804BF94\n" -" b _0804BDB2\n" -"_0804BF94:\n" -" movs r2, 0xE6\n" -" lsls r2, 5\n" -" add r2, sp\n" -" ldr r1, [r2]\n" -" adds r1, 0x4\n" -" str r1, [r2]\n" -" movs r3, 0x1\n" -" add r10, r3\n" -" mov r4, r10\n" -" cmp r4, 0x4\n" -" bge _0804BFAC\n" -" b _0804BD8A\n" -"_0804BFAC:\n" -" movs r2, 0x1\n" -" movs r1, 0x1\n" -" movs r3, 0xF\n" -" add r4, sp, 0x1C\n" -"_0804BFB4:\n" -" movs r5, 0\n" -" mov r10, r5\n" -" lsls r0, r3, 5\n" -" adds r0, r4\n" -"_0804BFBC:\n" -" strb r1, [r0]\n" -" strb r1, [r0, 0x1F]\n" -" adds r0, 0x20\n" -" movs r6, 0x1\n" -" add r10, r6\n" -" mov r5, r10\n" -" cmp r5, 0x2\n" -" ble _0804BFBC\n" -" movs r0, 0xF0\n" -" lsls r0, 1\n" -" adds r3, 0xF\n" -" adds r2, 0x1\n" -" cmp r2, 0x3\n" -" ble _0804BFB4\n" -" mov r10, r6\n" -" movs r5, 0x1\n" -" adds r4, r0, 0\n" -" mov r6, sp\n" -" adds r6, r4\n" -" adds r6, 0x8\n" -"_0804BFE4:\n" -" movs r2, 0\n" -" mov r1, r10\n" -" lsls r0, r1, 5\n" -" mov r3, r10\n" -" adds r3, 0x1\n" -" adds r1, r0, r6\n" -" add r0, sp\n" -" adds r0, 0x8\n" -"_0804BFF4:\n" -" strb r5, [r0, 0x16]\n" -" strb r5, [r1, 0x15]\n" -" adds r1, r4\n" -" adds r0, r4\n" -" adds r2, 0x1\n" -" cmp r2, 0x3\n" -" ble _0804BFF4\n" -" mov r10, r3\n" -" cmp r3, 0x2\n" -" ble _0804BFE4\n" -" ldr r5, _0804C094\n" -" add r5, sp\n" -" ldr r4, _0804C098\n" -" add r4, sp\n" -" str r4, [sp]\n" -" movs r0, 0x1\n" -" str r0, [sp, 0x4]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x5\n" -" movs r2, 0x4\n" -" adds r3, r5, 0\n" -" bl CreateGridCellConnections\n" -" str r4, [sp]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x5\n" -" movs r2, 0x4\n" -" adds r3, r5, 0\n" -" bl EnsureConnectedGrid\n" -" ldr r0, _0804C09C\n" -" movs r2, 0\n" -" ldrsh r3, [r0, r2]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x5\n" -" movs r2, 0x4\n" -" bl GenerateKecleonShop\n" -" ldr r0, _0804C0A0\n" -" movs r4, 0\n" -" ldrsh r3, [r0, r4]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x5\n" -" movs r2, 0x4\n" -" bl GenerateMonsterHouse\n" -" movs r5, 0xE5\n" -" lsls r5, 5\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" ldrb r3, [r5, 0x13]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x5\n" -" movs r2, 0x4\n" -" bl GenerateExtraHallways\n" -" add r0, sp, 0x8\n" -" movs r1, 0x5\n" -" movs r2, 0x4\n" -" bl GenerateRoomImperfections\n" -" ldr r3, _0804C0A4\n" -" add sp, r3\n" -" pop {r3-r5}\n" -" mov r8, r3\n" -" mov r9, r4\n" -" mov r10, r5\n" -" pop {r4-r7}\n" -" pop {r0}\n" -" bx r0\n" -" .align 2, 0\n" -"_0804C080: .4byte 0x00001ca8\n" -"_0804C084: .4byte 0x00001cb4\n" -"_0804C088: .4byte 0x00001cb8\n" -"_0804C08C: .4byte 0x00001cb0\n" -"_0804C090: .4byte 0x0000fffc\n" -"_0804C094: .4byte 0x00001c28\n" -"_0804C098: .4byte 0x00001c64\n" -"_0804C09C: .4byte gUnknown_202F1B0\n" -"_0804C0A0: .4byte gUnknown_202F1B2\n" -"_0804C0A4: .4byte 0x00001cc8"); -} -#endif // NONMATCHING // GenerateLineFloor - Generates a floor layout with 5 grid cells in a horizontal line. void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) @@ -2271,7 +1877,7 @@ void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; - s32 sizeX, sizeY; + s32 gridSizeX, gridSizeY; bool8 disableRoomMerging; listX[0] = 0; @@ -2285,22 +1891,22 @@ void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) listY[1] = 15; disableRoomMerging = 1; - sizeX = 5, sizeY = 1; - InitDungeonGrid(grid, sizeX, sizeY); + gridSizeX = 5, gridSizeY = 1; + InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, sizeX, sizeY, unkPtr->unk1); - CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->unk1); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); - sub_804D5B0(grid, sizeX, sizeY, unkPtr); - CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, disableRoomMerging); + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, disableRoomMerging); - EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); - GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); - GenerateRoomImperfections(grid, sizeX, sizeY); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } // GenerateCrossFloor - Generates a floor layout with 5 rooms arranged in a "plus" or "cross" configuration. @@ -2309,7 +1915,7 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; - s32 x, y, sizeX, sizeY; + s32 x, y, gridSizeX, gridSizeY; listX[0] = 11; listX[1] = 22; @@ -2321,12 +1927,12 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) listY[2] = 20; listY[3] = 30; - sizeX = 3, sizeY = 3; - InitDungeonGrid(grid, sizeX, sizeY); + gridSizeX = 3, gridSizeY = 3; + InitDungeonGrid(grid, gridSizeX, gridSizeY); // Set all cells as rooms - for (x = 0; x < sizeX; x++) { - for (y = 0; y < sizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { grid[x][y].isRoom = TRUE; } } @@ -2337,7 +1943,7 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) grid[0][2].isInvalid = TRUE; grid[2][2].isInvalid = TRUE; - CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); grid[0][1].connectedToRight = TRUE; grid[1][1].connectedToLeft = TRUE; @@ -2347,15 +1953,15 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) grid[1][1].connectedToTop = TRUE; grid[1][1].connectedToBottom = TRUE; grid[1][2].connectedToTop = TRUE; - CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, TRUE); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); - EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); - GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); - GenerateRoomImperfections(grid, sizeX, sizeY); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } // GenerateBeetleFloor - Generates a floor layout in a "beetle" shape, with a @@ -2365,7 +1971,7 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; - s32 x, y, sizeX, sizeY; + s32 x, y, gridSizeX, gridSizeY; listX[0] = 5; listX[1] = 15; @@ -2377,16 +1983,16 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) listY[2] = 20; listY[3] = 30; - sizeX = 3, sizeY = 3; - InitDungeonGrid(grid, sizeX, sizeY); + gridSizeX = 3, gridSizeY = 3; + InitDungeonGrid(grid, gridSizeX, gridSizeY); // Set all cells as rooms - for (x = 0; x < sizeX; x++) { - for (y = 0; y < sizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { grid[x][y].isRoom = TRUE; } } - CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); // Connect rooms in the same row together for (y = 0; y < 3; y++) { @@ -2395,32 +2001,32 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) grid[1][y].connectedToRight = TRUE; grid[2][y].connectedToLeft = TRUE; } - CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, TRUE); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); // Merge the center column into one large room MergeRoomsVertically(1, 0, 1, grid); MergeRoomsVertically(1, 0, 2, grid); - EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); - GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); - GenerateRoomImperfections(grid, sizeX, sizeY); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } // MergeRoomsVertically - Merges two vertically stacked rooms into one larger room. -static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]) +static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]) { s32 x, y; - s32 xStart = min(grid[roomX][room_y1].start.x, grid[roomX][room_y1+room_dy].start.x); - s32 yStart = grid[roomX][room_y1].start.y; - s32 xEnd = max(grid[roomX][room_y1].end.x, grid[roomX][room_y1+room_dy].end.x); - s32 yEnd = grid[roomX][room_y1 + room_dy].end.y; + s32 xStart = min(grid[roomX][roomY1].start.x, grid[roomX][roomY1+room_dy].start.x); + s32 yStart = grid[roomX][roomY1].start.y; + s32 xEnd = max(grid[roomX][roomY1].end.x, grid[roomX][roomY1+room_dy].end.x); + s32 yEnd = grid[roomX][roomY1 + room_dy].end.y; // Carve out the new larger room, retaining the index of the first room - u8 roomId = GetTile(grid[roomX][room_y1].start.x, grid[roomX][room_y1].start.y)->room; + u8 roomId = GetTile(grid[roomX][roomY1].start.x, grid[roomX][roomY1].start.y)->room; for (x = xStart; x < xEnd; x++) { for (y = yStart; y < yEnd; y++) { @@ -2430,95 +2036,95 @@ static void MergeRoomsVertically(s32 roomX, s32 room_y1, s32 room_dy, struct Gri } } - grid[roomX][room_y1].start.x = xStart; - grid[roomX][room_y1].end.x = xEnd; - grid[roomX][room_y1].start.y = yStart; - grid[roomX][room_y1].end.y = yEnd; + grid[roomX][roomY1].start.x = xStart; + grid[roomX][roomY1].end.x = xEnd; + grid[roomX][roomY1].start.y = yStart; + grid[roomX][roomY1].end.y = yEnd; - grid[roomX][room_y1 + room_dy].isMerged = TRUE; - grid[roomX][room_y1].isMerged = TRUE; - grid[roomX][room_y1 + room_dy].isConnected = FALSE; - grid[roomX][room_y1 + room_dy].hasBeenMerged = TRUE; + grid[roomX][roomY1 + room_dy].isMerged = TRUE; + grid[roomX][roomY1].isMerged = TRUE; + grid[roomX][roomY1 + room_dy].isConnected = FALSE; + grid[roomX][roomY1 + room_dy].hasBeenMerged = TRUE; } // GenerateOuterRoomsFloor - Generates a floor layout with a ring of rooms and nothing on the interior. -// This layout is bugged and will not properly connect rooms for sizeX < 3. -void GenerateOuterRoomsFloor(s32 sizeX_, s32 sizeY_, UnkDungeonGlobal_unk1C574 *unkPtr) +// This layout is bugged and will not properly connect rooms for gridSizeX < 3. +void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; s32 x, y; - s32 sizeX = sizeX_; - s32 sizeY = sizeY_; + s32 gridSizeX = gridSizeX_; + s32 gridSizeY = gridSizeY_; - GetGridPositions(listX, listY, sizeX, sizeY); - InitDungeonGrid(grid, sizeX, sizeY); + GetGridPositions(listX, listY, gridSizeX, gridSizeY); + InitDungeonGrid(grid, gridSizeX, gridSizeY); // Make all cells rooms - for (x = 0; x < sizeX; x++) { - for (y = 0; y < sizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { grid[x][y].isRoom = TRUE; } } // Invalidate all interior cells - for (x = 1; x < sizeX - 1; x++) { - for (y = 1; y < sizeY - 1; y++) { + for (x = 1; x < gridSizeX - 1; x++) { + for (y = 1; y < gridSizeY - 1; y++) { grid[x][y].isInvalid = TRUE; } } - CreateRoomsAndAnchors(grid, sizeX, sizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); // Maybe Todo: Add EpicYoshiMaster's fixed implementation of this function - // The original implementation fails for sizeX <= 2, as one of the branches + // The original implementation fails for gridSizeX <= 2, as one of the branches // is never taken, and the other branch does not provide a backup connection, leaving the two sides unconnected. // Additionally, there is a minor issue for top/bottom connections which results in hallways being connected from the bottom // instead of from the top, but this does not affect the connectivity of the map. - for (x = 0; x < sizeX - 1; x++) { + for (x = 0; x < gridSizeX - 1; x++) { if (x != 0) { grid[x][0].connectedToRight = TRUE; - grid[x][sizeY-1].connectedToRight = TRUE; + grid[x][gridSizeY-1].connectedToRight = TRUE; } - // Bug: if sizeX <= 2, this branch will never be run. + // Bug: if gridSizeX <= 2, this branch will never be run. // Additionally, because the branch above this has no meaningful hallways produced for - // sizeX == 1, no connections will be made between columns here. - // This results in an unconnected map for sizeX <= 2. - if (x < sizeX - 2) { + // gridSizeX == 1, no connections will be made between columns here. + // This results in an unconnected map for gridSizeX <= 2. + if (x < gridSizeX - 2) { grid[x+1][0].connectedToLeft = TRUE; - grid[x+1][sizeY-1].connectedToLeft = TRUE; + grid[x+1][gridSizeY-1].connectedToLeft = TRUE; } } - for (y = 0; y < sizeY - 1; y++) { + for (y = 0; y < gridSizeY - 1; y++) { if (y != 0) { grid[0][y].connectedToTop = TRUE; - grid[sizeX-1][y].connectedToTop = TRUE; + grid[gridSizeX-1][y].connectedToTop = TRUE; } // This connection ends up not being set for the bottom row, but this is fine because the other // connection to this room is still correct. The result is that hallways here will be using the opposing end // of the grid cell boundary for their turns compared to top/bottom hallways between other rows. - if (y < sizeY - 2) { + if (y < gridSizeY - 2) { grid[0][y].connectedToBottom = TRUE; - grid[sizeX-1][y].connectedToBottom = TRUE; + grid[gridSizeX-1][y].connectedToBottom = TRUE; } } - CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); - EnsureConnectedGrid(grid, sizeX, sizeY, listX, listY); + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateMazeRoom(grid, sizeX, sizeY, unkPtr->unk9); - GenerateKecleonShop(grid, sizeX, sizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, sizeX, sizeY, gUnknown_202F1B2); + GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->unk9); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); - GenerateExtraHallways(grid, sizeX, sizeY, unkPtr->unk13); - GenerateRoomImperfections(grid, sizeX, sizeY); - GenerateSecondaryStructures(grid, sizeX, sizeY); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); + GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); @@ -2552,41 +2158,40 @@ bool8 sub_804C70C(s32 a0, UnkDungeonGlobal_unk1C574 *unkPtr) } void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x1, s32 y1, s32 *a3, s32 *a4, s32 a5, s32 x2, s32 y2); -void sub_804D5F0(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x, s32 y, s32 x2, s32 y2, UnkDungeonGlobal_unk1C574 *unkPtr); void sub_8051438(struct GridCell *cell, s32 a1); -void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr) +void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr) { s32 tries; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; s32 r10 = 0; - s32 x3 = 0, y3 = 0; + s32 cursorX = 0, cursorY = 0; - GetGridPositions(listX, listY, x1, y1); - InitDungeonGrid(grid, x1, y1); - AssignRooms(grid, x1, y1, unkPtr->unk1); - for (x3 = 0; x3 < x1; x3++) { - for (y3 = 0; y3 < y1; y3++) { - grid[x3][y3].unk27 = 1; + GetGridPositions(listX, listY, gridSizeX, gridSizeY); + InitDungeonGrid(grid, gridSizeX, gridSizeY); + AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->unk1); + for (cursorX = 0; cursorX < gridSizeX; cursorX++) { + for (cursorY = 0; cursorY < gridSizeY; cursorY++) { + grid[cursorX][cursorY].unk27 = 1; } } for (tries = 0; tries < 64; tries++) { - x3 = DungeonRandInt(x1); - y3 = DungeonRandInt(y1); - r10 = y3 * x1 + x3; - if (grid[x3][y3].isRoom) + cursorX = DungeonRandInt(gridSizeX); + cursorY = DungeonRandInt(gridSizeY); + r10 = cursorY * gridSizeX + cursorX; + if (grid[cursorX][cursorY].isRoom) break; } - sub_8050F90(grid, x1, y1, listX, listY, r10, x2, y2); - if (x1 != 1 || y1 != 1) { - sub_804D5F0(grid, x1, y1, x3, y3, unkPtr); - CreateGridCellConnections(grid, x1, y1, listX, listY, TRUE); - EnsureConnectedGrid(grid, x1, y1, listX, listY); + sub_8050F90(grid, gridSizeX, gridSizeY, listX, listY, r10, x2, y2); + if (gridSizeX != 1 || gridSizeY != 1) { + AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, unkPtr); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); } - sub_8051438(&grid[x3][y3], a4); + sub_8051438(&grid[cursorX][cursorY], a4); } /* @@ -2624,8 +2229,8 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; s32 listY[GRID_CELL_LEN]; - const s32 sizeX = 2; - const s32 sizeY = 1; + const s32 gridSizeX = 2; + const s32 gridSizeY = 1; s32 currRoomId = 0; s32 x, y; @@ -2634,10 +2239,10 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) listX[2] = 54; listY[0] = 2; listY[1] = 30; - InitDungeonGrid(grid, sizeX, sizeY); + InitDungeonGrid(grid, gridSizeX, gridSizeY); - for (y = 0; y < sizeY; y++) { - for (x = 0; x < sizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + for (x = 0; x < gridSizeX; x++) { s32 currX, currY; s32 minX = listX[x] + 1; s32 minY = listY[y] + 1; @@ -2669,8 +2274,8 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) grid[0][0].connectedToRight = TRUE; grid[1][0].connectedToLeft = TRUE; - CreateGridCellConnections(grid, sizeX, sizeY, listX, listY, FALSE); - GenerateMonsterHouse(grid, sizeX, sizeY, 999); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, 999); } /* @@ -2703,7 +2308,7 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) * * Repeat 4-8 until a check fails. */ -void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 numExtraHallways) +void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways) { s32 i, j; @@ -2718,8 +2323,8 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s s32 checkX, checkY, checkX2, checkY2; s32 xLoop, yLoop; // Select a random grid cell - s32 x = DungeonRandInt(sizeX); - s32 y = DungeonRandInt(sizeY); + s32 x = DungeonRandInt(gridSizeX); + s32 y = DungeonRandInt(gridSizeY); // To generate extra hallways the cell must be: // - a room @@ -2737,11 +2342,11 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // If invalid, rotate counter-clockwise until one works for (j = 0; j < 3; j++) { - if (direction == DIRECTION_SOUTH && y >= sizeY - 1) { + if (direction == DIRECTION_SOUTH && y >= gridSizeY - 1) { direction = DIRECTION_EAST; } - if (direction == DIRECTION_EAST && x >= sizeX - 1) { + if (direction == DIRECTION_EAST && x >= gridSizeX - 1) { direction = DIRECTION_NORTH; } @@ -2901,21 +2506,21 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s } // GetGridPositions - Determines the starting positions of grid cells based on the given floor grid dimensions -void GetGridPositions(s32 *listX, s32 *listY, s32 sizeX, s32 sizeY) +void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY) { s32 i, sum; - for (i = 0, sum = 0; i < sizeX; i++) { + for (i = 0, sum = 0; i < gridSizeX; i++) { listX[i] = sum; - sum += DUNGEON_MAX_SIZE_X / sizeX; + sum += DUNGEON_MAX_SIZE_X / gridSizeX; } - listX[sizeX] = sum; + listX[gridSizeX] = sum; - for (i = 0, sum = 0; i < sizeY; i++) { + for (i = 0, sum = 0; i < gridSizeY; i++) { listY[i] = sum; - sum += DUNGEON_MAX_SIZE_Y / sizeY; + sum += DUNGEON_MAX_SIZE_Y / gridSizeY; } - listY[sizeY] = sum; + listY[gridSizeY] = sum; } /* @@ -2924,16 +2529,16 @@ void GetGridPositions(s32 *listX, s32 *listY, s32 sizeX, s32 sizeY) * The dungeon grid is an array of grid cells stored in column-major order * (to give contiguous storage to cells with the same x value), with a fixed column size of 15. */ -void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY) +void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) { s32 x, y; - for (x = 0; x < sizeX; x++) { - for (y = 0; y < sizeY; y++) { - if (gUnknown_202F1AE == 1 && x >= sizeX / 2) { + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + if (gUnknown_202F1AE == 1 && x >= gridSizeX / 2) { grid[x][y].isInvalid = TRUE; } - else if (gUnknown_202F1AE == 2 && x >= (sizeX * 3) / 4) { + else if (gUnknown_202F1AE == 2 && x >= (gridSizeX * 3) / 4) { grid[x][y].isInvalid = TRUE; } else { @@ -2943,7 +2548,7 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 siz grid[x][y].isRoom = TRUE; grid[x][y].isConnected = FALSE; grid[x][y].unk15 = FALSE; - grid[x][y].unk14 = FALSE; + grid[x][y].isMonsterHouse = FALSE; grid[x][y].unk12 = FALSE; grid[x][y].connectedToRight = FALSE; grid[x][y].connectedToLeft = FALSE; @@ -2957,8 +2562,8 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 siz grid[x][y].hasBeenMerged = FALSE; grid[x][y].isMazeRoom = FALSE; grid[x][y].isMerged = FALSE; - grid[x][y].unk28 = FALSE; - grid[x][y].unk29 = FALSE; + grid[x][y].flagImperfect = FALSE; + grid[x][y].flagSecondaryStructure = FALSE; } } } @@ -2975,9 +2580,11 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 siz * * Primarily Modifies: grid to assign certain grid cells to have isRoom TRUE. */ -void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, s32 sizeY, s32 roomsNumber) + +#define ROOM_BITS_COUNT 256 // Despite max rooms being 32, randomRoomBits can hold up to 256 possible rooms +void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber) { - bool8 randomRoomBits[256]; + bool8 randomRoomBits[ROOM_BITS_COUNT]; s32 i, nShuffles; s32 x, y; s32 attempts; @@ -2996,12 +2603,12 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, for (i = 0; i < roomsNumber; i++) { randomRoomBits[i] = TRUE; } - for (; i < 256; i++) { + for (; i < ROOM_BITS_COUNT; i++) { randomRoomBits[i] = FALSE; } // Shuffle around the acceptable rooms - maxRooms = sizeX * sizeY; + maxRooms = gridSizeX * gridSizeY; for (nShuffles = 0; nShuffles < 64; nShuffles++) { bool8 temp; @@ -3014,8 +2621,8 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, // Counter for randomRoomBits i = 0; gUnknown_202F1CC = 0; - for (x = 0; x < sizeX; x++) { - for (y = 0; y < sizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { if (grid[x][y].isInvalid) continue; @@ -3030,7 +2637,7 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, gUnknown_202F1CC++; // Don't make a room at (x_mid, 1) - if (sizeX % 2 != 0 && x == (sizeX - 1) / 2 && y == 1 ) { + if (gridSizeX % 2 != 0 && x == (gridSizeX - 1) / 2 && y == 1 ) { grid[x][y].isRoom = FALSE; } } @@ -3048,8 +2655,8 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, for (attempts = 0; attempts < 200; attempts++) { bool8 enoughRooms = FALSE; - for (x = 0; x < sizeX; x++) { - for (y = 0; y < sizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { if (grid[x][y].isInvalid) continue; @@ -3069,4 +2676,178 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sizeX, gUnknown_202F1AD = FALSE; } +#define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 + +/* + * CreateRoomsAndAnchors - Creates the rectangle regions of open terrain for each room + * leaving a margin relative to the border + * + * If the room is an anchor, a single tile is placed with a hallway indicator for later. + */ +void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags) +{ + s32 roomNumber = 0; + s32 x, y; + + for (y = 0; y < gridSizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + s32 minX = listX[x] + 2; + s32 minY = listY[y] + 2; + s32 rangeX = listX[x + 1] - listX[x] - 4; + s32 rangeY = listY[y + 1] - listY[y] - 3; + + if (grid[x][y].isInvalid) continue; + + if (grid[x][y].isRoom) { + // This cell is a room! + s32 roomSizeX, roomSizeY; + s32 startX, endX; + s32 startY, endY; + s32 roomX, roomY; + bool8 flagSecondary, flagImperfect; + + roomSizeX = DungeonRandRange(5, rangeX); + roomSizeY = DungeonRandRange(4, rangeY); + + // Force small rooms to have odd-numbered dimensions (?) + if ((roomSizeX | 1) < rangeX) { + roomSizeX |= 1; + } + + if ((roomSizeY | 1) < rangeY) { + roomSizeY |= 1; + } + + // Aspect ratio 2/3 < x/y < 3/2 + if (roomSizeX > (roomSizeY * 3) / 2) { + roomSizeX = (roomSizeY * 3) / 2; + } + + if (roomSizeY > (roomSizeX * 3) / 2) { + roomSizeY = (roomSizeX * 3) / 2; + } + + startX = DungeonRandInt(rangeX - roomSizeX) + minX; + startY = DungeonRandInt(rangeY - roomSizeY) + minY; + endX = startX + roomSizeX; + endY = startY + roomSizeY; + + // Create the room! + grid[x][y].start.x = startX; + grid[x][y].end.x = endX; + grid[x][y].start.y = startY; + grid[x][y].end.y = endY; + + for (roomX = startX; roomX < endX; roomX++) { + for (roomY = startY; roomY < endY; roomY++) { + SetTerrainNormal(GetTileSafe(roomX, roomY)); + GetTileSafe(roomX, roomY)->room = roomNumber; + } + } + + flagImperfect = TRUE; + // Randomly flag the room for a secondary structure + flagSecondary = DungeonRandInt(100) < GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE; + if (gUnknown_202F1C8 == 0) { + flagSecondary = FALSE; + } + + // Flag for imperfections if needed + if (!(roomFlags & 4)) { + flagImperfect = FALSE; + } + + if (flagImperfect && flagSecondary) { + // If a room gets both, pick one at random + if (DungeonRandInt(100) < 50) { + flagImperfect = FALSE; + } + else { + flagSecondary = FALSE; + } + } + + if (flagImperfect) { + grid[x][y].flagImperfect = TRUE; + } + + if (flagSecondary) { + grid[x][y].flagSecondaryStructure = TRUE; + } + + roomNumber++; + } + else { + // This cell is not a room, create a 1x1 hallway anchor + s32 pt_x, pt_y; + s32 unk_x1 = 2; + s32 unk_x2 = 4; + s32 unk_y1 = 2; + s32 unk_y2 = 4; + + if (x == 0) { + unk_x1 = 1; + } + if (y == 0) { + unk_y1 = 1; + } + + if (x == gridSizeX - 1) { + unk_x2 = 2; + } + if (y == gridSizeY - 1) { + unk_y2 = 2; + } + + pt_x = DungeonRandRange(minX + unk_x1, minX + rangeX - unk_x2); + pt_y = DungeonRandRange(minY + unk_y1, minY + rangeY - unk_y2); + + grid[x][y].start.x = pt_x; + grid[x][y].end.x = pt_x + 1; + grid[x][y].start.y = pt_y; + grid[x][y].end.y = pt_y + 1; + + // Flag the tile as open to serve as a hallway anchor + SetTerrainNormal(GetTileSafe(pt_x, pt_y)); + + // Set the room index to 0xFE for anchor + GetTileSafe(pt_x, pt_y)->room = 0xFE; + } + } + } +} + +void GenerateSecondaryStructure(struct GridCell *cell); + +void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) +{ + s32 x, y; + + for (y = 0; y < gridSizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + // To have a secondary structure a room must be: + // - valid + // - not a monster house, merged, or have imperfections + // - be a room + // - be flagged for a secondary structure + if (!grid[x][y].isInvalid && + !grid[x][y].isMonsterHouse && + !grid[x][y].isMerged && + grid[x][y].isRoom && + !grid[x][y].flagImperfect && + grid[x][y].flagSecondaryStructure) + { + GenerateSecondaryStructure(&grid[x][y]); + } + } + } +} + +static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + s32 cursorX = DungeonRandInt(gridSizeX); + s32 cursorY = DungeonRandInt(gridSizeY); + + AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, unkPtr); +} // From 88c5436602f4f1f7913f27172853fabb8ed62222 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 9 Nov 2024 17:41:27 +0100 Subject: [PATCH 08/30] GenerateOuterRingFloor --- src/code_804AFAC_1.c | 810 ++++++++----------------------------------- 1 file changed, 149 insertions(+), 661 deletions(-) diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 257dade6e..377f9df2e 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -53,7 +53,7 @@ extern const Position gAdjacentTileOffsets[]; void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); void GenerateStandardFloor(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); -void sub_804B72C(UnkDungeonGlobal_unk1C574 *a0); +void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0); @@ -195,7 +195,7 @@ void sub_804AFAC(void) gDungeon->unk3A08 = 1; break; case 3: - sub_804B72C(unkPtr); + GenerateOuterRingFloor(unkPtr); r10 = TRUE; break; case 4: @@ -646,7 +646,7 @@ void NAKED sub_804AFAC(void) "_0804B294: .4byte 0x00003a08\n" "_0804B298:\n" " mov r0, r8\n" -" bl sub_804B72C\n" +" bl GenerateOuterRingFloor\n" " movs r2, 0x1\n" " mov r10, r2\n" " b _0804B2F6\n" @@ -1079,666 +1079,154 @@ void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C5 GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } -// Decompile once data structure is better understood - -#ifdef NONMATCHING -void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) +// GenerateOuterRingFloor - Generates on a 6x4 grid, with the outer border of grid cells being hallways and the inner 4x2 grid being rooms. +void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *unkPtr) { - struct GridCell grid[15][15]; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 x, y; + s32 currRoomIndex; + s32 gridSizeX = 6; + s32 gridSizeY = 4; + // These are needed to match. Perhaps they wanted the code to be clear that inside = rooms, and outside = hallways. + bool8 outerIsRoom = FALSE; + bool8 innerIsRoom = TRUE; - sp.listX[0] = 0; - sp.listX[1] = 5; - sp.listX[3] = 28; - sp.listX[5] = 51 - sp.listX[6] = 56; - sp.listX[2] = 16; - sp.listX[4] = 29; + listX[0] = 0; + listX[1] = 5; + listX[3] = 28; + listX[5] = 51; + listX[6] = 56; + listX[2] = 16; + listX[4] = 39; - sp.listY[0] = 2; - sp.listY[1] = 7; - sp.listY[2] = 16; - sp.listY[3] = 25; - sp.listY[4] = 30; + listY[0] = 2; + listY[1] = 7; + listY[2] = 16; + listY[3] = 25; + listY[4] = 30; - InitDungeonGrid(grid, 6, 4); + InitDungeonGrid(grid, gridSizeX, gridSizeY); + + // Mark the outer ring as not being rooms + for (x = 0; x < gridSizeX; x++) { + grid[x][0].isRoom = outerIsRoom; + grid[x][gridSizeY - 1].isRoom = outerIsRoom; + } + + for (y = 0; y < gridSizeY; y++) { + grid[0][y].isRoom = outerIsRoom; + grid[gridSizeX - 1][y].isRoom = outerIsRoom; + } + + // Mark the inner tiles as rooms + for (x = 1; x < gridSizeX - 1; x++) { + for (y = 1; y < gridSizeY - 1; y++) { + grid[x][y].isRoom = innerIsRoom; + } + } + + currRoomIndex = 0; + + for (y = 0; y < gridSizeY; y++) { + for (x = 0; x < gridSizeX; x++) { + if (grid[x][y].isRoom) { + // Room + s32 curX, curY; + s32 minX = listX[x] + 2; + s32 minY = listY[y] + 2; + s32 rangeX = listX[x + 1] - listX[x] - 3; + s32 rangeY = listY[y + 1] - listY[y] - 3; + + s32 roomSizeX = DungeonRandRange(5, rangeX); + s32 roomSizeY = DungeonRandRange(4, rangeY); + s32 startX = DungeonRandInt(rangeX - roomSizeX) + minX; + s32 startY = DungeonRandInt(rangeY - roomSizeY) + minY; + s32 endX = startX + roomSizeX; + s32 endY = startY + roomSizeY; + + grid[x][y].start.x = startX; + grid[x][y].end.x = endX; + grid[x][y].start.y = startY; + grid[x][y].end.y = startY + roomSizeY; + for (curX = startX; curX < endX; curX++) { + for (curY = startY; curY < endY; curY++) { + SetTerrainNormal(GetTileSafe(curX, curY)); + GetTileSafe(curX, curY)->room = currRoomIndex; + } + } + + currRoomIndex++; + } + else + { + // Hallway Anchor + s32 minX = listX[x] + 1; + s32 minY = listY[y] + 1; + s32 rangeX = listX[x + 1] - listX[x] - 3; + s32 rangeY = listY[y + 1] - listY[y] - 3; + s32 startX = DungeonRandRange(minX, minX + rangeX); + s32 startY = DungeonRandRange(minY, minY + rangeY); + + grid[x][y].start.x = startX; + grid[x][y].end.x = startX + 1; + grid[x][y].start.y = startY; + grid[x][y].end.y = startY + 1; + + SetTerrainNormal(GetTileSafe(startX, startY)); + GetTileSafe(startX, startY)->room = CORRIDOR_ROOM; + } + } + } + + grid[0][0].connectedToRight = TRUE; + grid[1][0].connectedToLeft = TRUE; + grid[1][0].connectedToRight = TRUE; + grid[2][0].connectedToLeft = TRUE; + grid[2][0].connectedToRight = TRUE; + grid[3][0].connectedToLeft = TRUE; + grid[3][0].connectedToRight = TRUE; + grid[4][0].connectedToLeft = TRUE; + grid[4][0].connectedToRight = TRUE; + grid[5][0].connectedToLeft = TRUE; + grid[0][0].connectedToBottom = TRUE; + grid[0][1].connectedToTop = TRUE; + grid[0][1].connectedToBottom = TRUE; + grid[0][2].connectedToTop = TRUE; + grid[0][2].connectedToBottom = TRUE; + grid[0][3].connectedToTop = TRUE; + grid[0][3].connectedToRight = TRUE; + grid[1][3].connectedToLeft = TRUE; + grid[1][3].connectedToRight = TRUE; + grid[2][3].connectedToLeft = TRUE; + grid[2][3].connectedToRight = TRUE; + grid[3][3].connectedToLeft = TRUE; + grid[3][3].connectedToRight = TRUE; + grid[4][3].connectedToLeft = TRUE; + grid[4][3].connectedToRight = TRUE; + grid[5][3].connectedToLeft = TRUE; + grid[5][0].connectedToBottom = TRUE; + grid[5][1].connectedToTop = TRUE; + grid[5][1].connectedToBottom = TRUE; + grid[5][2].connectedToTop = TRUE; + grid[5][2].connectedToBottom = TRUE; + grid[5][3].connectedToTop = TRUE; + + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); + + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + + GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } -#else -NAKED void sub_804B72C(UnkDungeonGlobal_unk1C574 *unkPtr) -{ - asm_unified("push {r4-r7,lr}\n" -" mov r7, r10\n" -" mov r6, r9\n" -" mov r5, r8\n" -" push {r5-r7}\n" -" ldr r4, _0804B9AC\n" -" add sp, r4\n" -" movs r1, 0xE5\n" -" lsls r1, 5\n" -" add r1, sp\n" -" str r0, [r1]\n" -" movs r5, 0\n" -" movs r6, 0x1\n" -" ldr r1, _0804B9B0\n" -" add r1, sp\n" -" str r5, [r1]\n" -" movs r0, 0x5\n" -" str r0, [r1, 0x4]\n" -" movs r0, 0x1C\n" -" str r0, [r1, 0xC]\n" -" movs r0, 0x33\n" -" str r0, [r1, 0x14]\n" -" movs r0, 0x38\n" -" str r0, [r1, 0x18]\n" -" movs r2, 0x10\n" -" str r2, [r1, 0x8]\n" -" movs r0, 0x27\n" -" str r0, [r1, 0x10]\n" -" ldr r1, _0804B9B4\n" -" add r1, sp\n" -" movs r0, 0x2\n" -" str r0, [r1]\n" -" movs r0, 0x7\n" -" str r0, [r1, 0x4]\n" -" str r2, [r1, 0x8]\n" -" movs r0, 0x19\n" -" str r0, [r1, 0xC]\n" -" movs r0, 0x1E\n" -" str r0, [r1, 0x10]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" bl InitDungeonGrid\n" -" mov r2, sp\n" -" adds r2, 0x3B\n" -" ldr r3, _0804B9B8\n" -" add r3, sp\n" -" str r2, [r3]\n" -" mov r4, sp\n" -" adds r4, 0x3C\n" -" ldr r0, _0804B9BC\n" -" add r0, sp\n" -" str r4, [r0]\n" -" mov r1, sp\n" -" adds r1, 0x5B\n" -" ldr r2, _0804B9C0\n" -" add r2, sp\n" -" str r1, [r2]\n" -" mov r3, sp\n" -" adds r3, 0x5C\n" -" movs r4, 0xE6\n" -" lsls r4, 5\n" -" add r4, sp\n" -" str r3, [r4]\n" -" mov r0, sp\n" -" adds r0, 0x7B\n" -" ldr r1, _0804B9C4\n" -" add r1, sp\n" -" str r0, [r1]\n" -" mov r2, sp\n" -" adds r2, 0x7E\n" -" ldr r3, _0804B9C8\n" -" add r3, sp\n" -" str r2, [r3]\n" -" add r1, sp, 0x68\n" -" add r0, sp, 0x8\n" -" movs r2, 0xF0\n" -" lsls r2, 1\n" -" movs r4, 0x6\n" -"_0804B7CC:\n" -" strb r5, [r0, 0xA]\n" -" strb r5, [r1, 0xA]\n" -" adds r1, r2\n" -" adds r0, r2\n" -" subs r4, 0x1\n" -" cmp r4, 0\n" -" bne _0804B7CC\n" -" movs r2, 0x6\n" -" subs r2, 0x1\n" -" movs r4, 0x4\n" -" cmp r4, 0\n" -" beq _0804B80C\n" -" lsls r0, r2, 4\n" -" subs r0, r2\n" -" lsls r0, 5\n" -" add r0, sp\n" -" adds r0, 0x8\n" -" add r1, sp, 0x8\n" -" ldr r3, _0804B9CC\n" -" add r3, sp\n" -" str r4, [r3]\n" -"_0804B7F6:\n" -" strb r5, [r1, 0xA]\n" -" strb r5, [r0, 0xA]\n" -" adds r0, 0x20\n" -" adds r1, 0x20\n" -" ldr r3, _0804B9CC\n" -" add r3, sp\n" -" ldr r4, [r3]\n" -" subs r4, 0x1\n" -" str r4, [r3]\n" -" cmp r4, 0\n" -" bne _0804B7F6\n" -"_0804B80C:\n" -" movs r4, 0x1\n" -" cmp r4, r2\n" -" bge _0804B848\n" -" movs r1, 0x3\n" -"_0804B814:\n" -" adds r5, r4, 0x1\n" -" mov r8, r5\n" -" cmp r1, 0x1\n" -" ble _0804B842\n" -" lsls r0, r4, 4\n" -" subs r0, r4\n" -" lsls r0, 5\n" -" add r0, sp\n" -" adds r0, 0x8\n" -" adds r0, 0x20\n" -" subs r3, r1, 0x1\n" -" ldr r4, _0804B9CC\n" -" add r4, sp\n" -" str r3, [r4]\n" -"_0804B830:\n" -" strb r6, [r0, 0xA]\n" -" adds r0, 0x20\n" -" ldr r3, _0804B9CC\n" -" add r3, sp\n" -" ldr r5, [r3]\n" -" subs r5, 0x1\n" -" str r5, [r3]\n" -" cmp r5, 0\n" -" bne _0804B830\n" -"_0804B842:\n" -" mov r4, r8\n" -" cmp r4, r2\n" -" blt _0804B814\n" -"_0804B848:\n" -" movs r4, 0\n" -" ldr r5, _0804B9D0\n" -" add r5, sp\n" -" str r4, [r5]\n" -" ldr r0, _0804B9CC\n" -" add r0, sp\n" -" str r4, [r0]\n" -" cmp r4, 0x4\n" -" blt _0804B85C\n" -" b _0804BA8C\n" -"_0804B85C:\n" -" movs r4, 0\n" -" ldr r2, _0804B9CC\n" -" add r2, sp\n" -" ldr r1, [r2]\n" -" adds r1, 0x1\n" -" ldr r2, _0804B9D4\n" -" add r2, sp\n" -" str r1, [r2]\n" -" cmp r4, 0x6\n" -" blt _0804B872\n" -" b _0804BA7A\n" -"_0804B872:\n" -" ldr r3, _0804B9B0\n" -" add r3, sp\n" -" ldr r5, _0804B9D8\n" -" add r5, sp\n" -" str r3, [r5]\n" -" ldr r0, _0804B9B4\n" -" add r0, sp\n" -" ldr r1, _0804B9DC\n" -" add r1, sp\n" -" str r0, [r1]\n" -" ldr r2, _0804B9CC\n" -" add r2, sp\n" -" ldr r2, [r2]\n" -" lsls r0, r2, 2\n" -" ldr r3, [r1]\n" -" adds r0, r3, r0\n" -" ldr r3, _0804B9E0\n" -" add r3, sp\n" -" str r0, [r3]\n" -"_0804B898:\n" -" lsls r0, r4, 4\n" -" subs r0, r4\n" -" ldr r5, _0804B9CC\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" adds r0, r5\n" -" lsls r0, 5\n" -" mov r7, sp\n" -" adds r7, r0\n" -" adds r7, 0x8\n" -" ldrb r0, [r7, 0xA]\n" -" cmp r0, 0\n" -" bne _0804B8B4\n" -" b _0804B9F4\n" -"_0804B8B4:\n" -" lsls r0, r4, 2\n" -" ldr r1, _0804B9D8\n" -" add r1, sp\n" -" ldr r1, [r1]\n" -" adds r0, r1, r0\n" -" ldr r1, [r0]\n" -" adds r2, r1, 0x2\n" -" mov r10, r2\n" -" ldr r3, _0804B9E0\n" -" add r3, sp\n" -" ldr r3, [r3]\n" -" ldr r2, [r3]\n" -" adds r5, r2, 0x2\n" -" ldr r0, _0804B9E4\n" -" add r0, sp\n" -" str r5, [r0]\n" -" adds r4, 0x1\n" -" mov r9, r4\n" -" lsls r0, r4, 2\n" -" ldr r3, _0804B9D8\n" -" add r3, sp\n" -" ldr r3, [r3]\n" -" adds r0, r3, r0\n" -" ldr r4, [r0]\n" -" subs r4, r1\n" -" subs r4, 0x3\n" -" ldr r5, _0804B9D4\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" lsls r0, r5, 2\n" -" ldr r1, _0804B9DC\n" -" add r1, sp\n" -" ldr r1, [r1]\n" -" adds r0, r1, r0\n" -" ldr r5, [r0]\n" -" subs r5, r2\n" -" subs r5, 0x3\n" -" movs r0, 0x5\n" -" adds r1, r4, 0\n" -" bl DungeonRandRange\n" -" mov r8, r0\n" -" movs r0, 0x4\n" -" adds r1, r5, 0\n" -" bl DungeonRandRange\n" -" adds r6, r0, 0\n" -" mov r2, r8\n" -" subs r4, r2\n" -" adds r0, r4, 0\n" -" bl DungeonRandInt\n" -" adds r4, r0, 0\n" -" add r4, r10\n" -" subs r5, r6\n" -" adds r0, r5, 0\n" -" bl DungeonRandInt\n" -" ldr r5, _0804B9E4\n" -" add r5, sp\n" -" ldr r3, [r5]\n" -" adds r3, r0\n" -" mov r10, r3\n" -" mov r0, r8\n" -" adds r3, r4, r0\n" -" add r6, r10\n" -" strh r4, [r7]\n" -" strh r3, [r7, 0x4]\n" -" mov r1, r10\n" -" strh r1, [r7, 0x2]\n" -" strh r6, [r7, 0x6]\n" -" mov r8, r9\n" -" ldr r5, _0804B9D0\n" -" add r5, sp\n" -" ldr r2, [r5]\n" -" adds r2, 0x1\n" -" ldr r5, _0804B9E8\n" -" add r5, sp\n" -" str r2, [r5]\n" -" cmp r4, r3\n" -" bge _0804B99E\n" -"_0804B956:\n" -" mov r5, r10\n" -" adds r7, r4, 0x1\n" -" cmp r5, r6\n" -" bge _0804B998\n" -" ldr r0, _0804B9EC\n" -" mov r9, r0\n" -"_0804B962:\n" -" adds r0, r4, 0\n" -" adds r1, r5, 0\n" -" ldr r2, _0804B9F0\n" -" add r2, sp\n" -" str r3, [r2]\n" -" bl GetTileSafe\n" -" ldrh r1, [r0]\n" -" mov r2, r9\n" -" ands r1, r2\n" -" movs r2, 0x1\n" -" orrs r1, r2\n" -" strh r1, [r0]\n" -" adds r0, r4, 0\n" -" adds r1, r5, 0\n" -" bl GetTileSafe\n" -" ldr r1, _0804B9D0\n" -" add r1, sp\n" -" ldrb r1, [r1]\n" -" strb r1, [r0, 0x9]\n" -" adds r5, 0x1\n" -" ldr r2, _0804B9F0\n" -" add r2, sp\n" -" ldr r3, [r2]\n" -" cmp r5, r6\n" -" blt _0804B962\n" -"_0804B998:\n" -" adds r4, r7, 0\n" -" cmp r4, r3\n" -" blt _0804B956\n" -"_0804B99E:\n" -" ldr r3, _0804B9E8\n" -" add r3, sp\n" -" ldr r3, [r3]\n" -" ldr r4, _0804B9D0\n" -" add r4, sp\n" -" str r3, [r4]\n" -" b _0804BA72\n" -" .align 2, 0\n" -"_0804B9AC: .4byte 0xffffe320\n" -"_0804B9B0: .4byte 0x00001c28\n" -"_0804B9B4: .4byte 0x00001c64\n" -"_0804B9B8: .4byte 0x00001cd4\n" -"_0804B9BC: .4byte 0x00001cd8\n" -"_0804B9C0: .4byte 0x00001cbc\n" -"_0804B9C4: .4byte 0x00001cc4\n" -"_0804B9C8: .4byte 0x00001cc8\n" -"_0804B9CC: .4byte 0x00001ca4\n" -"_0804B9D0: .4byte 0x00001ca8\n" -"_0804B9D4: .4byte 0x00001ccc\n" -"_0804B9D8: .4byte 0x00001cac\n" -"_0804B9DC: .4byte 0x00001cb4\n" -"_0804B9E0: .4byte 0x00001cb8\n" -"_0804B9E4: .4byte 0x00001cb0\n" -"_0804B9E8: .4byte 0x00001cd0\n" -"_0804B9EC: .4byte 0x0000fffc\n" -"_0804B9F0: .4byte 0x00001cdc\n" -"_0804B9F4:\n" -" lsls r0, r4, 2\n" -" ldr r5, _0804BBE8\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" adds r0, r5, r0\n" -" ldr r2, [r0]\n" -" adds r0, r2, 0x1\n" -" ldr r1, _0804BBEC\n" -" add r1, sp\n" -" ldr r1, [r1]\n" -" ldr r3, [r1]\n" -" adds r6, r3, 0x1\n" -" adds r4, 0x1\n" -" mov r8, r4\n" -" lsls r1, r4, 2\n" -" adds r1, r5, r1\n" -" ldr r1, [r1]\n" -" subs r1, r2\n" -" subs r1, 0x3\n" -" ldr r5, _0804BBF0\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" lsls r2, r5, 2\n" -" ldr r4, _0804BBF4\n" -" add r4, sp\n" -" ldr r4, [r4]\n" -" adds r2, r4, r2\n" -" ldr r4, [r2]\n" -" subs r4, r3\n" -" subs r4, 0x3\n" -" adds r1, r0, r1\n" -" bl DungeonRandRange\n" -" adds r5, r0, 0\n" -" adds r4, r6, r4\n" -" adds r0, r6, 0\n" -" adds r1, r4, 0\n" -" bl DungeonRandRange\n" -" adds r4, r0, 0\n" -" strh r5, [r7]\n" -" adds r0, r5, 0x1\n" -" strh r0, [r7, 0x4]\n" -" strh r4, [r7, 0x2]\n" -" adds r0, r4, 0x1\n" -" strh r0, [r7, 0x6]\n" -" adds r0, r5, 0\n" -" adds r1, r4, 0\n" -" bl GetTileSafe\n" -" ldrh r1, [r0]\n" -" ldr r3, _0804BBF8\n" -" adds r2, r3, 0\n" -" ands r1, r2\n" -" movs r2, 0x1\n" -" orrs r1, r2\n" -" strh r1, [r0]\n" -" adds r0, r5, 0\n" -" adds r1, r4, 0\n" -" bl GetTileSafe\n" -" movs r1, 0xFF\n" -" strb r1, [r0, 0x9]\n" -"_0804BA72:\n" -" mov r4, r8\n" -" cmp r4, 0x6\n" -" bge _0804BA7A\n" -" b _0804B898\n" -"_0804BA7A:\n" -" ldr r4, _0804BBF0\n" -" add r4, sp\n" -" ldr r4, [r4]\n" -" ldr r5, _0804BBFC\n" -" add r5, sp\n" -" str r4, [r5]\n" -" cmp r4, 0x4\n" -" bge _0804BA8C\n" -" b _0804B85C\n" -"_0804BA8C:\n" -" add r1, sp, 0x8\n" -" movs r6, 0\n" -" movs r0, 0x1\n" -" strb r0, [r1, 0x16]\n" -" ldr r1, _0804BC00\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" movs r1, 0xFF\n" -" lsls r1, 1\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC04\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC08\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC0C\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC10\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC14\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC18\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC1C\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" add r1, sp, 0x8\n" -" strb r0, [r1, 0x14]\n" -" ldr r5, _0804BC20\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" strb r0, [r5]\n" -" ldr r1, _0804BC24\n" -" add r1, sp\n" -" ldr r1, [r1]\n" -" strb r0, [r1]\n" -" ldr r2, _0804BC28\n" -" add r2, sp\n" -" ldr r2, [r2]\n" -" strb r0, [r2]\n" -" movs r3, 0xE6\n" -" lsls r3, 5\n" -" add r3, sp\n" -" ldr r3, [r3]\n" -" strb r0, [r3]\n" -" ldr r4, _0804BC2C\n" -" add r4, sp\n" -" ldr r4, [r4]\n" -" strb r0, [r4]\n" -" ldr r5, _0804BC30\n" -" add r5, sp\n" -" ldr r5, [r5]\n" -" strb r0, [r5]\n" -" ldr r1, _0804BC34\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC38\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC3C\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC40\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC44\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC48\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC4C\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC50\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC54\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC58\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC5C\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC60\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC64\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC68\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" ldr r1, _0804BC6C\n" -" add r1, sp\n" -" strb r0, [r1]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" movs r4, 0xE5\n" -" lsls r4, 5\n" -" add r4, sp\n" -" ldr r3, [r4]\n" -" bl AssignRandomGridCellConnections\n" -" ldr r5, _0804BC70\n" -" add r5, sp\n" -" ldr r4, _0804BC74\n" -" add r4, sp\n" -" str r4, [sp]\n" -" str r6, [sp, 0x4]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" adds r3, r5, 0\n" -" bl CreateGridCellConnections\n" -" str r4, [sp]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" adds r3, r5, 0\n" -" bl EnsureConnectedGrid\n" -" ldr r0, _0804BC78\n" -" movs r5, 0\n" -" ldrsh r3, [r0, r5]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" bl GenerateKecleonShop\n" -" ldr r0, _0804BC7C\n" -" movs r1, 0\n" -" ldrsh r3, [r0, r1]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" bl GenerateMonsterHouse\n" -" movs r2, 0xE5\n" -" lsls r2, 5\n" -" add r2, sp\n" -" ldr r2, [r2]\n" -" ldrb r3, [r2, 0x13]\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" bl GenerateExtraHallways\n" -" add r0, sp, 0x8\n" -" movs r1, 0x6\n" -" movs r2, 0x4\n" -" bl GenerateRoomImperfections\n" -" movs r3, 0xE7\n" -" lsls r3, 5\n" -" add sp, r3\n" -" pop {r3-r5}\n" -" mov r8, r3\n" -" mov r9, r4\n" -" mov r10, r5\n" -" pop {r4-r7}\n" -" pop {r0}\n" -" bx r0\n" -" .align 2, 0\n" -"_0804BBE8: .4byte 0x00001cac\n" -"_0804BBEC: .4byte 0x00001cb8\n" -"_0804BBF0: .4byte 0x00001ccc\n" -"_0804BBF4: .4byte 0x00001cb4\n" -"_0804BBF8: .4byte 0x0000fffc\n" -"_0804BBFC: .4byte 0x00001ca4\n" -"_0804BC00: .4byte 0x000001fd\n" -"_0804BC04: .4byte 0x000003dd\n" -"_0804BC08: .4byte 0x000003de\n" -"_0804BC0C: .4byte 0x000005bd\n" -"_0804BC10: .4byte 0x000005be\n" -"_0804BC14: .4byte 0x0000079d\n" -"_0804BC18: .4byte 0x0000079e\n" -"_0804BC1C: .4byte 0x0000097d\n" -"_0804BC20: .4byte 0x00001cd4\n" -"_0804BC24: .4byte 0x00001cd8\n" -"_0804BC28: .4byte 0x00001cbc\n" -"_0804BC2C: .4byte 0x00001cc4\n" -"_0804BC30: .4byte 0x00001cc8\n" -"_0804BC34: .4byte 0x0000025d\n" -"_0804BC38: .4byte 0x0000025e\n" -"_0804BC3C: .4byte 0x0000043d\n" -"_0804BC40: .4byte 0x0000043e\n" -"_0804BC44: .4byte 0x0000061d\n" -"_0804BC48: .4byte 0x0000061e\n" -"_0804BC4C: .4byte 0x000007fd\n" -"_0804BC50: .4byte 0x000007fe\n" -"_0804BC54: .4byte 0x000009dd\n" -"_0804BC58: .4byte 0x0000097c\n" -"_0804BC5C: .4byte 0x0000099b\n" -"_0804BC60: .4byte 0x0000099c\n" -"_0804BC64: .4byte 0x000009bb\n" -"_0804BC68: .4byte 0x000009bc\n" -"_0804BC6C: .4byte 0x000009db\n" -"_0804BC70: .4byte 0x00001c28\n" -"_0804BC74: .4byte 0x00001c64\n" -"_0804BC78: .4byte gUnknown_202F1B0\n" -"_0804BC7C: .4byte gUnknown_202F1B2"); -} -#endif // NONMATCHING /* * GenerateCrossroadsFloor - Generates a floor layout with hallways on the inside and rooms on the outside, with empty corners. - * * Also nicknamed "Ladder Layout" by some. */ void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *unkPtr) @@ -1807,12 +1295,12 @@ void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *unkPtr) s32 rangeX = listX[x + 1] - listX[x] - 3; s32 rangeY = listY[y + 1] - listY[y] - 3; - s32 room_size_x = DungeonRandRange(5, rangeX); - s32 room_size_y = DungeonRandRange(4, rangeY); - s32 startX = DungeonRandInt(rangeX - room_size_x) + minX; - s32 startY = DungeonRandInt(rangeY - room_size_y) + minY; - s32 endX = startX + room_size_x; - s32 endY = startY + room_size_y; + s32 roomSizeX = DungeonRandRange(5, rangeX); + s32 roomSizeY = DungeonRandRange(4, rangeY); + s32 startX = DungeonRandInt(rangeX - roomSizeX) + minX; + s32 startY = DungeonRandInt(rangeY - roomSizeY) + minY; + s32 endX = startX + roomSizeX; + s32 endY = startY + roomSizeY; grid[x][y].start.x = startX; grid[x][y].end.x = endX; From 3eec797b8507956518e5372ba18647180b36b322 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 10 Nov 2024 15:18:00 +0100 Subject: [PATCH 09/30] AssignGridCellConnections --- asm/code_804AFAC.s | 413 ------------------------------------------- src/code_804AFAC_1.c | 273 ++++++++++++++++++++++++++-- 2 files changed, 258 insertions(+), 428 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index a651805c4..62fe24223 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -5,419 +5,6 @@ .text - - thumb_func_start AssignGridCellConnections -AssignGridCellConnections: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - adds r7, r3, 0 - ldr r6, [sp, 0x40] - ldr r0, [sp, 0x44] - ldrb r0, [r0, 0x5] - str r0, [sp, 0xC] - movs r0, 0x4 - bl DungeonRandInt - adds r5, r0, 0 - movs r1, 0 - mov r10, r1 - ldr r2, [sp, 0xC] - cmp r10, r2 - blt _0804D620 - b _0804D726 -_0804D620: - lsls r4, r6, 5 - mov r9, r4 - lsls r0, r7, 4 - subs r0, r7 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - mov r8, r0 -_0804D630: - movs r0, 0x8 - bl DungeonRandInt - adds r4, r0, 0 - movs r0, 0x4 - bl DungeonRandInt - cmp r4, 0x3 - bgt _0804D644 - adds r5, r0, 0 -_0804D644: - mov r4, r10 - adds r4, 0x1 -_0804D648: - movs r1, 0 - movs r0, 0x3 - ands r0, r5 - cmp r0, 0x1 - beq _0804D670 - cmp r0, 0x1 - bgt _0804D65C - cmp r0, 0 - beq _0804D666 - b _0804D686 -_0804D65C: - cmp r0, 0x2 - beq _0804D676 - cmp r0, 0x3 - beq _0804D67C - b _0804D686 -_0804D666: - ldr r0, [sp, 0x4] - subs r0, 0x1 - cmp r7, r0 - blt _0804D68A - b _0804D684 -_0804D670: - cmp r6, 0 - bgt _0804D68A - b _0804D684 -_0804D676: - cmp r7, 0 - bgt _0804D68A - b _0804D684 -_0804D67C: - ldr r0, [sp, 0x8] - subs r0, 0x1 - cmp r6, r0 - blt _0804D68A -_0804D684: - adds r5, 0x1 -_0804D686: - cmp r1, 0 - beq _0804D648 -_0804D68A: - movs r1, 0x3 - ands r1, r5 - cmp r1, 0x1 - beq _0804D6C6 - cmp r1, 0x1 - bgt _0804D69C - cmp r1, 0 - beq _0804D6A6 - b _0804D71E -_0804D69C: - cmp r1, 0x2 - beq _0804D6E2 - cmp r1, 0x3 - beq _0804D704 - b _0804D71E -_0804D6A6: - mov r1, r9 - add r1, r8 - movs r0, 0xF0 - lsls r0, 1 - adds r2, r1, r0 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D71E - movs r0, 0x1 - strb r0, [r1, 0x16] - strb r0, [r2, 0x15] - movs r1, 0xF0 - lsls r1, 1 - add r8, r1 - adds r7, 0x1 - b _0804D71E -_0804D6C6: - mov r2, r9 - add r2, r8 - adds r3, r2, 0 - subs r3, 0x20 - ldrb r0, [r3, 0x8] - cmp r0, 0 - bne _0804D71E - strb r1, [r2, 0x13] - strb r1, [r3, 0x14] - movs r2, 0x20 - negs r2, r2 - add r9, r2 - subs r6, 0x1 - b _0804D71E -_0804D6E2: - mov r1, r9 - add r1, r8 - ldr r0, _0804D700 - adds r2, r1, r0 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D71E - movs r0, 0x1 - strb r0, [r1, 0x15] - strb r0, [r2, 0x16] - ldr r1, _0804D700 - add r8, r1 - subs r7, 0x1 - b _0804D71E - .align 2, 0 -_0804D700: .4byte 0xfffffe20 -_0804D704: - mov r1, r9 - add r1, r8 - adds r2, r1, 0 - adds r2, 0x20 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D71E - movs r0, 0x1 - strb r0, [r1, 0x14] - strb r0, [r2, 0x13] - movs r1, 0x20 - add r9, r1 - adds r6, 0x1 -_0804D71E: - mov r10, r4 - ldr r2, [sp, 0xC] - cmp r10, r2 - blt _0804D630 -_0804D726: - ldr r4, [sp, 0x44] - ldrb r0, [r4, 0xB] - cmp r0, 0 - beq _0804D730 - b _0804D8B8 -_0804D730: - movs r0, 0 - mov r9, r0 - movs r7, 0 - ldr r1, [sp, 0x4] - cmp r9, r1 - blt _0804D73E - b _0804D8B0 -_0804D73E: - movs r2, 0x1 - mov r8, r2 -_0804D742: - movs r6, 0 - adds r4, r7, 0x1 - str r4, [sp, 0x14] - ldr r0, [sp, 0x8] - cmp r6, r0 - blt _0804D750 - b _0804D8A6 -_0804D750: - lsls r1, r7, 4 - str r1, [sp, 0x10] - subs r0, r1, r7 - lsls r0, 5 - ldr r2, [sp] - adds r3, r0, r2 -_0804D75C: - lsls r0, r6, 5 - adds r2, r0, r3 - ldrb r1, [r2, 0x8] - adds r4, r0, 0 - adds r0, r6, 0x1 - str r0, [sp, 0x18] - cmp r1, 0 - beq _0804D76E - b _0804D89C -_0804D76E: - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804D776 - b _0804D89C -_0804D776: - ldrb r0, [r2, 0x13] - negs r1, r0 - orrs r1, r0 - lsrs r1, 31 - ldrb r0, [r2, 0x14] - cmp r0, 0 - beq _0804D786 - adds r1, 0x1 -_0804D786: - ldrb r0, [r2, 0x15] - cmp r0, 0 - beq _0804D78E - adds r1, 0x1 -_0804D78E: - ldrb r0, [r2, 0x16] - cmp r0, 0 - beq _0804D796 - adds r1, 0x1 -_0804D796: - cmp r1, 0x1 - beq _0804D79C - b _0804D89C -_0804D79C: - movs r0, 0x4 - str r3, [sp, 0x1C] - bl DungeonRandInt - adds r5, r0, 0 - movs r2, 0 - mov r10, r2 - ldr r1, [sp, 0x10] - subs r0, r1, r7 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - adds r1, r4, r0 - ldr r3, [sp, 0x1C] -_0804D7B8: - movs r0, 0x3 - ands r0, r5 - cmp r0, 0x1 - beq _0804D7E0 - cmp r0, 0x1 - bgt _0804D7CA - cmp r0, 0 - beq _0804D7D4 - b _0804D800 -_0804D7CA: - cmp r0, 0x2 - beq _0804D7E8 - cmp r0, 0x3 - beq _0804D7F0 - b _0804D800 -_0804D7D4: - ldr r0, [sp, 0x4] - subs r0, 0x1 - cmp r7, r0 - bge _0804D7FE - ldrb r0, [r1, 0x16] - b _0804D7FA -_0804D7E0: - cmp r6, 0 - ble _0804D7FE - ldrb r0, [r1, 0x13] - b _0804D7FA -_0804D7E8: - cmp r7, 0 - ble _0804D7FE - ldrb r0, [r1, 0x15] - b _0804D7FA -_0804D7F0: - ldr r0, [sp, 0x8] - subs r0, 0x1 - cmp r6, r0 - bge _0804D7FE - ldrb r0, [r1, 0x14] -_0804D7FA: - cmp r0, 0 - beq _0804D80E -_0804D7FE: - adds r5, 0x1 -_0804D800: - mov r0, r10 - cmp r0, 0 - bne _0804D80E - adds r2, 0x1 - cmp r2, 0x7 - ble _0804D7B8 - b _0804D89C -_0804D80E: - movs r2, 0x3 - ands r2, r5 - cmp r2, 0x1 - beq _0804D844 - cmp r2, 0x1 - bgt _0804D820 - cmp r2, 0 - beq _0804D82A - b _0804D89C -_0804D820: - cmp r2, 0x2 - beq _0804D85C - cmp r2, 0x3 - beq _0804D880 - b _0804D89C -_0804D82A: - adds r1, r4, r3 - movs r4, 0xF0 - lsls r4, 1 - adds r2, r1, r4 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D89C - mov r0, r8 - strb r0, [r1, 0x16] - strb r0, [r2, 0x15] - movs r1, 0x1 - mov r9, r1 - b _0804D89C -_0804D844: - adds r1, r4, r3 - movs r4, 0xF0 - lsls r4, 1 - adds r0, r1, r4 - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _0804D89C - strb r2, [r1, 0x13] - adds r0, r1, 0 - subs r0, 0x20 - strb r2, [r0, 0x14] - b _0804D898 -_0804D85C: - adds r1, r4, r3 - movs r2, 0xF0 - lsls r2, 1 - adds r0, r1, r2 - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _0804D89C - mov r4, r8 - strb r4, [r1, 0x15] - ldr r2, _0804D87C - adds r0, r1, r2 - strb r4, [r0, 0x16] - movs r4, 0x1 - mov r9, r4 - b _0804D89C - .align 2, 0 -_0804D87C: .4byte 0xfffffe20 -_0804D880: - adds r1, r4, r3 - movs r2, 0xF0 - lsls r2, 1 - adds r0, r1, r2 - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _0804D89C - mov r4, r8 - strb r4, [r1, 0x14] - adds r0, r1, 0 - adds r0, 0x20 - strb r4, [r0, 0x13] -_0804D898: - movs r0, 0x1 - mov r9, r0 -_0804D89C: - ldr r6, [sp, 0x18] - ldr r1, [sp, 0x8] - cmp r6, r1 - bge _0804D8A6 - b _0804D75C -_0804D8A6: - ldr r7, [sp, 0x14] - ldr r2, [sp, 0x4] - cmp r7, r2 - bge _0804D8B0 - b _0804D742 -_0804D8B0: - mov r4, r9 - cmp r4, 0 - beq _0804D8B8 - b _0804D730 -_0804D8B8: - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end AssignGridCellConnections - thumb_func_start CreateGridCellConnections CreateGridCellConnections: push {r4-r7,lr} diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 377f9df2e..d12626ca0 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -1023,6 +1023,10 @@ struct GridCell #define GRID_CELL_LEN 15 +void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); +void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 x2, s32 y2); +void sub_8051438(struct GridCell *cell, s32 a1); +extern void sub_8051288(s32 a0); void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); @@ -1615,15 +1619,12 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } -void sub_804C790(s32 x1, s32 y1, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); -extern void sub_8051288(s32 a0); - bool8 sub_804C70C(s32 a0, UnkDungeonGlobal_unk1C574 *unkPtr) { struct FileFixedmapPosStruct **fileData = (void *) gDungeon->unk13568->data; s32 x1 = fileData[a0]->x; s32 y1 = fileData[a0]->y; - s32 x2, y2; + s32 gridSizeX, gridSizeY; if (x1 == 0 || y1 == 0) { GenerateOneRoomMonsterHouseFloor(); @@ -1634,20 +1635,17 @@ bool8 sub_804C70C(s32 a0, UnkDungeonGlobal_unk1C574 *unkPtr) return TRUE; } else { - x2 = DUNGEON_MAX_SIZE_X / (x1 + 4); - if (x2 <= 1) - x2 = 1; - y2 = DUNGEON_MAX_SIZE_Y / (y1 + 4); - if (y2 <= 1) - y2 = 1; - sub_804C790(x2, y2, x1, y1, a0, unkPtr); + gridSizeX = DUNGEON_MAX_SIZE_X / (x1 + 4); + if (gridSizeX <= 1) + gridSizeX = 1; + gridSizeY = DUNGEON_MAX_SIZE_Y / (y1 + 4); + if (gridSizeY <= 1) + gridSizeY = 1; + sub_804C790(gridSizeX, gridSizeY, x1, y1, a0, unkPtr); return FALSE; } } -void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 x1, s32 y1, s32 *a3, s32 *a4, s32 a5, s32 x2, s32 y2); -void sub_8051438(struct GridCell *cell, s32 a1); - void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr) { s32 tries; @@ -1684,7 +1682,7 @@ void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeo /* * GenerateOneRoomMonsterHouseFloor - Generates a floor layout with just one large room which is a Monster House. - * This generator is used as a fallback in the event generation fails too many times. + * This generator is used as a fallback if the event generation fails too many times. */ void GenerateOneRoomMonsterHouseFloor(void) { @@ -2338,4 +2336,249 @@ static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][ AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, unkPtr); } + +/* + * AssignGridCellConnections - Responsible for assigning connections to randomly adjacent grid cells + * + * Connections begin from the grid cell at (cursorX, cursorY), and are created using a + * random walk with momentum. + * + * There's a 50% chance it will continue in the same direction, otherwise it will be assigned a new random direction. + * If the direction traveled runs into the border of the map, the direction turns counterclockwise. + * If the direction walks towards an invalid grid tile, nothing happens and iteration continues. + * + * The random walk will be repeated floorConnectivity number of times (specified in FloorProperties) + * + * Once finished, if dead ends are disabled, an additional phase occurs to remove dead end hallway anchors (not rooms) + * The original implementation contains a bug when applying new connections to these rooms, where the incorrect + * grid cell index will be checked for validity (always the grid cell to the right), so some connections may go to + * invalid tiles or not be applied to valid ones. + * + */ + +enum CardinalDirection +{ + CARDINAL_DIR_RIGHT, + CARDINAL_DIR_UP, + CARDINAL_DIR_LEFT, + CARDINAL_DIR_DOWN, + NUM_CARDINAL_DIRECTIONS +}; + +#define CARDINAL_DIRECTION_MASK 3 + +void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + s32 i; + s32 x = cursorX; + s32 y = cursorY; + s32 floorConnectivity = unkPtr->unk5; + // Draw a random connection direction. + // Connect the current cell with the cell to the: + // 0: east + // 1: north + // 2: west + // 3: south + s32 cardinalDirection = DungeonRandInt(NUM_CARDINAL_DIRECTIONS); + + // Try to connect the current cell to another grid cell, repeat based on floorConnectivity + for (i = 0; i < floorConnectivity; i++) { + // Keep moving in the same cardinalDirection with probability 1/2 ("momentum" to connect in a straight line) + // Less forks and less doubling back + s32 test = DungeonRandInt(NUM_CARDINAL_DIRECTIONS * 2); + s32 newDirection = DungeonRandInt(NUM_CARDINAL_DIRECTIONS); + + if (test < NUM_CARDINAL_DIRECTIONS) { + // Shuffle to a new cardinalDirection + cardinalDirection = newDirection; + } + + // Make sure our cardinalDirection isn't going into a border + // If so, rotate counterclockwise + while (1) { + bool8 notOk = FALSE; + switch (cardinalDirection & CARDINAL_DIRECTION_MASK) { + case CARDINAL_DIR_RIGHT: + if (x < gridSizeX - 1) + notOk = TRUE; + else + cardinalDirection++; + break; + case CARDINAL_DIR_UP: + if (y > 0) + notOk = TRUE; + else + cardinalDirection++; + break; + case CARDINAL_DIR_LEFT: + if (x > 0) + notOk = TRUE; + else + cardinalDirection++; + break; + case CARDINAL_DIR_DOWN: + if (y < gridSizeY - 1) + notOk = TRUE; + else + cardinalDirection++; + break; + } + + if (notOk) + break; + } + + // Set the connection, then move in that cardinalDirection + switch (cardinalDirection & CARDINAL_DIRECTION_MASK) { + case CARDINAL_DIR_RIGHT: + if (!grid[x + 1][y].isInvalid) { + grid[x][y].connectedToRight = TRUE; + grid[x + 1][y].connectedToLeft = TRUE; + + x++; + } + break; + case CARDINAL_DIR_UP: + if (!grid[x][y - 1].isInvalid) { + grid[x][y].connectedToTop = TRUE; + grid[x][y - 1].connectedToBottom = TRUE; + + y--; + } + break; + case CARDINAL_DIR_LEFT: + if (!grid[x - 1][y].isInvalid) { + grid[x][y].connectedToLeft = TRUE; + grid[x - 1][y].connectedToRight = TRUE; + + x--; + } + break; + case CARDINAL_DIR_DOWN: + if (!grid[x][y + 1].isInvalid) { + grid[x][y].connectedToBottom = TRUE; + grid[x][y + 1].connectedToTop = TRUE; + + y++; + } + break; + } + } + + if (unkPtr->unkB) + return; + + // No dead ends, add some extra connections! + while (1) { + bool8 more = FALSE; + + // Locate potential dead ends + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + if (grid[x][y].isInvalid) + continue; + if (!grid[x][y].isRoom) + { + // Find which cardinalDirections this tile is connected in + s32 countConnect = 0; + + if (grid[x][y].connectedToTop) countConnect++; + if (grid[x][y].connectedToBottom) countConnect++; + if (grid[x][y].connectedToLeft) countConnect++; + if (grid[x][y].connectedToRight) countConnect++; + + if (countConnect == 1) { + s32 i; + bool8 ok; + + // This tile has only one connection, it's a dead end + // Connect it to a random other cell to remove the dead end + + cardinalDirection = DungeonRandInt(NUM_CARDINAL_DIRECTIONS); + + for (i = 0, ok = FALSE; i < 8; i++) { + switch (cardinalDirection & CARDINAL_DIRECTION_MASK) { + case CARDINAL_DIR_RIGHT: + if (x < gridSizeX - 1 && !grid[x][y].connectedToRight) + ok = TRUE; + else + cardinalDirection++; + break; + case CARDINAL_DIR_UP: + if (y > 0 && !grid[x][y].connectedToTop) + ok = TRUE; + else + cardinalDirection++; + break; + case CARDINAL_DIR_LEFT: + if (x > 0 && !grid[x][y].connectedToLeft) + ok = TRUE; + else + cardinalDirection++; + break; + case CARDINAL_DIR_DOWN: + if (y < gridSizeY - 1 && !grid[x][y].connectedToBottom) + ok = TRUE; + else + cardinalDirection++; + break; + } + + // Once we find a successful cardinalDirection, stop + if (ok) + break; + } + + // We couldn't find any successful cardinalDirection, give up. + if (!ok) + continue; + + // This section retains the original functionality + switch (cardinalDirection & CARDINAL_DIRECTION_MASK) { + case CARDINAL_DIR_RIGHT: + if (!grid[x + 1][y].isInvalid) { + grid[x][y].connectedToRight = TRUE; + grid[x + 1][y].connectedToLeft = TRUE; + + more = TRUE; + } + break; + // BUG: the wrong grid index is used for the validity check + case CARDINAL_DIR_UP: + if (!grid[x + 1][y].isInvalid) { + grid[x][y].connectedToTop = TRUE; + grid[x][y - 1].connectedToBottom = TRUE; + + more = TRUE; + } + break; + // BUG: the wrong grid index is used for the validity check + case CARDINAL_DIR_LEFT: + if (!grid[x + 1][y].isInvalid) { + grid[x][y].connectedToLeft = TRUE; + grid[x - 1][y].connectedToRight = TRUE; + + more = TRUE; + } + break; + // BUG: the wrong grid index is used for the validity check + case CARDINAL_DIR_DOWN: + if (!grid[x + 1][y].isInvalid) { + grid[x][y].connectedToBottom = TRUE; + grid[x][y + 1].connectedToTop = TRUE; + + more = TRUE; + } + break; + } + } + } + } + } + + if (!more) + break; + } +} + // From 05c4525ad38b6d65fcc0261e2d3cbe88c8e30839 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 11 Nov 2024 11:21:40 +0100 Subject: [PATCH 10/30] CreateGridCellConnections --- asm/code_804AFAC.s | 1045 +----------------------------------------- src/code_804AFAC_1.c | 402 +++++++++++++++- 2 files changed, 399 insertions(+), 1048 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 62fe24223..e54657da0 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -5,1037 +5,6 @@ .text - thumb_func_start CreateGridCellConnections -CreateGridCellConnections: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x58 - str r0, [sp, 0xC] - str r1, [sp, 0x10] - str r2, [sp, 0x14] - str r3, [sp, 0x18] - ldr r0, [sp, 0x7C] - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x1C] - movs r0, 0 - str r0, [sp, 0x20] - cmp r0, r1 - bge _0804D968 -_0804D8EC: - movs r1, 0 - mov r10, r1 - ldr r2, [sp, 0x20] - adds r2, 0x1 - str r2, [sp, 0x38] - ldr r3, [sp, 0x14] - cmp r10, r3 - bge _0804D95E - ldr r4, [sp, 0x20] - lsls r1, r4, 4 - subs r1, r4 - movs r3, 0 - lsls r1, 5 - ldr r0, [sp, 0xC] - adds r0, 0x8 - adds r1, r0 -_0804D90C: - ldrb r2, [r1] - cmp r2, 0 - beq _0804D91C - strb r3, [r1, 0xF] - strb r3, [r1, 0x10] - strb r3, [r1, 0x11] - strb r3, [r1, 0x12] - b _0804D952 -_0804D91C: - ldr r5, [sp, 0x20] - cmp r5, 0 - bgt _0804D924 - strb r2, [r1, 0xD] -_0804D924: - mov r6, r10 - cmp r6, 0 - bgt _0804D92C - strb r2, [r1, 0xB] -_0804D92C: - ldr r0, [sp, 0x10] - subs r0, 0x1 - ldr r7, [sp, 0x20] - cmp r7, r0 - blt _0804D938 - strb r2, [r1, 0xE] -_0804D938: - ldr r0, [sp, 0x14] - subs r0, 0x1 - cmp r10, r0 - blt _0804D942 - strb r2, [r1, 0xC] -_0804D942: - ldrb r0, [r1, 0xB] - strb r0, [r1, 0xF] - ldrb r0, [r1, 0xC] - strb r0, [r1, 0x10] - ldrb r0, [r1, 0xD] - strb r0, [r1, 0x11] - ldrb r0, [r1, 0xE] - strb r0, [r1, 0x12] -_0804D952: - adds r1, 0x20 - movs r0, 0x1 - add r10, r0 - ldr r2, [sp, 0x14] - cmp r10, r2 - blt _0804D90C -_0804D95E: - ldr r3, [sp, 0x38] - str r3, [sp, 0x20] - ldr r4, [sp, 0x10] - cmp r3, r4 - blt _0804D8EC -_0804D968: - movs r5, 0 - str r5, [sp, 0x20] - ldr r6, [sp, 0x10] - cmp r5, r6 - blt _0804D974 - b _0804DBC6 -_0804D974: - movs r7, 0 - mov r10, r7 - ldr r0, [sp, 0x20] - adds r0, 0x1 - str r0, [sp, 0x38] - ldr r1, [sp, 0x14] - cmp r10, r1 - blt _0804D986 - b _0804DBBA -_0804D986: - ldr r2, [sp, 0x20] - lsls r2, 4 - str r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r1, r2, r3 - lsls r1, 5 - movs r4, 0 - str r4, [sp, 0x48] - ldr r5, [sp, 0xC] - movs r6, 0xF0 - lsls r6, 1 - adds r0, r5, r6 - adds r0, r1 - mov r8, r0 - adds r5, r1, r5 - ldr r7, [sp, 0xC] - ldr r2, _0804DA0C - adds r0, r7, r2 - adds r7, r1, r0 - ldr r3, [sp, 0x78] - str r3, [sp, 0x4C] - ldr r0, [sp, 0xC] - adds r0, 0x20 - adds r0, r1, r0 - str r0, [sp, 0x50] - ldr r0, [sp, 0xC] - subs r0, 0x20 - adds r6, r1, r0 - ldr r4, [sp, 0x20] - lsls r0, r4, 2 - ldr r1, [sp, 0x18] - adds r0, r1 - str r0, [sp, 0x24] -_0804D9C8: - ldr r2, [sp, 0x20] - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - ldr r3, [sp, 0xC] - adds r0, r3 - ldr r1, [sp, 0x48] - adds r4, r1, r0 - ldrb r0, [r4, 0x8] - cmp r0, 0 - beq _0804D9E0 - b _0804DB92 -_0804D9E0: - ldrb r0, [r4, 0xA] - cmp r0, 0 - beq _0804DA10 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r0, 0x1 - movs r3, 0x4 - ldrsh r1, [r4, r3] - subs r1, 0x1 - bl DungeonRandRange - mov r9, r0 - movs r1, 0x2 - ldrsh r0, [r4, r1] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r4, r0, 0 - b _0804DA1A - .align 2, 0 -_0804DA0C: .4byte 0xfffffe20 -_0804DA10: - movs r0, 0 - ldrsh r3, [r4, r0] - mov r9, r3 - movs r1, 0x2 - ldrsh r4, [r4, r1] -_0804DA1A: - ldrb r0, [r5, 0x17] - cmp r0, 0 - beq _0804DA74 - ldrb r0, [r6, 0x8] - cmp r0, 0 - bne _0804DA68 - ldrb r0, [r6, 0xA] - cmp r0, 0 - beq _0804DA40 - movs r2, 0 - ldrsh r0, [r6, r2] - adds r0, 0x1 - movs r3, 0x4 - ldrsh r1, [r6, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r2, r0, 0 - b _0804DA44 -_0804DA40: - movs r0, 0 - ldrsh r2, [r6, r0] -_0804DA44: - movs r3, 0x2 - ldrsh r1, [r5, r3] - movs r0, 0x6 - ldrsh r3, [r6, r0] - subs r3, 0x1 - mov r12, r3 - movs r3, 0x1 - str r3, [sp] - ldr r3, [sp, 0x24] - ldr r0, [r3] - str r0, [sp, 0x4] - ldr r3, [sp, 0x4C] - ldr r0, [r3] - str r0, [sp, 0x8] - mov r0, r9 - mov r3, r12 - bl sub_804E328 -_0804DA68: - movs r0, 0 - strb r0, [r5, 0x17] - strb r0, [r6, 0x18] - movs r1, 0x1 - strb r1, [r5, 0xB] - strb r1, [r6, 0xB] -_0804DA74: - ldrb r0, [r5, 0x18] - cmp r0, 0 - beq _0804DAD4 - ldr r2, [sp, 0x50] - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804DAC6 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804DA9C - movs r3, 0x20 - ldrsh r0, [r5, r3] - adds r0, 0x1 - movs r2, 0x24 - ldrsh r1, [r5, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r2, r0, 0 - b _0804DAA0 -_0804DA9C: - movs r3, 0x20 - ldrsh r2, [r5, r3] -_0804DAA0: - movs r0, 0x6 - ldrsh r1, [r5, r0] - subs r1, 0x1 - movs r0, 0x22 - ldrsh r3, [r5, r0] - mov r12, r3 - movs r3, 0x1 - str r3, [sp] - ldr r3, [sp, 0x24] - ldr r0, [r3] - str r0, [sp, 0x4] - ldr r3, [sp, 0x4C] - ldr r0, [r3, 0x4] - subs r0, 0x1 - str r0, [sp, 0x8] - mov r0, r9 - mov r3, r12 - bl sub_804E328 -_0804DAC6: - movs r0, 0 - strb r0, [r5, 0x18] - ldr r1, [sp, 0x50] - strb r0, [r1, 0x17] - movs r2, 0x1 - strb r2, [r5, 0xB] - strb r2, [r1, 0xB] -_0804DAD4: - ldrb r0, [r5, 0x19] - cmp r0, 0 - beq _0804DB2E - ldrb r0, [r7, 0x8] - cmp r0, 0 - bne _0804DB22 - ldrb r0, [r7, 0xA] - cmp r0, 0 - beq _0804DAFA - movs r3, 0x2 - ldrsh r0, [r7, r3] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r7, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804DAFE -_0804DAFA: - movs r0, 0x2 - ldrsh r3, [r7, r0] -_0804DAFE: - movs r1, 0 - ldrsh r0, [r5, r1] - movs r1, 0 - ldrsh r2, [r7, r1] - subs r2, 0x1 - mov r9, r2 - movs r2, 0 - str r2, [sp] - ldr r2, [sp, 0x24] - ldr r1, [r2] - str r1, [sp, 0x4] - ldr r2, [sp, 0x4C] - ldr r1, [r2] - str r1, [sp, 0x8] - adds r1, r4, 0 - mov r2, r9 - bl sub_804E328 -_0804DB22: - movs r3, 0 - strb r3, [r5, 0x19] - strb r3, [r7, 0x1A] - movs r0, 0x1 - strb r0, [r5, 0xB] - strb r0, [r7, 0xB] -_0804DB2E: - ldrb r0, [r5, 0x1A] - cmp r0, 0 - beq _0804DB92 - mov r1, r8 - ldrb r0, [r1, 0x8] - cmp r0, 0 - bne _0804DB84 - ldrb r0, [r1, 0xA] - cmp r0, 0 - beq _0804DB56 - movs r2, 0x2 - ldrsh r0, [r1, r2] - adds r0, 0x1 - movs r3, 0x6 - ldrsh r1, [r1, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804DB5C -_0804DB56: - mov r0, r8 - movs r1, 0x2 - ldrsh r3, [r0, r1] -_0804DB5C: - movs r2, 0x4 - ldrsh r0, [r5, r2] - subs r0, 0x1 - mov r1, r8 - movs r2, 0 - ldrsh r1, [r1, r2] - mov r9, r1 - movs r1, 0 - str r1, [sp] - ldr r2, [sp, 0x24] - ldr r1, [r2, 0x4] - subs r1, 0x1 - str r1, [sp, 0x4] - ldr r2, [sp, 0x4C] - ldr r1, [r2] - str r1, [sp, 0x8] - adds r1, r4, 0 - mov r2, r9 - bl sub_804E328 -_0804DB84: - movs r3, 0 - strb r3, [r5, 0x1A] - mov r4, r8 - strb r3, [r4, 0x19] - movs r0, 0x1 - strb r0, [r5, 0xB] - strb r0, [r4, 0xB] -_0804DB92: - ldr r1, [sp, 0x48] - adds r1, 0x20 - str r1, [sp, 0x48] - movs r2, 0x20 - add r8, r2 - adds r5, 0x20 - adds r7, 0x20 - ldr r3, [sp, 0x4C] - adds r3, 0x4 - str r3, [sp, 0x4C] - ldr r4, [sp, 0x50] - adds r4, 0x20 - str r4, [sp, 0x50] - adds r6, 0x20 - movs r0, 0x1 - add r10, r0 - ldr r1, [sp, 0x14] - cmp r10, r1 - bge _0804DBBA - b _0804D9C8 -_0804DBBA: - ldr r2, [sp, 0x38] - str r2, [sp, 0x20] - ldr r3, [sp, 0x10] - cmp r2, r3 - bge _0804DBC6 - b _0804D974 -_0804DBC6: - ldr r4, [sp, 0x1C] - cmp r4, 0 - beq _0804DBCE - b _0804E026 -_0804DBCE: - movs r5, 0 - str r5, [sp, 0x20] - ldr r6, [sp, 0x10] - cmp r5, r6 - blt _0804DBDA - b _0804E026 -_0804DBDA: - movs r7, 0 - mov r10, r7 - ldr r0, [sp, 0x20] - adds r0, 0x1 - str r0, [sp, 0x38] - ldr r1, [sp, 0x14] - cmp r10, r1 - blt _0804DBEC - b _0804E018 -_0804DBEC: - movs r0, 0x64 - bl DungeonRandInt - mov r2, r10 - adds r2, 0x1 - str r2, [sp, 0x3C] - cmp r0, 0x4 - ble _0804DBFE - b _0804E00C -_0804DBFE: - mov r3, r10 - lsls r1, r3, 5 - ldr r4, [sp, 0x20] - lsls r2, r4, 4 - subs r0, r2, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - adds r4, r1, r0 - ldrb r0, [r4, 0x8] - str r1, [sp, 0x44] - str r2, [sp, 0x40] - cmp r0, 0 - beq _0804DC1C - b _0804E00C -_0804DC1C: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _0804DC24 - b _0804E00C -_0804DC24: - ldrb r0, [r4, 0x12] - cmp r0, 0 - beq _0804DC2C - b _0804E00C -_0804DC2C: - ldrb r0, [r4, 0x9] - cmp r0, 0 - beq _0804DC34 - b _0804E00C -_0804DC34: - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804DC3C - b _0804E00C -_0804DC3C: - movs r0, 0x4 - bl DungeonRandInt - cmp r0, 0x1 - bne _0804DC48 - b _0804DD50 -_0804DC48: - cmp r0, 0x1 - bgt _0804DC52 - cmp r0, 0 - beq _0804DC60 - b _0804E00C -_0804DC52: - cmp r0, 0x2 - bne _0804DC58 - b _0804DE3C -_0804DC58: - cmp r0, 0x3 - bne _0804DC5E - b _0804DF30 -_0804DC5E: - b _0804E00C -_0804DC60: - ldr r6, [sp, 0x20] - cmp r6, 0 - bgt _0804DC68 - b _0804E00C -_0804DC68: - ldr r7, _0804DD48 - adds r2, r4, r7 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DC74 - b _0804E00C -_0804DC74: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DC7C - b _0804E00C -_0804DC7C: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DC84 - b _0804E00C -_0804DC84: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DC8C - b _0804E00C -_0804DC8C: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DC94 - b _0804E00C -_0804DC94: - movs r1, 0 - ldrsh r0, [r2, r1] - str r0, [sp, 0x28] - ldrh r3, [r4, 0x2] - movs r5, 0x2 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x2] - movs r6, 0x2 - ldrsh r0, [r2, r6] - cmp r1, r0 - ble _0804DCAC - adds r3, r5, 0 -_0804DCAC: - lsls r0, r3, 16 - asrs r0, 16 - mov r9, r0 - movs r0, 0x4 - ldrsh r7, [r4, r0] - mov r10, r7 - ldrh r3, [r4, 0x6] - movs r5, 0x6 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x6] - movs r6, 0x6 - ldrsh r0, [r2, r6] - cmp r1, r0 - bge _0804DCCA - adds r3, r5, 0 -_0804DCCA: - lsls r0, r3, 16 - asrs r7, r0, 16 - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r8, r0 - ldr r5, [sp, 0x28] - cmp r5, r10 - bge _0804DD16 -_0804DCE4: - mov r4, r9 - adds r6, r5, 0x1 - cmp r9, r7 - bge _0804DD10 - ldr r0, _0804DD4C - adds r3, r0, 0 -_0804DCF0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r8 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DCF0 -_0804DD10: - adds r5, r6, 0 - cmp r5, r10 - blt _0804DCE4 -_0804DD16: - ldr r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r0, r2, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x44] - adds r0, r5, r0 - ldr r6, _0804DD48 - adds r3, r0, r6 - mov r1, sp - ldrh r1, [r1, 0x28] - strh r1, [r3] - mov r2, r10 - strh r2, [r3, 0x4] - mov r4, r9 - strh r4, [r3, 0x2] - strh r7, [r3, 0x6] - movs r5, 0x1 - strb r5, [r0, 0x12] - strb r5, [r3, 0x12] - movs r6, 0 - strb r6, [r0, 0xB] - strb r5, [r0, 0x11] - b _0804E00C - .align 2, 0 -_0804DD48: .4byte 0xfffffe20 -_0804DD4C: .4byte 0x0000fffc -_0804DD50: - mov r7, r10 - cmp r7, 0 - bgt _0804DD58 - b _0804E00C -_0804DD58: - adds r2, r4, 0 - subs r2, 0x20 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DD64 - b _0804E00C -_0804DD64: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DD6C - b _0804E00C -_0804DD6C: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DD74 - b _0804E00C -_0804DD74: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DD7C - b _0804E00C -_0804DD7C: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DD84 - b _0804E00C -_0804DD84: - ldrh r3, [r4] - movs r0, 0 - ldrsh r1, [r4, r0] - ldrh r5, [r2] - movs r6, 0 - ldrsh r0, [r2, r6] - cmp r1, r0 - ble _0804DD96 - adds r3, r5, 0 -_0804DD96: - lsls r0, r3, 16 - asrs r0, 16 - str r0, [sp, 0x2C] - movs r0, 0x2 - ldrsh r7, [r2, r0] - mov r10, r7 - ldrh r3, [r4, 0x4] - movs r5, 0x4 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x4] - movs r6, 0x4 - ldrsh r0, [r2, r6] - cmp r1, r0 - bge _0804DDB4 - adds r3, r5, 0 -_0804DDB4: - lsls r0, r3, 16 - asrs r0, 16 - mov r8, r0 - movs r0, 0x6 - ldrsh r7, [r4, r0] - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r9, r0 - ldr r5, [sp, 0x2C] - cmp r5, r8 - bge _0804DE06 -_0804DDD4: - mov r4, r10 - adds r6, r5, 0x1 - cmp r10, r7 - bge _0804DE00 - ldr r0, _0804DE38 - adds r3, r0, 0 -_0804DDE0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r9 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DDE0 -_0804DE00: - adds r5, r6, 0 - cmp r5, r8 - blt _0804DDD4 -_0804DE06: - ldr r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r0, r2, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x44] - adds r0, r5, r0 - adds r3, r0, 0 - subs r3, 0x20 - mov r6, sp - ldrh r6, [r6, 0x2C] - strh r6, [r3] - mov r1, r8 - strh r1, [r3, 0x4] - mov r2, r10 - strh r2, [r3, 0x2] - strh r7, [r3, 0x6] - movs r4, 0x1 - strb r4, [r0, 0x12] - strb r4, [r3, 0x12] - movs r5, 0 - strb r5, [r0, 0xB] - strb r4, [r0, 0x11] - b _0804E00C - .align 2, 0 -_0804DE38: .4byte 0x0000fffc -_0804DE3C: - ldr r0, [sp, 0x10] - subs r0, 0x2 - ldr r6, [sp, 0x20] - cmp r6, r0 - ble _0804DE48 - b _0804E00C -_0804DE48: - movs r7, 0xF0 - lsls r7, 1 - adds r2, r4, r7 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DE56 - b _0804E00C -_0804DE56: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DE5E - b _0804E00C -_0804DE5E: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DE66 - b _0804E00C -_0804DE66: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DE6E - b _0804E00C -_0804DE6E: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DE76 - b _0804E00C -_0804DE76: - movs r1, 0 - ldrsh r0, [r4, r1] - str r0, [sp, 0x30] - ldrh r3, [r2, 0x2] - movs r5, 0x2 - ldrsh r1, [r2, r5] - ldrh r5, [r4, 0x2] - movs r6, 0x2 - ldrsh r0, [r4, r6] - cmp r1, r0 - ble _0804DE8E - adds r3, r5, 0 -_0804DE8E: - lsls r0, r3, 16 - asrs r0, 16 - mov r9, r0 - movs r0, 0x4 - ldrsh r7, [r2, r0] - mov r10, r7 - ldrh r3, [r2, 0x6] - movs r5, 0x6 - ldrsh r1, [r2, r5] - ldrh r2, [r4, 0x6] - movs r6, 0x6 - ldrsh r0, [r4, r6] - cmp r1, r0 - bge _0804DEAC - adds r3, r2, 0 -_0804DEAC: - lsls r0, r3, 16 - asrs r7, r0, 16 - movs r0, 0x2 - ldrsh r1, [r4, r0] - ldr r0, [sp, 0x30] - bl GetTile - ldrb r0, [r0, 0x9] - mov r8, r0 - ldr r5, [sp, 0x30] - cmp r5, r10 - bge _0804DEF6 -_0804DEC4: - mov r4, r9 - adds r6, r5, 0x1 - cmp r9, r7 - bge _0804DEF0 - ldr r1, _0804DF2C - adds r3, r1, 0 -_0804DED0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r2, r8 - strb r2, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DED0 -_0804DEF0: - adds r5, r6, 0 - cmp r5, r10 - blt _0804DEC4 -_0804DEF6: - ldr r3, [sp, 0x40] - ldr r4, [sp, 0x20] - subs r0, r3, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - ldr r6, [sp, 0x44] - adds r0, r6, r0 - mov r1, sp - ldrh r1, [r1, 0x30] - strh r1, [r0] - mov r2, r10 - strh r2, [r0, 0x4] - mov r3, r9 - strh r3, [r0, 0x2] - strh r7, [r0, 0x6] - movs r4, 0xF0 - lsls r4, 1 - adds r1, r0, r4 - movs r5, 0x1 - strb r5, [r1, 0x12] - strb r5, [r0, 0x12] - movs r6, 0 - strb r6, [r1, 0xB] - strb r5, [r1, 0x11] - b _0804E00C - .align 2, 0 -_0804DF2C: .4byte 0x0000fffc -_0804DF30: - ldr r0, [sp, 0x14] - subs r0, 0x2 - cmp r10, r0 - bgt _0804E00C - adds r3, r4, 0 - adds r3, 0x20 - ldrb r0, [r3, 0xB] - cmp r0, 0 - beq _0804E00C - ldrb r0, [r3, 0x8] - cmp r0, 0 - bne _0804E00C - ldrb r0, [r3, 0xA] - cmp r0, 0 - beq _0804E00C - ldrb r0, [r3, 0x9] - cmp r0, 0 - bne _0804E00C - ldrb r0, [r3, 0x12] - cmp r0, 0 - bne _0804E00C - ldrh r2, [r4, 0x20] - movs r7, 0x20 - ldrsh r1, [r4, r7] - ldrh r5, [r4] - movs r6, 0 - ldrsh r0, [r4, r6] - cmp r1, r0 - ble _0804DF6C - adds r2, r5, 0 -_0804DF6C: - lsls r0, r2, 16 - asrs r0, 16 - str r0, [sp, 0x34] - movs r7, 0x2 - ldrsh r6, [r4, r7] - ldrh r2, [r3, 0x4] - movs r0, 0x4 - ldrsh r1, [r3, r0] - ldrh r5, [r4, 0x4] - movs r7, 0x4 - ldrsh r0, [r4, r7] - cmp r1, r0 - bge _0804DF88 - adds r2, r5, 0 -_0804DF88: - lsls r0, r2, 16 - asrs r0, 16 - mov r8, r0 - movs r0, 0x6 - ldrsh r3, [r3, r0] - movs r1, 0 - ldrsh r0, [r4, r1] - adds r1, r6, 0 - str r3, [sp, 0x54] - bl GetTile - ldrb r0, [r0, 0x9] - mov r10, r0 - ldr r5, [sp, 0x34] - ldr r3, [sp, 0x54] - cmp r5, r8 - bge _0804DFDE -_0804DFAA: - adds r4, r6, 0 - adds r7, r5, 0x1 - cmp r6, r3 - bge _0804DFD8 - ldr r2, _0804E038 - mov r9, r2 -_0804DFB6: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r10 - strb r1, [r0, 0x9] - adds r4, 0x1 - ldr r3, [sp, 0x54] - cmp r4, r3 - blt _0804DFB6 -_0804DFD8: - adds r5, r7, 0 - cmp r5, r8 - blt _0804DFAA -_0804DFDE: - ldr r2, [sp, 0x40] - ldr r4, [sp, 0x20] - subs r0, r2, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - ldr r7, [sp, 0x44] - adds r0, r7, r0 - mov r1, sp - ldrh r1, [r1, 0x34] - strh r1, [r0] - mov r2, r8 - strh r2, [r0, 0x4] - strh r6, [r0, 0x2] - strh r3, [r0, 0x6] - adds r1, r0, 0 - adds r1, 0x20 - movs r3, 0x1 - strb r3, [r1, 0x12] - strb r3, [r0, 0x12] - movs r4, 0 - strb r4, [r1, 0xB] - strb r3, [r1, 0x11] -_0804E00C: - ldr r5, [sp, 0x3C] - mov r10, r5 - ldr r6, [sp, 0x14] - cmp r10, r6 - bge _0804E018 - b _0804DBEC -_0804E018: - ldr r7, [sp, 0x38] - str r7, [sp, 0x20] - adds r0, r7, 0 - ldr r1, [sp, 0x10] - cmp r0, r1 - bge _0804E026 - b _0804DBDA -_0804E026: - add sp, 0x58 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804E038: .4byte 0x0000fffc - thumb_func_end CreateGridCellConnections - thumb_func_start GenerateRoomImperfections GenerateRoomImperfections: push {r4-r7,lr} @@ -1452,8 +421,8 @@ _0804E318: bx r0 thumb_func_end GenerateRoomImperfections - thumb_func_start sub_804E328 -sub_804E328: + thumb_func_start CreateHallway +CreateHallway: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -1788,7 +757,7 @@ _0804E57E: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804E328 + thumb_func_end CreateHallway thumb_func_start EnsureConnectedGrid EnsureConnectedGrid: @@ -1957,7 +926,7 @@ _0804E6AC: str r0, [sp, 0x8] ldr r0, [sp, 0x24] adds r2, r5, 0 - bl sub_804E328 + bl CreateHallway mov r5, r10 strb r5, [r6, 0xB] strb r5, [r6, 0x13] @@ -2019,7 +988,7 @@ _0804E728: str r0, [sp, 0x8] ldr r0, [sp, 0x24] adds r2, r5, 0 - bl sub_804E328 + bl CreateHallway mov r3, r10 strb r3, [r6, 0xB] strb r3, [r6, 0x14] @@ -2076,7 +1045,7 @@ _0804E79E: ldr r1, [r4] str r1, [sp, 0x8] adds r1, r5, 0 - bl sub_804E328 + bl CreateHallway mov r5, r10 strb r5, [r6, 0xB] strb r5, [r6, 0x15] @@ -2139,7 +1108,7 @@ _0804E818: ldr r1, [r4] str r1, [sp, 0x8] adds r1, r5, 0 - bl sub_804E328 + bl CreateHallway mov r5, r10 strb r5, [r6, 0xB] strb r5, [r6, 0x16] diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index d12626ca0..83ad0a0c9 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -996,7 +996,7 @@ struct GridCell Position start; Position end; bool8 isInvalid; - bool8 unk9; + bool8 hasSecondaryStructure; bool8 isRoom; bool8 isConnected; bool8 unk12; @@ -1010,10 +1010,10 @@ struct GridCell bool8 connectedToBottom; bool8 connectedToLeft; bool8 connectedToRight; - bool8 unk23; - bool8 unk24; - bool8 unk25; - bool8 unk26; + bool8 shouldConnectToTop; + bool8 shouldConnectToBottom; + bool8 shouldConnectToLeft; + bool8 shouldConnectToRight; bool8 unk27; bool8 flagImperfect; bool8 flagSecondaryStructure; @@ -1042,6 +1042,7 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); +void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s32 turnX, s32 turnY); /* * GenerateStandardFloor - Generates a standard, typical floor layout. @@ -2040,11 +2041,11 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gri grid[x][y].connectedToLeft = FALSE; grid[x][y].connectedToBottom = FALSE; grid[x][y].connectedToTop = FALSE; - grid[x][y].unk26 = FALSE; - grid[x][y].unk25 = FALSE; - grid[x][y].unk24 = FALSE; - grid[x][y].unk23 = FALSE; - grid[x][y].unk9 = FALSE; + grid[x][y].shouldConnectToRight = FALSE; + grid[x][y].shouldConnectToLeft = FALSE; + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y].hasSecondaryStructure = FALSE; grid[x][y].hasBeenMerged = FALSE; grid[x][y].isMazeRoom = FALSE; grid[x][y].isMerged = FALSE; @@ -2163,6 +2164,7 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz } #define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 +#define GENERATION_CONSTANT_MERGE_ROOMS_CHANCE 5 /* * CreateRoomsAndAnchors - Creates the rectangle regions of open terrain for each room @@ -2581,4 +2583,384 @@ void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN } } +/* + * CreateGridCellConnections - Creates connections through generating hallways and merging rooms + * + * First, connection links are copied over to a work array for managing hallway generation. + * + * Then, for each connection specified between two cells, a hallway is generated based on the following: + * - If the cell is a hallway anchor, the hallway is generated based on the exact point of the anchor tile + * - If the cell is a room, the hallway is generated based on a random interior point inside the room + * + * See: CreateHallway for how these points generate the hallway path + * + * Finally, if room merging is enabled there is a 9.75% chance that two connected rooms will be merged + * into a single larger room. (9.75% comes from two 5% rolls, one for each of the two rooms being merged) + * A room can only participate in a merge once. + * + * Merged rooms take up the full tile space occupied between the two rooms. + * + */ +void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging) +{ + s32 x, y; + + // Validate and copy grid connections over to a work array + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + if (grid[x][y].isInvalid) { + // For invalid cells, assign no connections + + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y].shouldConnectToLeft = FALSE; + grid[x][y].shouldConnectToRight = FALSE; + } + else { + // For valid cells, remove cell connections beyond the grid bounds + if (x <= 0) { + grid[x][y].connectedToLeft = FALSE; + } + + if (y <= 0) { + grid[x][y].connectedToTop = FALSE; + } + + if (x >= gridSizeX - 1) { + grid[x][y].connectedToRight = FALSE; + } + + if (y >= gridSizeY - 1) { + grid[x][y].connectedToBottom = FALSE; + } + + // Assign the connections + grid[x][y].shouldConnectToTop = grid[x][y].connectedToTop; + grid[x][y].shouldConnectToBottom = grid[x][y].connectedToBottom; + grid[x][y].shouldConnectToLeft = grid[x][y].connectedToLeft; + grid[x][y].shouldConnectToRight = grid[x][y].connectedToRight; + } + } + } + + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + s32 pt_x, pt_y, pt2_x, pt2_y; + + if (grid[x][y].isInvalid) + continue; + + if (grid[x][y].isRoom) { + // Room, pick a random point in the interior of the room + pt_x = DungeonRandRange(grid[x][y].start.x + 1, grid[x][y].end.x - 1); + pt_y = DungeonRandRange(grid[x][y].start.y + 1, grid[x][y].end.y - 1); + } + else { + // Hallway anchor, point is the 1x1 we've placed + pt_x = grid[x][y].start.x; + pt_y = grid[x][y].start.y; + } + + if (grid[x][y].shouldConnectToTop) { + // Connect to the cell above + if (!grid[x][y - 1].isInvalid) { + if (grid[x][y - 1].isRoom) { + // Room, pick a random interior x coordinate + pt2_x = DungeonRandRange(grid[x][y - 1].start.x + 1, grid[x][y - 1].end.x - 1); + } + else { + // Anchor, use the central x coordinate + pt2_x = grid[x][y - 1].start.x; + } + + // Create the hallway + CreateHallway(pt_x, grid[x][y].start.y, pt2_x, grid[x][y - 1].end.y - 1, TRUE, listX[x], listY[y]); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y - 1].shouldConnectToBottom = FALSE; + grid[x][y].isConnected = TRUE; + grid[x][y - 1].isConnected = TRUE; + } + + if (grid[x][y].shouldConnectToBottom) { + // Connect to the cell below + if (!grid[x][y + 1].isInvalid) { + if (grid[x][y + 1].isRoom) { + // Room, pick a random interior x coordinate + pt2_x = DungeonRandRange(grid[x][y + 1].start.x + 1, grid[x][y + 1].end.x - 1); + } + else { + // Anchor, use the central x coordinate + pt2_x = grid[x][y + 1].start.x; + } + + // Create the hallway + CreateHallway(pt_x, grid[x][y].end.y - 1, pt2_x, grid[x][y + 1].start.y, TRUE, listX[x], listY[y + 1] - 1); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y + 1].shouldConnectToTop = FALSE; + grid[x][y].isConnected = TRUE; + grid[x][y + 1].isConnected = TRUE; + } + + if (grid[x][y].shouldConnectToLeft) { + // Connect to the cell on the left + if (!grid[x - 1][y].isInvalid) { + if (grid[x - 1][y].isRoom) { + // Room, pick a random interior y coordinate + pt2_y = DungeonRandRange(grid[x - 1][y].start.y + 1, grid[x - 1][y].end.y - 1); + } + else { + // Anchor, use the central y coordinate + pt2_y = grid[x - 1][y].start.y; + } + + // Create the hallway + // Using (grid[x-1][y].start.x - 1) is a bug, it should be (grid[x-1][y].end.x - 1) + // But CreateHallway has safety checks making the end result the same anyways. + CreateHallway(grid[x][y].start.x, pt_y, grid[x - 1][y].start.x - 1, pt2_y, FALSE, listX[x], listY[y]); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToLeft = FALSE; + grid[x - 1][y].shouldConnectToRight = FALSE; + grid[x][y].isConnected = TRUE; + grid[x - 1][y].isConnected = TRUE; + } + + if (grid[x][y].shouldConnectToRight) { + // Connect to the cell on the right + if (!grid[x + 1][y].isInvalid) { + if (grid[x + 1][y].isRoom) { + // Room, pick a random interior y coordinate + pt2_y = DungeonRandRange(grid[x + 1][y].start.y + 1, grid[x + 1][y].end.y - 1); + } + else { + // Anchor, use the central y coordinate + pt2_y = grid[x + 1][y].start.y; + } + + // Create the hallway + CreateHallway(grid[x][y].end.x - 1, pt_y, grid[x + 1][y].start.x, pt2_y, FALSE, listX[x + 1] - 1, listY[y]); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToRight = FALSE; + grid[x + 1][y].shouldConnectToLeft = FALSE; + grid[x][y].isConnected = TRUE; + grid[x + 1][y].isConnected = TRUE; + } + } + } + + // If we don't want to merge rooms, we're done + if (disableRoomMerging) { + return; + } + + // If we do, we can try to merge some! + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + s32 chance = DungeonRandInt(100); + + // Conditions for merging a room: + // - rolls for merge chance + // - valid + // - connected to another room + // - not already merged + // - not have a secondary structure + // - is a room, not an anchor + if (chance < GENERATION_CONSTANT_MERGE_ROOMS_CHANCE && + !grid[x][y].isInvalid && + grid[x][y].isConnected && + !grid[x][y].isMerged && + !grid[x][y].hasSecondaryStructure && + grid[x][y].isRoom) + { + s32 chanceTwo = DungeonRandInt(4); + + // Verify the same for the target room + switch (chanceTwo) { + case 0: + if (x > 0 && + grid[x - 1][y].isConnected && + !grid[x - 1][y].isInvalid && + grid[x - 1][y].isRoom && + !grid[x - 1][y].hasSecondaryStructure && + !grid[x - 1][y].isMerged) + { + // Merge with the room to the left + s32 curX, curY; + s32 srcX = grid[x - 1][y].start.x; + s32 srcY = min(grid[x - 1][y].start.y, grid[x][y].start.y); + s32 dstX = grid[x][y].end.x; + s32 dstY = max(grid[x - 1][y].end.y, grid[x][y].end.y); + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x - 1][y].start.x = srcX; + grid[x - 1][y].end.x = dstX; + grid[x - 1][y].start.y = srcY; + grid[x - 1][y].end.y = dstY; + + // Mark merge flags on both rooms + grid[x][y].isMerged = TRUE; + grid[x - 1][y].isMerged = TRUE; + grid[x][y].isConnected = FALSE; + grid[x][y].hasBeenMerged = TRUE; + } + break; + case 1: + if (y >= 1 && + grid[x][y - 1].isConnected && + !grid[x][y - 1].isInvalid && + grid[x][y - 1].isRoom && + !grid[x][y - 1].hasSecondaryStructure && + !grid[x][y - 1].isMerged) + { + // Merge with the room above + s32 curX, curY; + s32 srcX = min(grid[x][y - 1].start.x, grid[x][y].start.x); + s32 srcY = grid[x][y - 1].start.y; + s32 dstX = max(grid[x][y - 1].end.x, grid[x][y].end.x); + s32 dstY = grid[x][y].end.y; + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x][y - 1].start.x = srcX; + grid[x][y - 1].end.x = dstX; + grid[x][y - 1].start.y = srcY; + grid[x][y - 1].end.y = dstY; + + // Mark merge flags on both rooms + grid[x][y].isMerged = TRUE; + grid[x][y - 1].isMerged = TRUE; + grid[x][y].isConnected = FALSE; + grid[x][y].hasBeenMerged = TRUE; + } + break; + case 2: + if (x <= gridSizeX - 2 && + grid[x + 1][y].isConnected && + !grid[x + 1][y].isInvalid && + grid[x + 1][y].isRoom && + !grid[x + 1][y].hasSecondaryStructure && + !grid[x + 1][y].isMerged) + { + // Merge with the room to the right + s32 curX, curY; + s32 srcX = grid[x][y].start.x; + s32 srcY = min(grid[x][y].start.y, grid[x + 1][y].start.y); + s32 dstX = grid[x + 1][y].end.x; + s32 dstY = max(grid[x][y].end.y, grid[x + 1][y].end.y); + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x][y].start.x = srcX; + grid[x][y].end.x = dstX; + grid[x][y].start.y = srcY; + grid[x][y].end.y = dstY; + + // Mark merge flags on both rooms + grid[x + 1][y].isMerged = TRUE; + grid[x][y].isMerged = TRUE; + grid[x + 1][y].isConnected = FALSE; + grid[x + 1][y].hasBeenMerged = TRUE; + } + break; + case 3: + if (y <= gridSizeY - 2 && + grid[x][y + 1].isConnected && + !grid[x][y + 1].isInvalid && + grid[x][y + 1].isRoom && + !grid[x][y + 1].hasSecondaryStructure && + !grid[x][y + 1].isMerged) + { + // Merge with the room below + s32 curX, curY; + s32 srcX = min(grid[x][y].start.x, grid[x][y + 1].start.x); + s32 srcY = grid[x][y].start.y; + s32 dstX = max(grid[x][y].end.x, grid[x][y + 1].end.x); + s32 dstY = grid[x][y + 1].end.y; + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x][y].start.x = srcX; + grid[x][y].end.x = dstX; + grid[x][y].start.y = srcY; + grid[x][y].end.y = dstY; + + // Mark merge flags on both rooms + grid[x][y + 1].isMerged = TRUE; + grid[x][y].isMerged = TRUE; + grid[x][y + 1].isConnected = FALSE; + grid[x][y + 1].hasBeenMerged = TRUE; + } + break; + } + } + } + } +} + // From ad0f0f4050705ba6073fcdb741cbb7cd0f9116bc Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 11 Nov 2024 17:01:04 +0100 Subject: [PATCH 11/30] SetTerrainObstacleChecked --- asm/code_804AFAC.s | 1334 +---------------------------------------- include/structs/map.h | 1 + src/code_804AFAC_1.c | 621 ++++++++++++++++++- 3 files changed, 598 insertions(+), 1358 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index e54657da0..21d398fff 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -5,1330 +5,6 @@ .text - thumb_func_start GenerateRoomImperfections -GenerateRoomImperfections: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x44 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - movs r0, 0 - str r0, [sp, 0xC] - cmp r0, r1 - blt _0804E058 - b _0804E318 -_0804E058: - movs r2, 0 - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0x28] - ldr r3, [sp, 0x8] - cmp r2, r3 - blt _0804E068 - b _0804E30C -_0804E068: - ldr r4, [sp, 0xC] - lsls r4, 4 - str r4, [sp, 0x14] - ldr r6, [sp, 0xC] - subs r0, r4, r6 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - str r0, [sp, 0x18] -_0804E07A: - lsls r0, r2, 5 - ldr r3, [sp, 0x18] - adds r4, r0, r3 - ldrb r1, [r4, 0x8] - str r0, [sp, 0x34] - adds r2, 0x1 - str r2, [sp, 0x2C] - cmp r1, 0 - beq _0804E08E - b _0804E302 -_0804E08E: - ldrb r0, [r4, 0x11] - cmp r0, 0 - beq _0804E096 - b _0804E302 -_0804E096: - ldrb r0, [r4, 0x12] - cmp r0, 0 - beq _0804E09E - b _0804E302 -_0804E09E: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _0804E0A6 - b _0804E302 -_0804E0A6: - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804E0AE - b _0804E302 -_0804E0AE: - ldrb r0, [r4, 0x9] - cmp r0, 0 - beq _0804E0B6 - b _0804E302 -_0804E0B6: - ldrb r0, [r4, 0x10] - cmp r0, 0 - beq _0804E0BE - b _0804E302 -_0804E0BE: - ldrb r0, [r4, 0x1C] - cmp r0, 0 - bne _0804E0C6 - b _0804E302 -_0804E0C6: - movs r0, 0x64 - bl DungeonRandInt - cmp r0, 0x3B - bgt _0804E0D2 - b _0804E302 -_0804E0D2: - movs r6, 0x4 - ldrsh r2, [r4, r6] - movs r1, 0 - ldrsh r0, [r4, r1] - subs r2, r0 - movs r3, 0x6 - ldrsh r0, [r4, r3] - movs r6, 0x2 - ldrsh r1, [r4, r6] - subs r0, r1 - adds r2, r0 - str r2, [sp, 0x10] - adds r0, r2, 0 - cmp r2, 0 - bge _0804E0F2 - adds r0, 0x3 -_0804E0F2: - asrs r0, 2 - str r0, [sp, 0x10] - cmp r0, 0 - bne _0804E0FE - movs r0, 0x1 - str r0, [sp, 0x10] -_0804E0FE: - movs r1, 0 - ldr r2, [sp, 0x10] - cmp r1, r2 - blt _0804E108 - b _0804E302 -_0804E108: - ldr r3, [sp, 0x14] - ldr r4, [sp, 0xC] - subs r0, r3, r4 - lsls r0, 5 - ldr r6, [sp] - adds r0, r6 - ldr r2, [sp, 0x34] - adds r0, r2, r0 - str r0, [sp, 0x20] -_0804E11A: - movs r4, 0 - adds r1, 0x1 - str r1, [sp, 0x30] -_0804E120: - movs r0, 0x4 - bl DungeonRandInt - str r0, [sp, 0x1C] - cmp r0, 0x1 - beq _0804E14A - cmp r0, 0x1 - ble _0804E138 - cmp r0, 0x2 - beq _0804E168 - cmp r0, 0x3 - beq _0804E182 -_0804E138: - ldr r3, [sp, 0x20] - movs r6, 0 - ldrsh r7, [r3, r6] - movs r1, 0x2 - ldrsh r0, [r3, r1] - mov r8, r0 - cmp r4, 0 - bne _0804E19C - b _0804E15C -_0804E14A: - ldr r2, [sp, 0x20] - movs r3, 0x4 - ldrsh r0, [r2, r3] - subs r7, r0, 0x1 - movs r0, 0x2 - ldrsh r6, [r2, r0] - mov r8, r6 - cmp r4, 0 - beq _0804E162 -_0804E15C: - movs r3, 0 - movs r2, 0x1 - b _0804E1A0 -_0804E162: - movs r3, 0x1 - negs r3, r3 - b _0804E19E -_0804E168: - ldr r1, [sp, 0x20] - movs r2, 0x4 - ldrsh r0, [r1, r2] - subs r7, r0, 0x1 - movs r3, 0x6 - ldrsh r0, [r1, r3] - subs r0, 0x1 - mov r8, r0 - cmp r4, 0 - beq _0804E194 - movs r3, 0x1 - negs r3, r3 - b _0804E19E -_0804E182: - ldr r6, [sp, 0x20] - movs r0, 0 - ldrsh r7, [r6, r0] - movs r1, 0x6 - ldrsh r0, [r6, r1] - subs r0, 0x1 - mov r8, r0 - cmp r4, 0 - beq _0804E19C -_0804E194: - movs r3, 0 - movs r2, 0x1 - negs r2, r2 - b _0804E1A0 -_0804E19C: - movs r3, 0x1 -_0804E19E: - movs r2, 0 -_0804E1A0: - movs r6, 0 - mov r9, r6 - ldr r5, [sp, 0x34] - ldr r0, [sp, 0x14] - str r0, [sp, 0x40] - ldr r6, [sp, 0x18] - adds r1, r5, r6 - movs r6, 0 - ldrsh r0, [r1, r6] - mov r10, r0 - adds r4, 0x1 - str r4, [sp, 0x24] - cmp r7, r10 - bge _0804E1BE - b _0804E2F0 -_0804E1BE: - movs r4, 0x4 - ldrsh r0, [r1, r4] - cmp r7, r0 - blt _0804E1C8 - b _0804E2F0 -_0804E1C8: - ldr r6, [sp, 0x40] - ldr r1, [sp, 0xC] - subs r0, r6, r1 - lsls r0, 5 - ldr r4, [sp] - adds r0, r4 - adds r4, r5, r0 - movs r6, 0x2 - ldrsh r0, [r4, r6] - cmp r8, r0 - bge _0804E1E0 - b _0804E2F0 -_0804E1E0: - movs r1, 0x6 - ldrsh r0, [r4, r1] - cmp r8, r0 - blt _0804E1EA - b _0804E2F0 -_0804E1EA: - adds r0, r7, 0 - mov r1, r8 - str r2, [sp, 0x38] - str r3, [sp, 0x3C] - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - ldr r2, [sp, 0x38] - ldr r3, [sp, 0x3C] - cmp r0, 0x1 - bne _0804E2D0 - movs r6, 0 -_0804E206: - ldr r1, _0804E228 - lsls r0, r6, 2 - adds r0, r1 - movs r2, 0 - ldrsh r1, [r0, r2] - adds r1, r7 - mov r10, r1 - movs r3, 0x2 - ldrsh r0, [r0, r3] - add r0, r8 - mov r9, r0 - movs r3, 0 - movs r5, 0x1 - negs r5, r5 -_0804E222: - movs r4, 0x1 - negs r4, r4 - b _0804E22E - .align 2, 0 -_0804E228: .4byte gAdjacentTileOffsets -_0804E22C: - adds r4, 0x1 -_0804E22E: - cmp r4, 0x1 - bgt _0804E25A - mov r1, r10 - adds r0, r1, r4 - mov r2, r9 - adds r1, r2, r5 - str r3, [sp, 0x3C] - bl GetTile - adds r2, r0, 0 - ldrh r1, [r2] - movs r0, 0x3 - ands r0, r1 - ldr r3, [sp, 0x3C] - cmp r0, 0x1 - bne _0804E22C - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - bne _0804E256 - movs r3, 0x1 -_0804E256: - cmp r3, 0 - beq _0804E22C -_0804E25A: - cmp r3, 0 - bne _0804E26A - adds r5, 0x1 - cmp r5, 0x1 - ble _0804E222 - adds r6, 0x1 - cmp r6, 0x7 - ble _0804E206 -_0804E26A: - cmp r6, 0x8 - bne _0804E2F0 - movs r6, 0 - ldr r3, [sp, 0x1C] - lsls r1, r3, 3 - ldr r0, _0804E2C4 - adds r4, r1, r0 -_0804E278: - ldr r0, _0804E2C8 - lsls r1, r6, 2 - adds r1, r0 - movs r2, 0 - ldrsh r0, [r1, r2] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - add r1, r8 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - movs r1, 0 - cmp r0, 0x1 - bne _0804E29C - movs r1, 0x1 -_0804E29C: - ldrb r0, [r4] - cmp r0, r1 - bne _0804E2AA - adds r4, 0x2 - adds r6, 0x2 - cmp r6, 0x7 - ble _0804E278 -_0804E2AA: - cmp r6, 0x8 - bne _0804E2F0 - adds r0, r7, 0 - mov r1, r8 - bl GetTileSafe - ldrh r2, [r0] - ldr r4, _0804E2CC - adds r1, r4, 0 - ands r2, r1 - strh r2, [r0] - b _0804E2F0 - .align 2, 0 -_0804E2C4: .4byte gUnknown_80F6DD5 -_0804E2C8: .4byte gAdjacentTileOffsets -_0804E2CC: .4byte 0x0000fffc -_0804E2D0: - adds r7, r3 - add r8, r2 - movs r6, 0x1 - add r9, r6 - mov r0, r9 - cmp r0, 0x9 - bgt _0804E2F0 - movs r1, 0 - ldrsh r0, [r4, r1] - cmp r7, r0 - blt _0804E2F0 - movs r6, 0x4 - ldrsh r0, [r4, r6] - cmp r7, r0 - bge _0804E2F0 - b _0804E1C8 -_0804E2F0: - ldr r4, [sp, 0x24] - cmp r4, 0x1 - bgt _0804E2F8 - b _0804E120 -_0804E2F8: - ldr r1, [sp, 0x30] - ldr r0, [sp, 0x10] - cmp r1, r0 - bge _0804E302 - b _0804E11A -_0804E302: - ldr r2, [sp, 0x2C] - ldr r1, [sp, 0x8] - cmp r2, r1 - bge _0804E30C - b _0804E07A -_0804E30C: - ldr r2, [sp, 0x28] - str r2, [sp, 0xC] - ldr r3, [sp, 0x4] - cmp r2, r3 - bge _0804E318 - b _0804E058 -_0804E318: - add sp, 0x44 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GenerateRoomImperfections - - thumb_func_start CreateHallway -CreateHallway: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r5, r0, 0 - adds r4, r1, 0 - str r2, [sp] - str r3, [sp, 0x4] - ldr r0, [sp, 0x28] - lsls r0, 24 - mov r10, r5 - mov r9, r4 - ldr r1, [sp, 0x2C] - mov r8, r1 - ldr r7, [sp, 0x30] - cmp r0, 0 - bne _0804E350 - b _0804E470 -_0804E350: - movs r6, 0 -_0804E352: - cmp r4, r7 - beq _0804E3A8 - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E360 - b _0804E57E -_0804E360: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E390 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - ldr r3, _0804E38C - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E39C - .align 2, 0 -_0804E38C: .4byte 0x0000fffc -_0804E390: - cmp r5, r10 - beq _0804E396 - b _0804E57E -_0804E396: - cmp r4, r9 - beq _0804E39C - b _0804E57E -_0804E39C: - cmp r4, r7 - bge _0804E3A4 - adds r4, 0x1 - b _0804E352 -_0804E3A4: - subs r4, 0x1 - b _0804E352 -_0804E3A8: - movs r6, 0 - ldr r0, [sp] - cmp r5, r0 - beq _0804E40A - movs r7, 0 -_0804E3B2: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E3BC - b _0804E57E -_0804E3BC: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E3EC - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - ldr r3, _0804E3E8 - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E3F8 - .align 2, 0 -_0804E3E8: .4byte 0x0000fffc -_0804E3EC: - cmp r5, r10 - beq _0804E3F2 - b _0804E57E -_0804E3F2: - cmp r4, r9 - beq _0804E3F8 - b _0804E57E -_0804E3F8: - ldr r0, [sp] - cmp r5, r0 - bge _0804E402 - adds r5, 0x1 - b _0804E404 -_0804E402: - subs r5, 0x1 -_0804E404: - ldr r1, [sp] - cmp r5, r1 - bne _0804E3B2 -_0804E40A: - movs r6, 0 - ldr r3, [sp, 0x4] - cmp r4, r3 - bne _0804E414 - b _0804E57E -_0804E414: - movs r7, 0 -_0804E416: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E420 - b _0804E57E -_0804E420: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E450 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - ldr r3, _0804E44C - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E45C - .align 2, 0 -_0804E44C: .4byte 0x0000fffc -_0804E450: - cmp r5, r10 - beq _0804E456 - b _0804E57E -_0804E456: - cmp r4, r9 - beq _0804E45C - b _0804E57E -_0804E45C: - ldr r0, [sp, 0x4] - cmp r4, r0 - bge _0804E466 - adds r4, 0x1 - b _0804E468 -_0804E466: - subs r4, 0x1 -_0804E468: - ldr r1, [sp, 0x4] - cmp r4, r1 - bne _0804E416 - b _0804E57E -_0804E470: - movs r6, 0 - cmp r5, r8 - beq _0804E4C6 - movs r7, 0 -_0804E478: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E482 - b _0804E57E -_0804E482: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E4B0 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - ldr r3, _0804E4AC - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E4B8 - .align 2, 0 -_0804E4AC: .4byte 0x0000fffc -_0804E4B0: - cmp r5, r10 - bne _0804E57E - cmp r4, r9 - bne _0804E57E -_0804E4B8: - cmp r5, r8 - bge _0804E4C0 - adds r5, 0x1 - b _0804E4C2 -_0804E4C0: - subs r5, 0x1 -_0804E4C2: - cmp r5, r8 - bne _0804E478 -_0804E4C6: - movs r6, 0 - ldr r0, [sp, 0x4] - cmp r4, r0 - beq _0804E522 - movs r7, 0 -_0804E4D0: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - bgt _0804E57E - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E508 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - ldr r3, _0804E504 - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E510 - .align 2, 0 -_0804E504: .4byte 0x0000fffc -_0804E508: - cmp r5, r10 - bne _0804E57E - cmp r4, r9 - bne _0804E57E -_0804E510: - ldr r0, [sp, 0x4] - cmp r4, r0 - bge _0804E51A - adds r4, 0x1 - b _0804E51C -_0804E51A: - subs r4, 0x1 -_0804E51C: - ldr r1, [sp, 0x4] - cmp r4, r1 - bne _0804E4D0 -_0804E522: - movs r6, 0 - ldr r3, [sp] - cmp r5, r3 - beq _0804E57E - movs r7, 0 -_0804E52C: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - bgt _0804E57E - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E564 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - ldr r3, _0804E560 - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E56C - .align 2, 0 -_0804E560: .4byte 0x0000fffc -_0804E564: - cmp r5, r10 - bne _0804E57E - cmp r4, r9 - bne _0804E57E -_0804E56C: - ldr r0, [sp] - cmp r5, r0 - bge _0804E576 - adds r5, 0x1 - b _0804E578 -_0804E576: - subs r5, 0x1 -_0804E578: - ldr r1, [sp] - cmp r5, r1 - bne _0804E52C -_0804E57E: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end CreateHallway - - thumb_func_start EnsureConnectedGrid -EnsureConnectedGrid: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x40 - str r0, [sp, 0xC] - str r1, [sp, 0x10] - str r2, [sp, 0x14] - str r3, [sp, 0x18] - movs r0, 0 - str r0, [sp, 0x1C] - cmp r0, r1 - blt _0804E5AE - b _0804E8AA -_0804E5AE: - movs r1, 0x1 - mov r10, r1 -_0804E5B2: - movs r2, 0 - str r2, [sp, 0x20] - ldr r3, [sp, 0x1C] - adds r3, 0x1 - str r3, [sp, 0x2C] - ldr r4, [sp, 0x14] - cmp r2, r4 - blt _0804E5C4 - b _0804E89E -_0804E5C4: - ldr r5, [sp, 0x1C] - lsls r5, 4 - ldr r6, [sp, 0x1C] - subs r1, r5, r6 - lsls r1, 5 - ldr r2, [sp, 0xC] - movs r3, 0xF0 - lsls r3, 1 - adds r0, r2, r3 - adds r0, r1 - mov r8, r0 - adds r6, r1, r2 - ldr r4, _0804E6A4 - adds r0, r2, r4 - adds r7, r1, r0 - adds r0, r2, 0 - adds r0, 0x20 - adds r0, r1 - mov r9, r0 - ldr r5, [sp, 0x60] - str r5, [sp, 0x34] - adds r0, r2, 0 - subs r0, 0x20 - adds r1, r0 - str r1, [sp, 0x38] - movs r0, 0 - str r0, [sp, 0x3C] - ldr r1, [sp, 0x1C] - lsls r0, r1, 2 - ldr r2, [sp, 0x18] - adds r0, r2 - str r0, [sp, 0x28] -_0804E604: - ldr r3, [sp, 0x1C] - lsls r0, r3, 4 - subs r0, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x3C] - adds r4, r5, r0 - ldrb r0, [r4, 0x8] - cmp r0, 0 - beq _0804E61C - b _0804E874 -_0804E61C: - ldrb r0, [r4, 0x11] - cmp r0, 0 - beq _0804E624 - b _0804E874 -_0804E624: - ldrb r0, [r4, 0xB] - cmp r0, 0 - beq _0804E62C - b _0804E874 -_0804E62C: - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804E634 - b _0804E848 -_0804E634: - ldrb r0, [r4, 0x9] - cmp r0, 0 - beq _0804E63C - b _0804E848 -_0804E63C: - movs r1, 0 - ldrsh r0, [r4, r1] - adds r0, 0x1 - movs r2, 0x4 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - str r0, [sp, 0x24] - movs r3, 0x2 - ldrsh r0, [r4, r3] - adds r0, 0x1 - movs r5, 0x6 - ldrsh r1, [r4, r5] - subs r1, 0x1 - bl DungeonRandRange - adds r5, r0, 0 - ldr r0, [sp, 0x20] - cmp r0, 0 - ble _0804E6DC - subs r4, 0x20 - ldrb r0, [r4, 0x8] - cmp r0, 0 - bne _0804E6DC - ldrb r0, [r4, 0x12] - cmp r0, 0 - bne _0804E6DC - ldrb r0, [r4, 0xB] - cmp r0, 0 - beq _0804E6DC - ldrb r0, [r4, 0xA] - cmp r0, 0 - beq _0804E6A8 - movs r1, 0 - ldrsh r0, [r4, r1] - adds r0, 0x1 - movs r2, 0x4 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r5, r0, 0 - movs r3, 0x2 - ldrsh r0, [r4, r3] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - b _0804E6AC - .align 2, 0 -_0804E6A4: .4byte 0xfffffe20 -_0804E6A8: - movs r3, 0 - ldrsh r5, [r4, r3] -_0804E6AC: - movs r4, 0x2 - ldrsh r1, [r6, r4] - ldr r0, [sp, 0x38] - movs r2, 0x6 - ldrsh r3, [r0, r2] - subs r3, 0x1 - mov r4, r10 - str r4, [sp] - ldr r2, [sp, 0x28] - ldr r0, [r2] - str r0, [sp, 0x4] - ldr r4, [sp, 0x34] - ldr r0, [r4] - str r0, [sp, 0x8] - ldr r0, [sp, 0x24] - adds r2, r5, 0 - bl CreateHallway - mov r5, r10 - strb r5, [r6, 0xB] - strb r5, [r6, 0x13] - ldr r0, [sp, 0x38] - strb r5, [r0, 0x14] - b _0804E874 -_0804E6DC: - ldr r0, [sp, 0x14] - subs r0, 0x1 - ldr r1, [sp, 0x20] - cmp r1, r0 - bge _0804E758 - mov r2, r9 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804E758 - ldrb r0, [r2, 0x12] - cmp r0, 0 - bne _0804E758 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804E758 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804E724 - movs r3, 0x20 - ldrsh r0, [r6, r3] - adds r0, 0x1 - movs r4, 0x24 - ldrsh r1, [r6, r4] - subs r1, 0x1 - bl DungeonRandRange - adds r5, r0, 0 - movs r1, 0x22 - ldrsh r0, [r6, r1] - adds r0, 0x1 - movs r2, 0x26 - ldrsh r1, [r6, r2] - subs r1, 0x1 - bl DungeonRandRange - b _0804E728 -_0804E724: - movs r3, 0x20 - ldrsh r5, [r6, r3] -_0804E728: - movs r4, 0x6 - ldrsh r1, [r6, r4] - subs r1, 0x1 - movs r0, 0x22 - ldrsh r3, [r6, r0] - mov r2, r10 - str r2, [sp] - ldr r4, [sp, 0x28] - ldr r0, [r4] - str r0, [sp, 0x4] - ldr r2, [sp, 0x34] - ldr r0, [r2, 0x4] - subs r0, 0x1 - str r0, [sp, 0x8] - ldr r0, [sp, 0x24] - adds r2, r5, 0 - bl CreateHallway - mov r3, r10 - strb r3, [r6, 0xB] - strb r3, [r6, 0x14] - mov r4, r9 - strb r3, [r4, 0x13] - b _0804E874 -_0804E758: - ldr r0, [sp, 0x1C] - cmp r0, 0 - ble _0804E7C8 - ldrb r0, [r7, 0x8] - cmp r0, 0 - bne _0804E7C8 - ldrb r0, [r7, 0x12] - cmp r0, 0 - bne _0804E7C8 - ldrb r0, [r7, 0xB] - cmp r0, 0 - beq _0804E7C8 - ldrb r0, [r7, 0xA] - cmp r0, 0 - beq _0804E79A - movs r1, 0 - ldrsh r0, [r7, r1] - adds r0, 0x1 - movs r2, 0x4 - ldrsh r1, [r7, r2] - subs r1, 0x1 - bl DungeonRandRange - movs r3, 0x2 - ldrsh r0, [r7, r3] - adds r0, 0x1 - movs r4, 0x6 - ldrsh r1, [r7, r4] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804E79E -_0804E79A: - movs r0, 0x2 - ldrsh r3, [r7, r0] -_0804E79E: - movs r1, 0 - ldrsh r0, [r6, r1] - movs r4, 0 - ldrsh r2, [r7, r4] - subs r2, 0x1 - movs r1, 0 - str r1, [sp] - ldr r4, [sp, 0x28] - ldr r1, [r4] - str r1, [sp, 0x4] - ldr r4, [sp, 0x34] - ldr r1, [r4] - str r1, [sp, 0x8] - adds r1, r5, 0 - bl CreateHallway - mov r5, r10 - strb r5, [r6, 0xB] - strb r5, [r6, 0x15] - strb r5, [r7, 0x16] - b _0804E874 -_0804E7C8: - ldr r0, [sp, 0x10] - subs r0, 0x1 - ldr r1, [sp, 0x1C] - cmp r1, r0 - bge _0804E874 - mov r2, r8 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804E874 - ldrb r0, [r2, 0x12] - cmp r0, 0 - bne _0804E874 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804E874 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804E812 - movs r3, 0 - ldrsh r0, [r2, r3] - adds r0, 0x1 - movs r4, 0x4 - ldrsh r1, [r2, r4] - subs r1, 0x1 - bl DungeonRandRange - mov r1, r8 - movs r2, 0x2 - ldrsh r0, [r1, r2] - adds r0, 0x1 - movs r3, 0x6 - ldrsh r1, [r1, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804E818 -_0804E812: - mov r4, r8 - movs r0, 0x2 - ldrsh r3, [r4, r0] -_0804E818: - movs r1, 0x4 - ldrsh r0, [r6, r1] - subs r0, 0x1 - mov r4, r8 - movs r1, 0 - ldrsh r2, [r4, r1] - movs r1, 0 - str r1, [sp] - ldr r4, [sp, 0x28] - ldr r1, [r4, 0x4] - subs r1, 0x1 - str r1, [sp, 0x4] - ldr r4, [sp, 0x34] - ldr r1, [r4] - str r1, [sp, 0x8] - adds r1, r5, 0 - bl CreateHallway - mov r5, r10 - strb r5, [r6, 0xB] - strb r5, [r6, 0x16] - mov r0, r8 - strb r5, [r0, 0x15] - b _0804E874 -_0804E848: - movs r1, 0 - ldrsh r0, [r6, r1] - movs r2, 0x2 - ldrsh r1, [r6, r2] - bl GetTileSafe - ldrh r1, [r0] - ldr r3, _0804E99C - adds r2, r3, 0 - ands r1, r2 - strh r1, [r0] - ldrh r1, [r0, 0x4] - ldr r4, _0804E9A0 - adds r2, r4, 0 - ands r1, r2 - ldr r5, _0804E9A4 - adds r2, r5, 0 - ands r1, r2 - subs r3, 0x1 - adds r2, r3, 0 - ands r1, r2 - strh r1, [r0, 0x4] -_0804E874: - movs r4, 0x20 - add r8, r4 - adds r6, 0x20 - adds r7, 0x20 - add r9, r4 - ldr r5, [sp, 0x34] - adds r5, 0x4 - str r5, [sp, 0x34] - ldr r0, [sp, 0x38] - adds r0, 0x20 - str r0, [sp, 0x38] - ldr r1, [sp, 0x3C] - adds r1, 0x20 - str r1, [sp, 0x3C] - ldr r2, [sp, 0x20] - adds r2, 0x1 - str r2, [sp, 0x20] - ldr r3, [sp, 0x14] - cmp r2, r3 - bge _0804E89E - b _0804E604 -_0804E89E: - ldr r4, [sp, 0x2C] - str r4, [sp, 0x1C] - ldr r5, [sp, 0x10] - cmp r4, r5 - bge _0804E8AA - b _0804E5B2 -_0804E8AA: - movs r6, 0 - str r6, [sp, 0x1C] - ldr r0, [sp, 0x10] - cmp r6, r0 - bge _0804E98A -_0804E8B4: - movs r1, 0 - str r1, [sp, 0x20] - ldr r2, [sp, 0x1C] - adds r2, 0x1 - str r2, [sp, 0x2C] - ldr r3, [sp, 0x14] - cmp r1, r3 - bge _0804E980 - ldr r4, [sp, 0x1C] - lsls r4, 4 - mov r9, r4 -_0804E8CA: - ldr r5, [sp, 0x20] - lsls r2, r5, 5 - ldr r6, [sp, 0x1C] - lsls r3, r6, 4 - subs r0, r3, r6 - lsls r0, 5 - ldr r1, [sp, 0xC] - adds r4, r0, r1 - adds r1, r2, r4 - ldrb r0, [r1, 0x8] - mov r8, r2 - adds r5, 0x1 - str r5, [sp, 0x30] - cmp r0, 0 - bne _0804E976 - ldrb r0, [r1, 0x11] - cmp r0, 0 - bne _0804E976 - ldrb r0, [r1, 0xB] - cmp r0, 0 - bne _0804E976 - ldrb r0, [r1, 0xF] - cmp r0, 0 - bne _0804E976 - movs r6, 0 - ldrsh r5, [r1, r6] - movs r6, 0x4 - ldrsh r0, [r1, r6] - cmp r5, r0 - bge _0804E976 - mov r10, r4 -_0804E908: - ldr r1, [sp, 0x1C] - subs r0, r3, r1 - lsls r0, 5 - ldr r3, [sp, 0xC] - adds r0, r3 - adds r0, r2, r0 - movs r6, 0x2 - ldrsh r4, [r0, r6] - movs r1, 0x6 - ldrsh r0, [r0, r1] - adds r7, r5, 0x1 - cmp r4, r0 - bge _0804E95C - mov r6, r8 - add r6, r10 -_0804E926: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - ldr r3, _0804E99C - adds r1, r3, 0 - ands r2, r1 - strh r2, [r0] - ldrh r2, [r0, 0x4] - adds r3, 0x1 - adds r1, r3, 0 - ands r2, r1 - adds r3, 0x1 - adds r1, r3, 0 - ands r2, r1 - subs r3, 0x3 - adds r1, r3, 0 - ands r2, r1 - strh r2, [r0, 0x4] - movs r1, 0xFF - strb r1, [r0, 0x9] - adds r4, 0x1 - movs r1, 0x6 - ldrsh r0, [r6, r1] - cmp r4, r0 - blt _0804E926 -_0804E95C: - adds r5, r7, 0 - mov r2, r8 - mov r3, r9 - ldr r4, [sp, 0x1C] - subs r0, r3, r4 - lsls r0, 5 - ldr r6, [sp, 0xC] - adds r0, r6 - adds r0, r2, r0 - movs r1, 0x4 - ldrsh r0, [r0, r1] - cmp r5, r0 - blt _0804E908 -_0804E976: - ldr r2, [sp, 0x30] - str r2, [sp, 0x20] - ldr r3, [sp, 0x14] - cmp r2, r3 - blt _0804E8CA -_0804E980: - ldr r4, [sp, 0x2C] - str r4, [sp, 0x1C] - ldr r5, [sp, 0x10] - cmp r4, r5 - blt _0804E8B4 -_0804E98A: - add sp, 0x40 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804E99C: .4byte 0x0000fffc -_0804E9A0: .4byte 0x0000fffe -_0804E9A4: .4byte 0x0000fffd - thumb_func_end EnsureConnectedGrid - - thumb_func_start sub_804E9A8 -sub_804E9A8: - push {r4,r5,lr} - adds r4, r0, 0 - lsls r1, 24 - lsls r2, 24 - lsrs r2, 24 - ldrh r0, [r4] - ldr r5, _0804E9D8 - adds r3, r5, 0 - ands r3, r0 - strh r3, [r4] - cmp r1, 0 - beq _0804E9D0 - ldrb r0, [r4, 0x9] - cmp r0, r2 - bne _0804E9D0 - adds r0, r3, 0 - ands r0, r5 - movs r1, 0x2 - orrs r0, r1 - strh r0, [r4] -_0804E9D0: - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_0804E9D8: .4byte 0x0000fffc - thumb_func_end sub_804E9A8 thumb_func_start sub_804E9DC sub_804E9DC: @@ -2802,7 +1478,7 @@ _0804F4BA: mov r1, r9 mov r3, r8 lsrs r2, r3, 24 - bl sub_804E9A8 + bl SetTerrainObstacleChecked _0804F4D6: adds r0, r6, 0 mov r1, r10 @@ -2885,7 +1561,7 @@ _0804F55A: mov r1, r9 mov r3, r8 lsrs r2, r3, 24 - bl sub_804E9A8 + bl SetTerrainObstacleChecked adds r5, 0x2 b _0804F4BA _0804F570: @@ -2895,7 +1571,7 @@ _0804F570: mov r1, r9 mov r3, r8 lsrs r2, r3, 24 - bl sub_804E9A8 + bl SetTerrainObstacleChecked subs r4, 0x2 b _0804F4BA _0804F586: @@ -2905,7 +1581,7 @@ _0804F586: mov r1, r9 mov r3, r8 lsrs r2, r3, 24 - bl sub_804E9A8 + bl SetTerrainObstacleChecked subs r5, 0x2 b _0804F4BA _0804F59C: @@ -2915,7 +1591,7 @@ _0804F59C: mov r1, r9 mov r3, r8 lsrs r2, r3, 24 - bl sub_804E9A8 + bl SetTerrainObstacleChecked adds r4, 0x2 b _0804F4BA _0804F5B2: diff --git a/include/structs/map.h b/include/structs/map.h index cda59ded2..7e8e22a16 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -9,6 +9,7 @@ enum TerrainType { + TERRAIN_TYPE_WALL = 0, // x0 When neither TERRAIN_TYPE_NORMAL nor TERRAIN_TYPE_SECONDARY are set TERRAIN_TYPE_NORMAL = 1 << 0, // x1 TERRAIN_TYPE_SECONDARY = 1 << 1, // Water or lava depending on the dungeon. x2 TERRAIN_TYPE_UNK_2 = 1 << 2, // x4 diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 83ad0a0c9..5e70d51bc 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -70,13 +70,29 @@ struct FileFixedmapPosStruct u8 y; }; -static inline void SetTerrainNormal(Tile *tile) +// Helper functions for terrain flags +static inline void SetTerrainType(Tile *tile, u32 terrainType) { tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - tile->terrainType |= TERRAIN_TYPE_NORMAL; + tile->terrainType |= terrainType; } -static inline u32 GetTerrain(Tile *tile) +static inline void SetTerrainNormal(Tile *tile) +{ + SetTerrainType(tile, TERRAIN_TYPE_NORMAL); +} + +static inline void SetTerrainSecondary(Tile *tile) +{ + SetTerrainType(tile, TERRAIN_TYPE_SECONDARY); +} + +static inline void SetTerrainWall(Tile *tile) +{ + SetTerrainType(tile, TERRAIN_TYPE_WALL); +} + +static inline u32 GetTerrainType(Tile *tile) { return tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); } @@ -972,15 +988,15 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) Tile *tile = GetTileSafe(x, y); tile->terrainType &= ~(TERRAIN_TYPE_UNK_2); - if (tile->room == CORRIDOR_ROOM && (GetTerrain(tile) == TERRAIN_TYPE_NORMAL)) { - if (x > 0 && (GetTerrain(GetTile(x - 1, y)) == TERRAIN_TYPE_NORMAL)) + if (tile->room == CORRIDOR_ROOM && (GetTerrainType(tile) == TERRAIN_TYPE_NORMAL)) { + if (x > 0 && (GetTerrainType(GetTile(x - 1, y)) == TERRAIN_TYPE_NORMAL)) unkCount++; - if (y > 0 && (GetTerrain(GetTile(x, y - 1)) == TERRAIN_TYPE_NORMAL)) + if (y > 0 && (GetTerrainType(GetTile(x, y - 1)) == TERRAIN_TYPE_NORMAL)) unkCount++; - if (x < DUNGEON_MAX_SIZE_X - 2 && (GetTerrain(GetTile(x + 1, y)) == TERRAIN_TYPE_NORMAL)) + if (x < DUNGEON_MAX_SIZE_X - 2 && (GetTerrainType(GetTile(x + 1, y)) == TERRAIN_TYPE_NORMAL)) unkCount++; // BUG: It should check for y and not x. Not sure if it has any effect, because this function is called only once with maxY equal to DUNGEON_MAX_SIZE_Y - if (x < DUNGEON_MAX_SIZE_Y - 2 && (GetTerrain(GetTile(x, y + 1)) == TERRAIN_TYPE_NORMAL)) + if (x < DUNGEON_MAX_SIZE_Y - 2 && (GetTerrainType(GetTile(x, y + 1)) == TERRAIN_TYPE_NORMAL)) unkCount++; if (unkCount > 2) { @@ -1858,7 +1874,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // Keep walking until an obstacle is encountered while (1) { - if (GetTerrain(GetTile(currX, currY)) != TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX, currY)) != TERRAIN_TYPE_NORMAL) break; currX += gAdjacentTileOffsets[direction].x; @@ -1866,7 +1882,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s } // Abort if we reached secondary terrain - if (GetTerrain(GetTile(currX, currY)) == TERRAIN_TYPE_SECONDARY) + if (GetTerrainType(GetTile(currX, currY)) == TERRAIN_TYPE_SECONDARY) continue; // Check that the current tile is at least 2 away from the map border @@ -1887,13 +1903,13 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // Make sure the direction 90 degrees counterclockwise isn't an open tile checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; - if (GetTerrain(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) continue; // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; - if (GetTerrain(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) continue; // Number of steps to walk in one direction before turning @@ -1909,7 +1925,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s if (currX <= 1 || currY <= 1 || currX >= DUNGEON_MAX_SIZE_X - 1 || currY >= DUNGEON_MAX_SIZE_Y - 1) break; - if (GetTerrain(GetTile(currX, currY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX, currY)) == TERRAIN_TYPE_NORMAL) break; if (GetTile(currX, currY)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) break; @@ -1917,33 +1933,33 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s willNotMakeSquare = TRUE; // Check Bottom to Right - if ((GetTerrain(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX + 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrainType(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX + 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } // Check Top to Right - if ((GetTerrain(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX + 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrainType(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX + 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } // Check Bottom to Left - if ((GetTerrain(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX - 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrainType(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX - 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } // Check Top to Left - if ((GetTerrain(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX - 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrain(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) + if ((GetTerrainType(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX - 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) { willNotMakeSquare = FALSE; } @@ -1957,13 +1973,13 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // Make sure the direction 90 degrees counterclockwise isn't an open tile checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; - if (GetTerrain(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) break; // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; - if (GetTerrain(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) break; j--; @@ -2163,8 +2179,10 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz gUnknown_202F1AD = FALSE; } -#define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 -#define GENERATION_CONSTANT_MERGE_ROOMS_CHANCE 5 +// Todo: move to header +#define GENERATION_CONSTANT_MERGE_ROOMS_CHANCE 5 // (0 to 100) probability to merge two rooms together +#define GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE 60 // (0 to 100) probability that a room will not have imperfections, if it was already flagged for them +#define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 // (0 to 100) probability that a room will be flagged to have a secondary structure. /* * CreateRoomsAndAnchors - Creates the rectangle regions of open terrain for each room @@ -2963,4 +2981,549 @@ void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN } } +extern const bool8 gUnknown_80F6DD5[][NUM_DIRECTIONS]; + +/* + * GenerateRoomImperfections - Attempt to generate room imperfections for each room, if flagged to do so. + * + * Rooms are flagged for whether to allow imperfections in CreateRoomsAndAnchors. + * Each qualifying flagged room has a 40% chance to generate imperfections in the room. + * + * Imperfections are generated by randomly growing walls of the room inwards + * for a certain number of iterations, depending on the average length of the room. + * + * Each iteration will go in both a counterclockwise and clockwise generation movement (not necessarily for the same corner though) + * + * We pick a random corner, derive our direction from the movement being used, then seek up to 10 tiles for one to replace. + * We avoid getting too close to hallways and ensure our cardinal neighbor tiles match what we expect for open terrain. + */ +void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) +{ + s32 x, y; + + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + s32 counter, length; + // To have imperfections a room must: + // - be valid + // - not have been merged + // - be a room + // - be connected + // - not have a secondary structure + // - not be a maze room + // - be flagged to be made imperfect + if (grid[x][y].isInvalid) + continue; + if (grid[x][y].hasBeenMerged) + continue; + if (grid[x][y].isMerged) + continue; + if (!grid[x][y].isConnected) + continue; + if (!grid[x][y].isRoom) + continue; + if (grid[x][y].hasSecondaryStructure) + continue; + if (grid[x][y].isMazeRoom) + continue; + if (!grid[x][y].flagImperfect) + continue; + + // Roll for imperfections + // By default, is a 40% chance that the room will still have imperfections + if (DungeonRandInt(100) < GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE) + continue; + + length = grid[x][y].end.x - grid[x][y].start.x + (grid[x][y].end.y - grid[x][y].start.y); + length /= 4; + if (length == 0) + length = 1; + + // Shrink the room from its corners either in the x or y direction + // Repeat the number of times equal to the average room length + for (counter = 0; counter < length; counter++) { + s32 i, v; + for (i = 0; i < 2; i++) { + // Start from one of four corners + // i == 0 => fill in walls counterclockwise + // i == 1 => fill in walls clockwise + s32 pt_x, pt_y; + s32 moveX, moveY; + s32 startingCorner = DungeonRandInt(4); + + switch (startingCorner) { + // Top-left corner + case 0: + default: + pt_x = grid[x][y].start.x; + pt_y = grid[x][y].start.y; + if (i != 0) { + moveX = 1; + moveY = 0; + } + else { + moveX = 0; + moveY = 1; + } + break; + // Top-right corner + case 1: + pt_x = grid[x][y].end.x - 1; + pt_y = grid[x][y].start.y; + if (i != 0) { + moveX = 0; + moveY = 1; + } + else { + moveX = -1; + moveY = 0; + } + break; + // Bottom-right corner + case 2: + pt_x = grid[x][y].end.x - 1; + pt_y = grid[x][y].end.y - 1; + + if (i != 0) { + moveX = -1; + moveY = 0; + } + else { + moveX = 0; + moveY = -1; + } + break; + // Bottom-left corner + case 3: + pt_x = grid[x][y].start.x; + pt_y = grid[x][y].end.y - 1; + + if (i != 0) { + moveX = 0; + moveY = -1; + } + else { + moveX = 1; + moveY = 0; + } + break; + } + + // Search up to 10 tiles for a new tile to replace + // from the selected starting corner and direction + for (v = 0; v < 10; v++) { + // Make sure we're still in bounds + if (pt_x < grid[x][y].start.x || pt_x >= grid[x][y].end.x) + break; + if (pt_y < grid[x][y].start.y || pt_y >= grid[x][y].end.y) + break; + + if (GetTerrainType(GetTile(pt_x, pt_y)) == TERRAIN_TYPE_NORMAL) { + // Make sure there aren't any hallways within 2 spaces from the current tile + // If there are, skip filling it in + + s32 direction = DIRECTION_SOUTH; + while (direction < NUM_DIRECTIONS) { + s32 offsetX, offsetY; + s32 nextX = pt_x + gAdjacentTileOffsets[direction].x; + s32 nextY = pt_y + gAdjacentTileOffsets[direction].y; + + bool8 found = FALSE; + for (offsetY = -1; offsetY <= 1; offsetY++) { + for (offsetX = -1; offsetX <= 1; offsetX++) { + // Search for open terrain which is not a part of a room (a hallway) + Tile *tile = GetTile(nextX + offsetX, nextY + offsetY); + + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + continue; + if (tile->room == CORRIDOR_ROOM) { + found = TRUE; + } + + if (found) + break; + } + + if (found) + break; + } + + if (found) + break; + + direction++; + } + + // If direction == NUM_DIRECTIONS, we didn't find any hallways and are good to proceed + if (direction == NUM_DIRECTIONS) { + // Check that our cardinal neighbors' terrain types match what we expect for generating new tiles in this direction + // For example, if we're generating from the top-left corner, we should only expect tiles + // below us or to our right to have open terrain. If another tile does, we should stop + // because the resulting room may look strange otherwise + + direction = DIRECTION_SOUTH; + while (direction < NUM_DIRECTIONS) { + s32 nextX = gAdjacentTileOffsets[direction].x; + s32 nextY = gAdjacentTileOffsets[direction].y; + bool8 isOpen = (GetTerrainType(GetTile(pt_x + nextX, pt_y + nextY)) == TERRAIN_TYPE_NORMAL); + + if (gUnknown_80F6DD5[startingCorner][direction] != isOpen) + break; + + // Advance by 2 to only check cardinal directions + direction += 2; + } + + // If direction == NUM_DIRECTIONS, the neighbors match what we expect + if (direction == NUM_DIRECTIONS) { + // Fill in the current open floor tile with a wall + SetTerrainWall(GetTileSafe(pt_x, pt_y)); + } + } + + break; + } + else { + // The terrain is filled or already a wall, move to the next tile + pt_x += moveX; + pt_y += moveY; + } + } + } + } + } + } +} + +/* + * CreateHallway - Creates a hallway between two points. + * + * |---------B + * | + * A------| + * + * The hallway generated consists of two parallel paths connected by a perpendicular "kink" in the path + * The "kink" in a path occurs along (turn_x, turnY), which in practice is the grid cell boundary + * If the paths trace same line, no "kink" will be generated + * + * If generation runs into an existing open tile, creation stops prematurely (such as another hallway). + * + * The vertical flag specifies whether the hallway is being generated horizontally or vertically + */ +void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 turnX_, s32 turnY_) +{ + s32 startX = x; + s32 startY = y; + s32 turnX = turnX_; + s32 turnY = turnY_; + s32 counter; + + if (vertical) { + // Vertical hallway + + counter = 0; + // Create the vertical line between the starting point and the grid cell boundary + while (y != turnY) { + if (counter++ >= DUNGEON_MAX_SIZE_X) + return; // Sanity check! + + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileSafe(x, y)); + } + else { + // If we find open floor, stop here + // The hall has connected up to an existing hall + if (x != startX || y != startY) + return; + } + + if (y < turnY) { + y++; + } + else { + y--; + } + } + + counter = 0; + // Create the horizontal line to connect the horizontal lines at two different x values + while (x != endX) { + if (counter++ >= DUNGEON_MAX_SIZE_X) + return; // Sanity check! + + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileSafe(x, y)); + } + else { + if (x != startX || y != startY) + return; + } + + if (x < endX) { + x++; + } + else { + x--; + } + } + + counter = 0; + // Create the vertical line between the end point and the grid cell + while (y != endY) { + if (counter++ >= DUNGEON_MAX_SIZE_X) + return; + + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileSafe(x, y)); + } + else { + if (x != startX || y != startY) + return; + } + + if (y < endY) { + y++; + } + else { + y--; + } + } + } + else { + // Horizontal hallway + + counter = 0; + // Create the horizontal line between the starting point and the grid cell boundary + while (x != turnX) { + if (counter++ >= DUNGEON_MAX_SIZE_X) + return; // Sanity check! + + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileSafe(x, y)); + } + else { + // If we find open floor, stop here + // The hall has connected up to an existing hall + if (x != startX || y != startY) + return; + } + + if (x < turnX) { + x++; + } + else { + x--; + } + } + + counter = 0; + // Create the vertical line to connect the horizontal lines at two different y values + while (y != endY) { + if (counter++ >= DUNGEON_MAX_SIZE_X) + return; + + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileSafe(x, y)); + } + else { + if (x != startX || y != startY) + return; + } + + if (y < endY) { + y++; + } + else { + y--; + } + } + + counter = 0; + // Create the horizontal line between the end point and the grid cell + while (x != endX) { + if (counter++ >= DUNGEON_MAX_SIZE_X) + return; + + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileSafe(x, y)); + } + else { + if (x != startX || y != startY) + return; + } + + if (x < endX) { + x++; + } + else { + x--; + } + } + } +} + +/* + * EnsureConnectedGrid - Ensure the grid forms a connected graph (all valid cells are reachable) by adding hallways to unreachable cells + * + * If the unconnected cell is a hallway anchor, it will be ignored and filled in. + * If the unconnected cell is a room, it will check all adjacent directions for a connected room, then add a hallway between if found. + * + * If no eligible room is found, the room will be removed and filled back in. + */ +void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY) +{ + s32 x, y; + + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + // If any of these is TRUE, this cell is fine and we don't need to worry about it + if (grid[x][y].isInvalid) + continue; + if (grid[x][y].hasBeenMerged) + continue; + if (grid[x][y].isConnected) + continue; + + if (grid[x][y].isRoom && !grid[x][y].hasSecondaryStructure) { + // Unconnected room + s32 pt_x, pt_y; + s32 rnd_x = DungeonRandRange(grid[x][y].start.x + 1, grid[x][y].end.x - 1); + s32 rnd_y = DungeonRandRange(grid[x][y].start.y + 1, grid[x][y].end.y - 1); + + if (y > 0 && !grid[x][y - 1].isInvalid && !grid[x][y - 1].isMerged && grid[x][y - 1].isConnected) { + // Attempt to connect to the grid cell above if it's connected + if (grid[x][y - 1].isRoom) { + // Room, take random interior x coordinate + pt_x = DungeonRandRange(grid[x][y - 1].start.x + 1, grid[x][y - 1].end.x - 1); + pt_y = DungeonRandRange(grid[x][y - 1].start.y + 1, grid[x][y - 1].end.y - 1); // Unused + } + else { + // Anchor, take center x + pt_x = grid[x][y - 1].start.x; + pt_y = grid[x][y - 1].start.y; // Unused + } + + CreateHallway(rnd_x, grid[x][y].start.y, pt_x, grid[x][y - 1].end.y - 1, TRUE, listX[x], listY[y]); + + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToTop = TRUE; + grid[x][y - 1].connectedToBottom = TRUE; + } + else if (y < gridSizeY - 1 && !grid[x][y + 1].isInvalid && !grid[x][y + 1].isMerged && grid[x][y + 1].isConnected) { + // Attempt to connect to the grid cell below if it's connected + if (grid[x][y + 1].isRoom) { + // Room, take random interior x coordinate + pt_x = DungeonRandRange(grid[x][y + 1].start.x + 1, grid[x][y + 1].end.x - 1); + pt_y = DungeonRandRange(grid[x][y + 1].start.y + 1, grid[x][y + 1].end.y - 1); // Unused + } + else { + // Anchor, take center x + pt_x = grid[x][y + 1].start.x; + pt_y = grid[x][y + 1].start.y; // Unused + } + + CreateHallway(rnd_x, grid[x][y].end.y - 1, pt_x, grid[x][y + 1].start.y, TRUE, listX[x], listY[y + 1] - 1); + + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToBottom = TRUE; + grid[x][y + 1].connectedToTop = TRUE; + } + else if (x > 0 && !grid[x - 1][y].isInvalid && !grid[x - 1][y].isMerged && grid[x - 1][y].isConnected) { + // Attempt to connect to the grid cell left if it's connected + if (grid[x - 1][y].isRoom) { + // Room, take random interior y coordinate + pt_x = DungeonRandRange(grid[x - 1][y].start.x + 1, grid[x - 1][y].end.x - 1); //Unused + pt_y = DungeonRandRange(grid[x - 1][y].start.y + 1, grid[x - 1][y].end.y - 1); + } + else { + // Anchor, take center y + pt_x = grid[x - 1][y].start.x; // Unused + pt_y = grid[x - 1][y].start.y; + } + + // Typo? Would expect grid[x - 1][y].end.x - 1 for 3rd parameter + CreateHallway(grid[x][y].start.x, rnd_y, grid[x - 1][y].start.x - 1, pt_y, FALSE, listX[x], listY[y]); + + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToLeft = TRUE; + grid[x - 1][y].connectedToRight = TRUE; + } + else if (x < gridSizeX - 1 && !grid[x + 1][y].isInvalid && !grid[x + 1][y].isMerged && grid[x + 1][y].isConnected) { + // Attempt to connect to the grid cell right if it's connected + if (grid[x + 1][y].isRoom) { + // Room, take random interior y coordinate + pt_x = DungeonRandRange(grid[x + 1][y].start.x + 1, grid[x + 1][y].end.x - 1); // Unused + pt_y = DungeonRandRange(grid[x + 1][y].start.y + 1, grid[x + 1][y].end.y - 1); + } + else { + // Anchor, take center y + pt_x = grid[x + 1][y].start.x; // Unused + pt_y = grid[x + 1][y].start.y; + } + + CreateHallway(grid[x][y].end.x - 1, rnd_y, grid[x + 1][y].start.x, pt_y, FALSE, listX[x + 1] - 1, listY[y]); + + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToRight = TRUE; + grid[x + 1][y].connectedToLeft = TRUE; + } + } + else { + // Unconnected anchor, don't bother trying. + + // Just fill it in with wall tiles + Tile *tile = GetTileSafe(grid[x][y].start.x, grid[x][y].start.y); + SetTerrainWall(tile); + + // Also remove any spawn flags + // TODO: rename to spawn_or_visibility_flags stairs/item/trap + tile->unk4 &= ~(0x1); + tile->unk4 &= ~(0x2); + tile->unk4 &= ~(0x4); + } + } + } + + // If any rooms are still unconnected (meaning attempts to connect failed) + // Fill in the rooms + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + s32 curX, curY; + if (grid[x][y].isInvalid || grid[x][y].hasBeenMerged || grid[x][y].isConnected || grid[x][y].unk15) + continue; + + for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { + for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { + Tile *tile = GetTileSafe(curX, curY); + // Set it to wall terrain + SetTerrainWall(tile); + + // Remove any spawn flags + tile->unk4 &= ~(0x2); + tile->unk4 &= ~(0x1); + tile->unk4 &= ~(0x4); + + // Set room index to 0xFF (not a room) + tile->room = CORRIDOR_ROOM; + } + } + } + } +} + +/* + * SetTerrainObstacleChecked - Sets terrain on a specific tile as an obstacle (either a wall or secondary terrain) + * + * If secondary terrain is requested and the room indices match, secondary terrain (water/lava) will be placed for the tile. + * + * Otherwise, the tile will be a wall. + */ +void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomIndex) +{ + SetTerrainWall(tile); + if (useSecondaryTerrain && tile->room == roomIndex) { + SetTerrainSecondary(tile); + } +} + // From 445f0a84e2f2ae5dbca2afdfdc580ced104be44e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 11 Nov 2024 21:01:00 +0100 Subject: [PATCH 12/30] GenerateKecleonShop --- asm/code_804AFAC.s | 673 ---------------------------------- include/structs/map.h | 1 + include/structs/str_dungeon.h | 12 +- src/code_804AFAC_1.c | 269 +++++++++++++- src/trap_1.c | 14 +- 5 files changed, 272 insertions(+), 697 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 21d398fff..f8802bda4 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -6,679 +6,6 @@ .text - thumb_func_start sub_804E9DC -sub_804E9DC: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - movs r5, 0 - movs r0, 0x3 - mov r8, r0 - movs r7, 0x8 - ldr r3, _0804EAF0 - mov r9, r3 -_0804E9F2: - movs r4, 0 - adds r6, r5, 0x1 - mov r10, r6 -_0804E9F8: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - adds r6, r4, 0x1 - cmp r0, 0x1 - beq _0804EA0E - b _0804EB0E -_0804EA0E: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r0, 0xFF - bne _0804EAF4 - cmp r5, 0 - ble _0804EA4E - subs r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EA4E - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - strh r1, [r2] - adds r0, r1, 0 - mov r6, r8 - ands r0, r6 - cmp r0, 0x2 - bne _0804EA4E - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] -_0804EA4E: - cmp r4, 0 - ble _0804EA82 - subs r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EA82 - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - orrs r1, r7 - strh r1, [r2] - adds r0, r1, 0 - mov r6, r8 - ands r0, r6 - cmp r0, 0x2 - bne _0804EA82 - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] -_0804EA82: - adds r6, r4, 0x1 - cmp r4, 0x1E - bgt _0804EABA - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EABA - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - mov r12, r3 - orrs r1, r7 - strh r1, [r2] - adds r0, r1, 0 - mov r3, r8 - ands r0, r3 - cmp r0, 0x2 - bne _0804EABA - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] -_0804EABA: - cmp r5, 0x36 - bgt _0804EB0E - mov r0, r10 - adds r1, r4, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EB0E - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - orrs r1, r7 - strh r1, [r2] - adds r0, r1, 0 - mov r4, r8 - ands r0, r4 - cmp r0, 0x2 - bne _0804EB0E - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] - b _0804EB0E - .align 2, 0 -_0804EAF0: .4byte 0x0000fffc -_0804EAF4: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r0, 0xFE - bne _0804EB0E - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0xFF - strb r1, [r0, 0x9] -_0804EB0E: - adds r4, r6, 0 - cmp r4, 0x1F - bgt _0804EB16 - b _0804E9F8 -_0804EB16: - mov r5, r10 - cmp r5, 0x37 - bgt _0804EB1E - b _0804E9F2 -_0804EB1E: - bl sub_804EB30 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804E9DC - - thumb_func_start sub_804EB30 -sub_804EB30: - push {r4-r7,lr} - ldr r0, _0804EBB4 - ldr r6, [r0] - movs r2, 0 - movs r1, 0x1F - ldr r3, _0804EBB8 - adds r0, r6, r3 -_0804EB3E: - strh r2, [r0] - subs r0, 0x2 - subs r1, 0x1 - cmp r1, 0 - bge _0804EB3E - movs r5, 0 -_0804EB4A: - movs r4, 0 - adds r7, r5, 0x1 -_0804EB4E: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _0804EBA2 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r3, [r0, 0x9] - cmp r3, 0x1F - bhi _0804EBA2 - lsls r0, r3, 1 - ldr r2, _0804EBBC - adds r1, r6, r2 - adds r2, r1, r0 - movs r1, 0 - ldrsh r0, [r2, r1] - cmp r0, 0x1F - bgt _0804EBA2 - lsls r0, 2 - lsls r1, r3, 7 - adds r0, r1 - adds r0, r6, r0 - ldr r3, _0804EBC0 - adds r0, r3 - strh r5, [r0] - movs r3, 0 - ldrsh r0, [r2, r3] - lsls r0, 2 - adds r0, r1 - adds r0, r6, r0 - ldr r1, _0804EBC4 - adds r0, r1 - strh r4, [r0] - ldrh r0, [r2] - adds r0, 0x1 - strh r0, [r2] -_0804EBA2: - adds r4, 0x1 - cmp r4, 0x1F - ble _0804EB4E - adds r5, r7, 0 - cmp r5, 0x37 - ble _0804EB4A - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804EBB4: .4byte gDungeon -_0804EBB8: .4byte 0x00010882 -_0804EBBC: .4byte 0x00010844 -_0804EBC0: .4byte 0x00010884 -_0804EBC4: .4byte 0x00010886 - thumb_func_end sub_804EB30 - - thumb_func_start GenerateKecleonShop -GenerateKecleonShop: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x58 - str r0, [sp, 0x40] - str r1, [sp, 0x44] - mov r10, r2 - adds r4, r3, 0 - ldr r0, _0804EE90 - ldr r0, [r0] - mov r8, r0 - ldr r1, _0804EE94 - ldr r0, _0804EE98 - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - ldr r0, _0804EE9C - ldrb r0, [r0] - cmp r0, 0 - beq _0804EBF8 - b _0804EED4 -_0804EBF8: - bl sub_8043D10 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _0804EC06 - b _0804EED4 -_0804EC06: - cmp r4, 0 - bne _0804EC0C - b _0804EED4 -_0804EC0C: - movs r0, 0x64 - bl DungeonRandInt - cmp r4, r0 - bgt _0804EC18 - b _0804EED4 -_0804EC18: - movs r5, 0 - add r7, sp, 0x20 - adds r1, r7, 0 - mov r0, sp -_0804EC20: - strh r5, [r0] - strh r5, [r1] - adds r1, 0x2 - adds r0, 0x2 - adds r5, 0x1 - cmp r5, 0xE - ble _0804EC20 - movs r5, 0xC7 -_0804EC30: - movs r0, 0xF - bl DungeonRandInt - adds r4, r0, 0 - movs r0, 0xF - bl DungeonRandInt - lsls r4, 1 - mov r1, sp - adds r2, r1, r4 - movs r4, 0 - ldrsh r3, [r2, r4] - lsls r0, 1 - adds r1, r0 - ldrh r0, [r1] - strh r0, [r2] - strh r3, [r1] - subs r5, 0x1 - cmp r5, 0 - bge _0804EC30 - adds r6, r7, 0 - movs r5, 0xC7 -_0804EC5C: - movs r0, 0xF - bl DungeonRandInt - adds r4, r0, 0 - movs r0, 0xF - bl DungeonRandInt - lsls r4, 1 - adds r4, r6, r4 - movs r1, 0 - ldrsh r2, [r4, r1] - lsls r0, 1 - adds r0, r6, r0 - ldrh r1, [r0] - strh r1, [r4] - strh r2, [r0] - subs r5, 0x1 - cmp r5, 0 - bge _0804EC5C - movs r5, 0 -_0804EC84: - lsls r0, r5, 1 - add r0, sp - movs r3, 0 - ldrsh r2, [r0, r3] - mov r9, r2 - ldr r4, [sp, 0x44] - cmp r9, r4 - blt _0804EC96 - b _0804EECC -_0804EC96: - movs r4, 0 -_0804EC98: - lsls r0, r4, 1 - adds r0, r7, r0 - movs r2, 0 - ldrsh r1, [r0, r2] - cmp r1, r10 - blt _0804ECA6 - b _0804EEC4 -_0804ECA6: - lsls r1, 5 - mov r3, r9 - lsls r2, r3, 4 - subs r0, r2, r3 - lsls r0, 5 - ldr r3, [sp, 0x40] - adds r0, r3 - adds r3, r1, r0 - ldrb r0, [r3, 0x8] - str r1, [sp, 0x4C] - str r2, [sp, 0x48] - cmp r0, 0 - beq _0804ECC2 - b _0804EEC4 -_0804ECC2: - ldrb r0, [r3, 0x11] - cmp r0, 0 - beq _0804ECCA - b _0804EEC4 -_0804ECCA: - ldrb r0, [r3, 0x12] - cmp r0, 0 - beq _0804ECD2 - b _0804EEC4 -_0804ECD2: - ldrb r0, [r3, 0xB] - cmp r0, 0 - bne _0804ECDA - b _0804EEC4 -_0804ECDA: - ldrb r0, [r3, 0xA] - cmp r0, 0 - bne _0804ECE2 - b _0804EEC4 -_0804ECE2: - ldrb r0, [r3, 0x9] - cmp r0, 0 - beq _0804ECEA - b _0804EEC4 -_0804ECEA: - ldrb r0, [r3, 0x10] - cmp r0, 0 - beq _0804ECF2 - b _0804EEC4 -_0804ECF2: - ldrb r0, [r3, 0x1D] - cmp r0, 0 - beq _0804ECFA - b _0804EEC4 -_0804ECFA: - movs r0, 0x4 - ldrsh r1, [r3, r0] - movs r2, 0 - ldrsh r0, [r3, r2] - subs r1, r0 - cmp r1, 0 - bge _0804ED0A - negs r1, r1 -_0804ED0A: - cmp r1, 0x4 - bgt _0804ED10 - b _0804EEC4 -_0804ED10: - movs r0, 0x6 - ldrsh r1, [r3, r0] - movs r2, 0x2 - ldrsh r0, [r3, r2] - subs r1, r0 - cmp r1, 0 - bge _0804ED20 - negs r1, r1 -_0804ED20: - cmp r1, 0x3 - bgt _0804ED26 - b _0804EEC4 -_0804ED26: - ldr r1, _0804EEA0 - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x1 - strb r0, [r3, 0xC] - ldr r2, _0804EEA4 - movs r4, 0 - ldrsh r0, [r3, r4] - adds r0, 0x1 - str r0, [r2] - movs r7, 0x4 - ldrsh r0, [r3, r7] - subs r0, 0x1 - str r0, [r2, 0x8] - movs r0, 0x2 - ldrsh r1, [r3, r0] - adds r1, 0x1 - str r1, [r2, 0x4] - movs r4, 0x6 - ldrsh r3, [r3, r4] - subs r0, r3, 0x1 - str r0, [r2, 0xC] - subs r0, r1 - mov r10, r2 - cmp r0, 0x2 - bgt _0804ED5C - str r3, [r2, 0xC] -_0804ED5C: - ldr r0, _0804EEA8 - add r0, r8 - ldr r1, _0804EEAC - str r1, [r0] - ldr r0, _0804EEB0 - add r0, r8 - str r1, [r0] - ldr r0, _0804EEB4 - add r0, r8 - ldr r1, _0804EEB8 - str r1, [r0] - ldr r0, _0804EEBC - add r0, r8 - str r1, [r0] - mov r7, r10 - ldr r5, [r7] - ldr r0, [r7, 0x8] - cmp r5, r0 - bge _0804EDFA - mov r3, r10 -_0804ED84: - ldr r4, [r3, 0x4] - ldr r0, [r3, 0xC] - adds r1, r5, 0x1 - str r1, [sp, 0x54] - cmp r4, r0 - bge _0804EDF0 - ldr r6, _0804EEA8 - add r6, r8 - ldr r2, _0804EEA4 - mov r10, r2 -_0804ED98: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x50] - bl GetTileSafe - ldrh r2, [r0] - movs r1, 0x20 - orrs r1, r2 - strh r1, [r0] - ldrh r2, [r0, 0x4] - ldr r7, _0804EEC0 - adds r1, r7, 0 - ands r2, r1 - adds r7, 0x7 - adds r1, r7, 0 - ands r2, r1 - strh r2, [r0, 0x4] - ldr r0, [r6] - ldr r3, [sp, 0x50] - cmp r0, r5 - ble _0804EDC4 - str r5, [r6] -_0804EDC4: - ldr r1, _0804EEB0 - add r1, r8 - ldr r0, [r1] - cmp r0, r4 - ble _0804EDD0 - str r4, [r1] -_0804EDD0: - ldr r1, _0804EEB4 - add r1, r8 - ldr r0, [r1] - cmp r0, r5 - bge _0804EDDC - str r5, [r1] -_0804EDDC: - ldr r1, _0804EEBC - add r1, r8 - ldr r0, [r1] - cmp r0, r4 - bge _0804EDE8 - str r4, [r1] -_0804EDE8: - adds r4, 0x1 - ldr r0, [r3, 0xC] - cmp r4, r0 - blt _0804ED98 -_0804EDF0: - ldr r5, [sp, 0x54] - mov r1, r10 - ldr r0, [r1, 0x8] - cmp r5, r0 - blt _0804ED84 -_0804EDFA: - ldr r3, [sp, 0x4C] - ldr r2, [sp, 0x48] - mov r4, r9 - subs r0, r2, r4 - lsls r0, 5 - ldr r7, [sp, 0x40] - adds r1, r0, r7 - adds r0, r3, r1 - movs r4, 0 - ldrsh r5, [r0, r4] - movs r7, 0x4 - ldrsh r0, [r0, r7] - cmp r5, r0 - bge _0804EE6C - mov r8, r1 -_0804EE18: - mov r1, r9 - subs r0, r2, r1 - lsls r0, 5 - ldr r2, [sp, 0x40] - adds r0, r2 - adds r0, r3, r0 - movs r3, 0x2 - ldrsh r4, [r0, r3] - movs r7, 0x6 - ldrsh r0, [r0, r7] - adds r1, r5, 0x1 - str r1, [sp, 0x54] - cmp r4, r0 - bge _0804EE52 - ldr r6, [sp, 0x4C] - add r6, r8 -_0804EE38: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x10 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x1 - movs r2, 0x6 - ldrsh r0, [r6, r2] - cmp r4, r0 - blt _0804EE38 -_0804EE52: - ldr r5, [sp, 0x54] - ldr r3, [sp, 0x4C] - ldr r2, [sp, 0x48] - mov r4, r9 - subs r0, r2, r4 - lsls r0, 5 - ldr r7, [sp, 0x40] - adds r0, r7 - adds r0, r3, r0 - movs r1, 0x4 - ldrsh r0, [r0, r1] - cmp r5, r0 - blt _0804EE18 -_0804EE6C: - ldr r2, _0804EEA4 - ldr r0, [r2] - ldr r1, [r2, 0x8] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r5, r0, 1 - ldr r0, [r2, 0x4] - ldr r1, [r2, 0xC] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r4, r0, 1 - ldr r0, _0804EE94 - strh r5, [r0] - strh r4, [r0, 0x2] - b _0804EED4 - .align 2, 0 -_0804EE90: .4byte gDungeon -_0804EE94: .4byte gUnknown_202F1D8 -_0804EE98: .4byte 0x0000ffff -_0804EE9C: .4byte gUnknown_202F1AB -_0804EEA0: .4byte gUnknown_202F1AA -_0804EEA4: .4byte gUnknown_202F1B8 -_0804EEA8: .4byte 0x0000e240 -_0804EEAC: .4byte 0x0000270f -_0804EEB0: .4byte 0x0000e244 -_0804EEB4: .4byte 0x0000e248 -_0804EEB8: .4byte 0xffffd8f1 -_0804EEBC: .4byte 0x0000e24c -_0804EEC0: .4byte 0x0000fff7 -_0804EEC4: - adds r4, 0x1 - cmp r4, 0xE - bgt _0804EECC - b _0804EC98 -_0804EECC: - adds r5, 0x1 - cmp r5, 0xE - bgt _0804EED4 - b _0804EC84 -_0804EED4: - add sp, 0x58 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GenerateKecleonShop - thumb_func_start GenerateMonsterHouse GenerateMonsterHouse: push {r4-r7,lr} diff --git a/include/structs/map.h b/include/structs/map.h index 7e8e22a16..1f0c4c92c 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -5,6 +5,7 @@ #include "structs/str_position.h" #define MAX_ROOM_COUNT 32 // Empirical max, not sure if the code supports any more. +#define ROOM_0xFE 0xFE // Anchor? #define CORRIDOR_ROOM 0xFF enum TerrainType diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 3a10faf66..93871dfb8 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -230,6 +230,15 @@ struct MessageLogString u8 str[MESSAGE_LOG_BUFFER_SIZE]; }; +#define DEFAULT_MAX_POSITION 9999 +struct MinMaxPosition +{ + s32 minX; + s32 minY; + s32 maxX; + s32 maxY; +}; + // size: 0x1CEDC typedef struct Dungeon { @@ -350,8 +359,7 @@ typedef struct Dungeon Position unkE218; Position unkE21C; // stair location? Position unkE220[8]; - u32 unkE240; - u8 fillE244[0xE250 - 0xE244]; + struct MinMaxPosition kecleonShopPos; u32 unkE250; u8 fillE254[0xE260 - 0xE254]; u32 unkE260; diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 5e70d51bc..d0bdbed76 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -10,7 +10,7 @@ extern const u8 gUnknown_80F6DCC[]; extern struct FileArchive gDungeonFileArchive; -extern u8 gUnknown_202F1AA; +extern bool8 gUnknown_202F1AA; extern u8 gUnknown_202F1AB; extern u8 gUnknown_202F1AC; extern u8 gUnknown_202F1A8; @@ -25,15 +25,7 @@ extern s32 gUnknown_202F1D0; extern s32 gUnknown_202F1CC; extern Position gUnknown_202F1D8; -struct UnkStruct_202F1B8 -{ - s32 unk0; - s32 unk4; - s32 unk8; - s32 unkC; -}; - -extern struct UnkStruct_202F1B8 gUnknown_202F1B8; +extern struct MinMaxPosition gUnknown_202F1B8; extern void sub_804FD30(void); extern void sub_804FD30(void); @@ -42,7 +34,8 @@ extern void sub_804FCCC(void); extern void GenerateOneRoomMonsterHouseFloor(void); extern void sub_804FBE8(void); extern void sub_804FC74(void); -extern void sub_804E9DC(void); +void sub_804EB30(void); +void sub_804E9DC(void); extern void GenerateTwoRoomsWithMonsterHouseFloor(void); extern u8 sub_8043D10(); extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); @@ -107,7 +100,7 @@ void sub_804AFAC(void) UnkDungeonGlobal_unk1C574 *unkPtr = &gDungeon->unk1C574; gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); - gUnknown_202F1AA = 0; + gUnknown_202F1AA = FALSE; gUnknown_202F1AB = 0; gUnknown_202F1AC = 0; gUnknown_202F1A8 = (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_WATER); @@ -1015,7 +1008,7 @@ struct GridCell bool8 hasSecondaryStructure; bool8 isRoom; bool8 isConnected; - bool8 unk12; + bool8 isKecleonShop; bool8 unk13; bool8 isMonsterHouse; bool8 unk15; @@ -2052,7 +2045,7 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gri grid[x][y].isConnected = FALSE; grid[x][y].unk15 = FALSE; grid[x][y].isMonsterHouse = FALSE; - grid[x][y].unk12 = FALSE; + grid[x][y].isKecleonShop = FALSE; grid[x][y].connectedToRight = FALSE; grid[x][y].connectedToLeft = FALSE; grid[x][y].connectedToBottom = FALSE; @@ -2317,7 +2310,7 @@ void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s SetTerrainNormal(GetTileSafe(pt_x, pt_y)); // Set the room index to 0xFE for anchor - GetTileSafe(pt_x, pt_y)->room = 0xFE; + GetTileSafe(pt_x, pt_y)->room = ROOM_0xFE; } } } @@ -3526,4 +3519,250 @@ void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomInd } } +void sub_804E9DC(void) +{ + s32 x, y; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) + continue; + + if (GetTile(x, y)->room == CORRIDOR_ROOM) { + if (x > 0) { + Tile *tile = GetTileSafe(x - 1, y); + if (tile->room != CORRIDOR_ROOM) { + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + + if (GetTerrainType(tile) == TERRAIN_TYPE_SECONDARY) { + SetTerrainType(tile, TERRAIN_TYPE_NORMAL); + } + } + } + if (y > 0) { + Tile *tile = GetTileSafe(x, y - 1); + if (tile->room != CORRIDOR_ROOM) { + // Yes, these |= have to be duplicated in order to match. Either it's an error and they wanted to use a different flag, or just copy-pasted it twice. + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + if (GetTerrainType(tile) == TERRAIN_TYPE_SECONDARY) { + SetTerrainType(tile, TERRAIN_TYPE_NORMAL); + } + } + } + if (y < DUNGEON_MAX_SIZE_Y - 1) { + Tile *tile = GetTileSafe(x, y + 1); + if (tile->room != CORRIDOR_ROOM) { + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + if (GetTerrainType(tile) == TERRAIN_TYPE_SECONDARY) { + SetTerrainType(tile, TERRAIN_TYPE_NORMAL); + } + } + } + if (x < DUNGEON_MAX_SIZE_X - 1) { + Tile *tile = GetTileSafe(x + 1, y); + if (tile->room != CORRIDOR_ROOM) { + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + if (GetTerrainType(tile) == TERRAIN_TYPE_SECONDARY) { + SetTerrainType(tile, TERRAIN_TYPE_NORMAL); + } + } + } + } + else if (GetTile(x, y)->room == ROOM_0xFE) { + GetTileSafe(x, y)->room = CORRIDOR_ROOM; + } + } + } + sub_804EB30(); +} + +void sub_804EB30(void) +{ + s32 i; + s32 x, y; + Dungeon *dungeon = gDungeon; + + for (i = 0; i < MAX_ROOM_COUNT; i++) { + dungeon->naturalJunctionListCounts[i] = 0; + } + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (GetTile(x, y)->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) { + u32 roomIndex = GetTile(x, y)->room; + if (roomIndex < MAX_ROOM_COUNT && dungeon->naturalJunctionListCounts[roomIndex] < MAX_ROOM_COUNT) { + dungeon->naturalJunctionList[roomIndex][dungeon->naturalJunctionListCounts[roomIndex]].x = x; + dungeon->naturalJunctionList[roomIndex][dungeon->naturalJunctionListCounts[roomIndex]].y = y; + dungeon->naturalJunctionListCounts[roomIndex]++; + } + } + } + } +} + +/* + * GenerateKecleonShop - Potentially generate a kecleon shop on the floor. + * + * To spawn a kecleon shop, the floor cannot have a monster house, must not be a rescue floor, and must roll + * the percentage chance of kecleon_chance. + * + * Grid cells indices are shuffled, then each is checked to meet the conditions to spawn a kecleon shop in that cell: + * The room must be valid, connected, have no other special features, and have dimensions of at least 5x4. + * + * Once the first room (if any) is found that meets these conditions, the room is assigned as a kecleon shop. + * The kecleon shop will occupy the whole room interior, with a one tile margin from the room walls. + * Kecleon shop tiles restrict monster and stair spawns. + */ +void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) +{ + s16 listX[GRID_CELL_LEN]; + s16 listY[GRID_CELL_LEN]; + s32 x, y; + s32 i, j; + Dungeon *dungeon = gDungeon; + + gUnknown_202F1D8.x = -1; + gUnknown_202F1D8.y = -1; + + if (gUnknown_202F1AB || sub_8043D10() == 2 || chance == 0) + return; + if (chance <= DungeonRandInt(100)) + return; + + // All possible grid cells + for (i = 0; i < GRID_CELL_LEN; i++) { + listX[i] = i; + listY[i] = i; + } + + // Shuffle x indices + for (i = 0; i < 200; i++) { + s32 temp; + s32 a = DungeonRandInt(GRID_CELL_LEN); + s32 b = DungeonRandInt(GRID_CELL_LEN); + + SWAP(listX[a], listX[b], temp); + } + + // Shuffle y indices + for (i = 0; i < 200; i++) { + s32 temp; + s32 a = DungeonRandInt(GRID_CELL_LEN); + s32 b = DungeonRandInt(GRID_CELL_LEN); + + SWAP(listY[a], listY[b], temp); + } + + for (i = 0; i < GRID_CELL_LEN; i++) { + x = listX[i]; + if (x >= gridSizeX) + continue; + + for (j = 0; j < GRID_CELL_LEN; j++) { + s32 curX, curY; + + y = listY[j]; + if (y >= gridSizeY) + continue; + + // We've identified a random in-bounds grid cell + // To support a kecleon shop it must be: + // - valid + // - not a merged room + // - connected + // - a room + // - have no other special features (mazes/secondary structures) + // - have dimensions of at least 5x4 + if (grid[x][y].isInvalid) + continue; + if (grid[x][y].hasBeenMerged) + continue; + if (grid[x][y].isMerged) + continue; + if (!grid[x][y].isConnected) + continue; + if (!grid[x][y].isRoom) + continue; + if (grid[x][y].hasSecondaryStructure) + continue; + if (grid[x][y].isMazeRoom) + continue; + if (grid[x][y].flagSecondaryStructure) + continue; + + if (abs(grid[x][y].end.x - grid[x][y].start.x) < 5 || abs(grid[x][y].end.y - grid[x][y].start.y) < 4) + continue; + + // This room can be a kecleon shop + gUnknown_202F1AA = TRUE; + grid[x][y].isKecleonShop = TRUE; + + // Make the shop span the whole room + gUnknown_202F1B8.minX = grid[x][y].start.x + 1; + gUnknown_202F1B8.maxX = grid[x][y].end.x - 1; + gUnknown_202F1B8.minY = grid[x][y].start.y + 1; + gUnknown_202F1B8.maxY = grid[x][y].end.y - 1; + + if (gUnknown_202F1B8.maxY - gUnknown_202F1B8.minY < 3) { + // This should never happen? + gUnknown_202F1B8.maxY++; + } + + // Set to values that guarantee they'll be replaced later + dungeon->kecleonShopPos.minX = DEFAULT_MAX_POSITION; + dungeon->kecleonShopPos.minY = DEFAULT_MAX_POSITION; + dungeon->kecleonShopPos.maxX = -DEFAULT_MAX_POSITION; + dungeon->kecleonShopPos.maxY = -DEFAULT_MAX_POSITION; + + // Generate the actual shop on the interior, leaving + // a 1-tile border from the room walls + for (curX = gUnknown_202F1B8.minX; curX < gUnknown_202F1B8.maxX; curX++) { + for (curY = gUnknown_202F1B8.minY; curY < gUnknown_202F1B8.maxY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + tile->terrainType |= TERRAIN_TYPE_SHOP; + + // Restrict monsters and stairs from spawning here + tile->unk4 &= ~(0x8); + tile->unk4 &= ~(0x1); + + // Ensure the borders are assigned properly + if (dungeon->kecleonShopPos.minX > curX) { + dungeon->kecleonShopPos.minX = curX; + } + + if (dungeon->kecleonShopPos.minY > curY) { + dungeon->kecleonShopPos.minY = curY; + } + + if (dungeon->kecleonShopPos.maxX < curX) { + dungeon->kecleonShopPos.maxX = curX; + } + + if (dungeon->kecleonShopPos.maxY < curY) { + dungeon->kecleonShopPos.maxY = curY; + } + } + } + + // Sets an unknown spawn flag for all tiles in the room + for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { + for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { + GetTileSafe(curX, curY)->unk4 |= 0x10; + } + } + + curX = (gUnknown_202F1B8.minX + gUnknown_202F1B8.maxX) / 2; + curY = (gUnknown_202F1B8.minY + gUnknown_202F1B8.maxY) / 2; + gUnknown_202F1D8.x = curX; + gUnknown_202F1D8.y = curY; + + return; + } + } +} + // diff --git a/src/trap_1.c b/src/trap_1.c index 26f7f947b..04c7e0134 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -17,7 +17,7 @@ extern u8 gYayoiSan[]; extern void sub_8082FA8(unkStruct_8094924 *, void *, s32); void SaveTile(unkStruct_8094924 *r0, Tile *tile); -void sub_80830F8(void * , u32*); +void sub_80830F8(void * , void*); void sub_808312C(void *, u32 *); void SaveDungeonWeather(unkStruct_8094924 *r0, Weather *weather); void sub_8083078(void *, u32); @@ -87,8 +87,8 @@ u8 sub_8083188(unkStruct_8094924 *r0); s16 sub_8083170(unkStruct_8094924 *r0); void sub_80831F8(unkStruct_8094924 *r0, Position *); void RestoreDungeonWeather(unkStruct_8094924 *r0, Weather *); -void sub_8083220(unkStruct_8094924 *r0, u32 *); -void sub_8083260(unkStruct_8094924 *r0, u32 *); +void sub_8083220(unkStruct_8094924 *r0, void *); +void sub_8083260(unkStruct_8094924 *r0, void *); void RestoreTile(unkStruct_8094924 *r0, Tile *); extern u16 sub_8083158(unkStruct_8094924 *param_1); void sub_80820A8(unkStruct_8094924 *r0, Item *); @@ -513,7 +513,7 @@ void sub_8081454(unkStruct_8094924 *param_1) { SavePosition(param_1,&gDungeon->unkE220[iVar4]); } - sub_80830F8(param_1,&gDungeon->unkE240); + sub_80830F8(param_1,&gDungeon->kecleonShopPos); sub_80830F8(param_1,&gDungeon->unkE250); sub_808312C(param_1,&gDungeon->unkE260); @@ -846,9 +846,9 @@ void sub_8081C7C(unkStruct_8094924 *r0) { sub_80831F8(r0,&gDungeon->unkE220[iVar7]); } - sub_8083220(r0,&gDungeon->unkE240); - sub_8083220(r0,&gDungeon->unkE240 + 0x4); - sub_8083260(r0,&gDungeon->unkE240 + 0x8); + sub_8083220(r0,&gDungeon->kecleonShopPos); + sub_8083220(r0,&gDungeon->unkE250); + sub_8083260(r0,&gDungeon->unkE260); for(y = 0; y < 8; y++) From 366690ced99d793d67309133678f428f9be9d2f2 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 11 Nov 2024 21:44:55 +0100 Subject: [PATCH 13/30] GenerateMonsterHouse --- asm/code_8040094.s | 6 +- asm/code_804AFAC.s | 264 ----------------------------------- asm/code_804FD30.s | 2 +- asm/code_805D8C8.s | 4 +- include/dungeon_generation.h | 18 +++ src/code_803D110.c | 4 +- src/code_804267C.c | 4 +- src/code_8042B34.c | 13 +- src/code_8044CC8.c | 4 +- src/code_804AFAC_1.c | 138 ++++++++++++++++-- src/dungeon_action.c | 4 +- src/status.c | 4 +- src/trap.c | 4 +- 13 files changed, 172 insertions(+), 297 deletions(-) create mode 100644 include/dungeon_generation.h diff --git a/asm/code_8040094.s b/asm/code_8040094.s index 50633499f..ff84e1e29 100644 --- a/asm/code_8040094.s +++ b/asm/code_8040094.s @@ -285,7 +285,7 @@ _08040370: mov r7, r10 ands r7, r0 _08040378: - bl sub_8043D10 + bl GetFloorType lsls r0, 24 cmp r0, 0 bne _08040398 @@ -498,7 +498,7 @@ _08040500: ands r0, r1 cmp r0, 0 beq _08040548 - bl sub_8043D10 + bl GetFloorType lsls r0, 24 movs r6, 0x5 cmp r0, 0 @@ -513,7 +513,7 @@ _08040528: ands r0, r1 cmp r0, 0 beq _08040548 - bl sub_8043D10 + bl GetFloorType lsls r0, 24 movs r6, 0x5 cmp r0, 0 diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index f8802bda4..5ba7d6944 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -5,270 +5,6 @@ .text - - thumb_func_start GenerateMonsterHouse -GenerateMonsterHouse: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x108 - str r0, [sp, 0x100] - mov r8, r1 - adds r7, r2, 0 - adds r4, r3, 0 - ldr r5, _0804F094 - ldr r0, [r5] - str r0, [sp, 0x104] - cmp r4, 0 - bne _0804EF04 - b _0804F0C0 -_0804EF04: - movs r0, 0x64 - bl DungeonRandInt - cmp r4, r0 - bgt _0804EF10 - b _0804F0C0 -_0804EF10: - ldr r0, _0804F098 - ldrb r0, [r0] - cmp r0, 0 - beq _0804EF1A - b _0804F0C0 -_0804EF1A: - ldr r0, [r5] - movs r1, 0xD1 - lsls r1, 3 - adds r0, r1 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, 0 - beq _0804EF2C - b _0804F0C0 -_0804EF2C: - bl sub_8043D10 - lsls r0, 24 - cmp r0, 0 - beq _0804EF38 - b _0804F0C0 -_0804EF38: - movs r6, 0 - movs r1, 0 - cmp r1, r8 - bge _0804EF94 -_0804EF40: - adds r2, r1, 0x1 - cmp r7, 0 - ble _0804EF8E - lsls r0, r1, 4 - subs r0, r1 - lsls r0, 5 - ldr r1, [sp, 0x100] - adds r1, 0x8 - adds r1, r0, r1 - adds r3, r7, 0 -_0804EF54: - ldrb r0, [r1] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x9] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x3] - cmp r0, 0 - beq _0804EF86 - ldrb r0, [r1, 0x2] - cmp r0, 0 - beq _0804EF86 - ldrb r0, [r1, 0x4] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x7] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x8] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x1] - cmp r0, 0 - bne _0804EF86 - adds r6, 0x1 -_0804EF86: - adds r1, 0x20 - subs r3, 0x1 - cmp r3, 0 - bne _0804EF54 -_0804EF8E: - adds r1, r2, 0 - cmp r1, r8 - blt _0804EF40 -_0804EF94: - cmp r6, 0 - bne _0804EF9A - b _0804F0C0 -_0804EF9A: - movs r1, 0 - mov r0, sp - adds r0, 0xFF -_0804EFA0: - strb r1, [r0] - subs r0, 0x1 - cmp r0, sp - bge _0804EFA0 - mov r1, sp - movs r0, 0x1 - strb r0, [r1] - movs r5, 0x3F -_0804EFB0: - adds r0, r6, 0 - bl DungeonRandInt - adds r4, r0, 0 - adds r0, r6, 0 - bl DungeonRandInt - mov r3, sp - adds r2, r3, r4 - ldrb r3, [r2] - mov r4, sp - adds r1, r4, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - subs r5, 0x1 - cmp r5, 0 - bge _0804EFB0 - movs r5, 0 - movs r1, 0 - cmp r1, r8 - bge _0804F0C0 - ldr r6, [sp, 0x100] - mov r9, r6 - movs r4, 0 -_0804EFE2: - movs r3, 0 - cmp r3, r7 - bge _0804F0B2 - mov r10, r3 - lsls r0, r4, 5 - ldr r6, [sp, 0x100] - adds r2, r0, r6 -_0804EFF0: - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0x11] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804F0A6 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804F0A6 - ldrb r0, [r2, 0xC] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0xF] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0x10] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0x9] - cmp r0, 0 - bne _0804F0A6 - mov r6, sp - adds r0, r6, r5 - ldrb r0, [r0] - cmp r0, 0 - beq _0804F0A4 - ldr r1, _0804F09C - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x1 - strb r0, [r2, 0xE] - movs r0, 0 - ldrsh r5, [r2, r0] - movs r1, 0x4 - ldrsh r0, [r2, r1] - cmp r5, r0 - bge _0804F0C0 - mov r2, r10 - add r2, r9 - mov r8, r2 -_0804F046: - mov r1, r10 - add r1, r9 - movs r3, 0x2 - ldrsh r4, [r1, r3] - movs r6, 0x6 - ldrsh r0, [r1, r6] - adds r7, r5, 0x1 - cmp r4, r0 - bge _0804F086 - adds r6, r1, 0 -_0804F05A: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - movs r1, 0x40 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r1, [r0, 0x9] - ldr r2, [sp, 0x104] - ldr r3, _0804F0A0 - adds r0, r2, r3 - strb r1, [r0] - adds r4, 0x1 - movs r1, 0x6 - ldrsh r0, [r6, r1] - cmp r4, r0 - blt _0804F05A -_0804F086: - adds r5, r7, 0 - mov r2, r8 - movs r3, 0x4 - ldrsh r0, [r2, r3] - cmp r5, r0 - blt _0804F046 - b _0804F0C0 - .align 2, 0 -_0804F094: .4byte gDungeon -_0804F098: .4byte gUnknown_202F1AA -_0804F09C: .4byte gUnknown_202F1AB -_0804F0A0: .4byte 0x00003a0c -_0804F0A4: - adds r5, 0x1 -_0804F0A6: - movs r6, 0x20 - add r10, r6 - adds r2, 0x20 - adds r3, 0x1 - cmp r3, r7 - blt _0804EFF0 -_0804F0B2: - movs r0, 0xF0 - lsls r0, 1 - add r9, r0 - adds r4, 0xF - adds r1, 0x1 - cmp r1, r8 - blt _0804EFE2 -_0804F0C0: - add sp, 0x108 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GenerateMonsterHouse - thumb_func_start GenerateMazeRoom GenerateMazeRoom: push {r4-r7,lr} diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index e8517f86b..350c44135 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -125,7 +125,7 @@ _0804FFAA: ldr r0, _08050240 add r0, r9 strh r1, [r0] - bl sub_8043D10 + bl GetFloorType lsls r0, 24 lsrs r0, 24 cmp r0, 0x2 diff --git a/asm/code_805D8C8.s b/asm/code_805D8C8.s index a4d028c38..a38de0a22 100644 --- a/asm/code_805D8C8.s +++ b/asm/code_805D8C8.s @@ -5979,7 +5979,7 @@ sub_80649A0: bl sub_803ECB4 movs r0, 0 bl sub_80073B8 - bl sub_8043D10 + bl GetFloorType lsls r0, 24 lsrs r0, 24 cmp r0, 0x1 @@ -6109,7 +6109,7 @@ _08064A58: ldr r0, [sp, 0xE4] movs r1, 0 bl sub_803ECB4 - bl sub_8043D10 + bl GetFloorType adds r4, r0, 0 lsls r4, 24 lsrs r4, 24 diff --git a/include/dungeon_generation.h b/include/dungeon_generation.h new file mode 100644 index 000000000..fd49803bb --- /dev/null +++ b/include/dungeon_generation.h @@ -0,0 +1,18 @@ +#ifndef GUARD_DUNGEON_GENERATION_H +#define GUARD_DUNGEON_GENERATION_H + +/* + * Defines key constant values for floor generation, providing a way + * to modify these constants if desired. + */ +#define GENERATION_CONSTANT_MERGE_ROOMS_CHANCE 5 // (0 to 100) probability to merge two rooms together +#define GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE 60 // (0 to 100) probability that a room will not have imperfections, if it was already flagged for them +#define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 // (0 to 100) probability that a room will be flagged to have a secondary structure. + +enum FloorType { + FLOOR_TYPE_NORMAL, + FLOOR_TYPE_FIXED, // Fixed room + FLOOR_TYPE_RESCUE, // Rescuing another player +}; + +#endif diff --git a/src/code_803D110.c b/src/code_803D110.c index 937591752..a9c1f6789 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -18,7 +18,7 @@ extern u32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0); extern void sub_808E9C4(UnkDungeonGlobal_unk1CD98 *r0, s16 r1); extern u8 GetBodySize(s16 index); extern bool8 sub_80848EC(void); -extern u8 sub_8043D10(void); +extern u8 GetFloorType(void); extern const u8 *GetDungeonName2(u8 dungeon); extern void sub_8008DC8(s32 r0, s32 r1, u16 r2, u16 r3); @@ -1066,7 +1066,7 @@ void sub_803E13C(void) void sub_803E178(void) { - s32 val = sub_8043D10(); + s32 val = GetFloorType(); if (val == 0) { if (gDungeon->dungeonLocation.id == DUNGEON_METEOR_CAVE && !gDungeon->deoxysDefeat) { diff --git a/src/code_804267C.c b/src/code_804267C.c index 9983217bb..5a79a22fc 100644 --- a/src/code_804267C.c +++ b/src/code_804267C.c @@ -29,7 +29,7 @@ extern void sub_80429A0(Entity *); extern void sub_8042B34(u32, u32, u32); extern bool8 sub_8042CC0(void); extern void sub_8042D7C(void); -extern u8 sub_8043D10(void); +extern u8 GetFloorType(void); extern bool8 sub_8045888(Entity *); // This func plays the appropriate ascend/descend SFX for stairs depending on the direction @@ -39,7 +39,7 @@ void PlayStairsSound(void) songIndex = 997; - switch (sub_8043D10()) { + switch (GetFloorType()) { case 0: default: songIndex = IsStairDirectionUp(gDungeon->dungeonLocation.id) ? 340 : 341; diff --git a/src/code_8042B34.c b/src/code_8042B34.c index 5fdc960d7..62d442818 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -8,6 +8,7 @@ #include "code_800E9A8.h" #include "dungeon_util.h" #include "dungeon_message.h" +#include "dungeon_generation.h" #include "bg_control.h" #include "random.h" #include "file_system.h" @@ -390,7 +391,7 @@ extern Entity *gLeaderPointer; void sub_8044124(void); void sub_8043FD0(void); void sub_806B404(void); -u8 sub_8043D10(void); +u8 GetFloorType(void); extern const u8 *gUnknown_80FEC48; extern const u8 *gUnknown_80FEC7C; @@ -871,7 +872,7 @@ void xxx_dungeon_8042F6C(struct UnkStruct_xxx_dungeon_8042F6C *r8) sub_8083AB0(var, NULL, GetLeader()); check = TRUE; } - else if (gDungeon->unk678 == 1 && sub_8043D10() == 2 && gDungeon->unk654 == 2) { + else if (gDungeon->unk678 == 1 && GetFloorType() == FLOOR_TYPE_RESCUE && gDungeon->unk654 == 2) { sub_8083AB0(0x228, NULL, GetLeader()); if (gDungeon->unk66E != 0) { sub_8097810(); @@ -993,14 +994,14 @@ bool8 sub_8043CE4(s32 dungeonId) return (gDungeonWaterType[dungeonId] == 2); } -u8 sub_8043D10(void) +u8 GetFloorType(void) { if (gDungeon->unk678 == 1 && gDungeon->unk64C.unk1 == gDungeon->dungeonLocation.floor) - return 2; + return FLOOR_TYPE_RESCUE; else if (IsBossFight()) - return 1; + return FLOOR_TYPE_FIXED; else - return 0; + return FLOOR_TYPE_NORMAL; } void sub_8043D50(s32 *a0, s32 *a1) diff --git a/src/code_8044CC8.c b/src/code_8044CC8.c index 0b2c75b9e..a291cd59c 100644 --- a/src/code_8044CC8.c +++ b/src/code_8044CC8.c @@ -21,7 +21,7 @@ extern s32 gUnknown_202EE6C; bool8 sub_80461C8(Position *, u32); void sub_80460F8(Position *, Item *, u32); -extern u8 sub_8043D10(void); +extern u8 GetFloorType(void); extern bool8 sub_8045888(Entity *); EWRAM_DATA struct unkStruct_202EE44 gUnknown_202EE44[10] = {0}; @@ -156,7 +156,7 @@ u8 *sub_8044EC8(s32 param_1) uVar1 = gUnknown_202EE44[param_1].unk0; - if ((uVar1 == 0x26) && (sub_8043D10() == 2)) { + if ((uVar1 == 0x26) && (GetFloorType() == 2)) { return *gUnknown_80F91EC; } else { diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index d0bdbed76..06992aad3 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -1,4 +1,5 @@ #include "global.h" +#include "dungeon_generation.h" #include "file_system.h" #include "tile_types.h" #include "dungeon_map_access.h" @@ -37,7 +38,7 @@ extern void sub_804FC74(void); void sub_804EB30(void); void sub_804E9DC(void); extern void GenerateTwoRoomsWithMonsterHouseFloor(void); -extern u8 sub_8043D10(); +extern u8 GetFloorType(); extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); @@ -285,7 +286,7 @@ void sub_804AFAC(void) sub_804FBE8(); if (gDungeon->unkE218.x != -1 && gDungeon->unkE218.y != -1) { - if (sub_8043D10() == 1) + if (GetFloorType() == 1) break; if (gDungeon->unkE21C.x != -1 && gDungeon->unkE21C.y != -1 && sub_8050C30(gDungeon->unkE21C.x, gDungeon->unkE21C.y, 0)) break; @@ -828,7 +829,7 @@ void NAKED sub_804AFAC(void) " ldrsh r0, [r0, r6]\n" " cmp r0, r4\n" " beq _0804B42A\n" -" bl sub_8043D10\n" +" bl GetFloorType\n" " lsls r0, 24\n" " lsrs r0, 24\n" " cmp r0, 0x1\n" @@ -2172,11 +2173,6 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz gUnknown_202F1AD = FALSE; } -// Todo: move to header -#define GENERATION_CONSTANT_MERGE_ROOMS_CHANCE 5 // (0 to 100) probability to merge two rooms together -#define GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE 60 // (0 to 100) probability that a room will not have imperfections, if it was already flagged for them -#define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 // (0 to 100) probability that a room will be flagged to have a secondary structure. - /* * CreateRoomsAndAnchors - Creates the rectangle regions of open terrain for each room * leaving a margin relative to the border @@ -3627,7 +3623,7 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gUnknown_202F1D8.x = -1; gUnknown_202F1D8.y = -1; - if (gUnknown_202F1AB || sub_8043D10() == 2 || chance == 0) + if (gUnknown_202F1AB || GetFloorType() == FLOOR_TYPE_RESCUE || chance == 0) return; if (chance <= DungeonRandInt(100)) return; @@ -3765,4 +3761,128 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 } } +/* + * GenerateMonsterHouse - Possibly generate a monster house on the floor. + * + * A Monster House will be generated with a probability determined by the Monster House spawn chance, and only + * if the floor supports one (no kecleon shop, no non-MH outlaw missions, no special floor types) + * + * A Monster House will be generated in a random room that's valid, connected, not merged, not a maze room, and + * is not a few unknown conditions. + */ +void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) +{ + // To spawn a monster house on this floor: + // - It must meet the probability chance + // - not have a kecleon shop + // - Be an outlaw monster house floor or not be a special destination floor with a target + // - Be a Normal Floor Type + + s32 i; + bool8 values[256]; + s32 x, y; + s32 numValid; + Dungeon *dungeon = gDungeon; + + if (chance == 0 || chance <= DungeonRandInt(100)) + return; + if (gUnknown_202F1AA) + return; + if (gDungeon->unk688 != 0) + return; + if (GetFloorType() != FLOOR_TYPE_NORMAL) + return; + + numValid = 0; + + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + // A grid cell can have a monster house if it: + // - is valid + // - is not a merged room + // - is connected + // - is a room + // - is not a maze + // - and some other unknown condition + if (grid[x][y].isInvalid) + continue; + if (grid[x][y].hasBeenMerged) + continue; + if (!grid[x][y].isConnected) + continue; + if (!grid[x][y].isRoom) + continue; + if (grid[x][y].isKecleonShop) + continue; + if (grid[x][y].unk15) + continue; + if (grid[x][y].isMazeRoom) + continue; + if (grid[x][y].hasSecondaryStructure) + continue; + + numValid++; + } + } + + if (numValid == 0) + return; + + // Have a single 1, the rest as 0's + for (i = 0; i < 256; i++) { + values[i] = FALSE; + } + values[0] = TRUE; + + // Shuffle values + for (i = 0; i < 64; i++) { + s32 temp; + s32 a = DungeonRandInt(numValid); + s32 b = DungeonRandInt(numValid); + + SWAP(values[a], values[b], temp); + } + + // Counter + i = 0; + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + if (grid[x][y].isInvalid) + continue; + if (grid[x][y].hasBeenMerged) + continue; + if (!grid[x][y].isConnected) + continue; + if (!grid[x][y].isRoom) + continue; + if (grid[x][y].isKecleonShop) + continue; + if (grid[x][y].unk15) + continue; + if (grid[x][y].isMazeRoom) + continue; + if (grid[x][y].hasSecondaryStructure) + continue; + + if (values[i]) { + s32 curX, curY; + // The selected room can support a monster house + // Generate one! + gUnknown_202F1AB = TRUE; + grid[x][y].isMonsterHouse = TRUE; + + for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { + for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { + GetTileSafe(curX, curY)->terrainType |= TERRAIN_TYPE_IN_MONSTER_HOUSE; + dungeon->unk3A0C = GetTile(curX, curY)->room; + } + } + return; + } + + i++; + } + } +} + // diff --git a/src/dungeon_action.c b/src/dungeon_action.c index 436c0fd25..9eafa3880 100644 --- a/src/dungeon_action.c +++ b/src/dungeon_action.c @@ -27,7 +27,7 @@ extern const ItemText gActions[]; extern void sub_8071B48(void); extern void sub_8043ED0(u32); -extern u8 sub_8043D10(void); +extern u8 GetFloorType(void); extern bool8 sub_8044B28(void); extern void sub_8086AC0(void); extern void sub_8043ED0(u32); @@ -199,7 +199,7 @@ u8 *sub_8044BA8(u16 param_1, u8 id) u32 uVar3; u32 uVar4; - if ((param_1 == 0x26) && (sub_8043D10() == 2)) { + if ((param_1 == 0x26) && (GetFloorType() == 2)) { return *gUnknown_80F91EC; } else { diff --git a/src/status.c b/src/status.c index 781895657..15520a96b 100644 --- a/src/status.c +++ b/src/status.c @@ -141,7 +141,7 @@ extern void sub_804178C(u32); extern void sub_8041D5C(Entity *); extern void sub_8041D48(Entity *); extern void sub_8041D38(Entity * pokemon); -extern u8 sub_8043D10(void); +extern u8 GetFloorType(void); extern void sub_8041CDC(Entity *pokemon); extern void sub_8041CEC(Entity *pokemon); extern void nullsub_73(Entity *); @@ -741,7 +741,7 @@ void HandleScannerOrb(Entity* pokemon, Entity* target) void HandleStairsOrb(Entity* pokemon, Entity* target) { if (EntityExists(target)) { - if(sub_8043D10()) + if(GetFloorType()) { TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FAF3C); } diff --git a/src/trap.c b/src/trap.c index 54f96b19e..5456a80b9 100644 --- a/src/trap.c +++ b/src/trap.c @@ -73,7 +73,7 @@ bool8 sub_806AA0C(s32, s32); void sub_80421EC(Position *, u32); bool8 sub_8045888(Entity *); -u8 sub_8043D10(void); +u8 GetFloorType(void); void sub_8068FE0(Entity *, u32, Entity *); void sub_8045C28(Item *, u8 , u8); void sub_8045BF8(u8 *, Item *); @@ -551,7 +551,7 @@ void HandlePitfallTrap(Entity *pokemon, Entity *target, Tile *tile) sub_803E708(0x1e,0x48); } if (info->isTeamLeader) { - if (sub_8043D10() != 2) { + if (GetFloorType() != 2) { info->unk15C = 1; info->unk15E = 1; sub_803E708(0x28,0x4b); From f97df99fdf73f447bc1310c83eaaa5e3c8442fa8 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 12 Nov 2024 10:14:06 +0100 Subject: [PATCH 14/30] IsNextToHallway --- asm/code_804AFAC.s | 801 +------------------------------------------ src/code_804AFAC_1.c | 353 ++++++++++++++++++- 2 files changed, 356 insertions(+), 798 deletions(-) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 5ba7d6944..be57e660a 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -5,792 +5,7 @@ .text - thumb_func_start GenerateMazeRoom -GenerateMazeRoom: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x104 - str r0, [sp, 0x100] - mov r10, r1 - mov r9, r2 - adds r4, r3, 0 - ldr r0, _0804F244 - ldr r5, [r0] - cmp r4, 0 - bne _0804F0EE - b _0804F266 -_0804F0EE: - movs r0, 0x64 - bl DungeonRandInt - cmp r4, r0 - bgt _0804F0FA - b _0804F266 -_0804F0FA: - ldr r1, _0804F248 - adds r0, r5, r1 - movs r3, 0 - ldrsh r0, [r0, r3] - cmp r0, 0 - blt _0804F108 - b _0804F266 -_0804F108: - movs r5, 0 - movs r6, 0 - cmp r6, r10 - bge _0804F184 -_0804F110: - adds r7, r6, 0x1 - mov r4, r9 - cmp r4, 0 - ble _0804F17E - lsls r0, r6, 4 - subs r0, r6 - lsls r0, 5 - ldr r6, [sp, 0x100] - adds r2, r0, r6 -_0804F122: - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0x11] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804F176 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804F176 - ldrb r0, [r2, 0xC] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0xF] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0xE] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0x9] - cmp r0, 0 - bne _0804F176 - movs r1, 0x4 - ldrsh r0, [r2, r1] - movs r3, 0 - ldrsh r1, [r2, r3] - subs r0, r1 - movs r3, 0x1 - ands r0, r3 - cmp r0, 0 - beq _0804F176 - movs r6, 0x6 - ldrsh r0, [r2, r6] - movs r6, 0x2 - ldrsh r1, [r2, r6] - subs r0, r1 - ands r0, r3 - cmp r0, 0 - beq _0804F176 - adds r5, 0x1 -_0804F176: - adds r2, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _0804F122 -_0804F17E: - adds r6, r7, 0 - cmp r6, r10 - blt _0804F110 -_0804F184: - cmp r5, 0 - beq _0804F266 - movs r1, 0 - mov r0, sp - adds r0, 0xFF -_0804F18E: - strb r1, [r0] - subs r0, 0x1 - cmp r0, sp - bge _0804F18E - mov r1, sp - movs r0, 0x1 - strb r0, [r1] - movs r7, 0x3F - mov r8, r7 -_0804F1A0: - adds r0, r5, 0 - bl DungeonRandInt - adds r4, r0, 0 - adds r0, r5, 0 - bl DungeonRandInt - mov r1, sp - adds r2, r1, r4 - ldrb r3, [r2] - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - movs r3, 0x1 - negs r3, r3 - add r8, r3 - mov r4, r8 - cmp r4, 0 - bge _0804F1A0 - movs r6, 0 - mov r8, r6 - cmp r6, r10 - bge _0804F266 - ldr r7, [sp, 0x100] - mov r12, r7 -_0804F1D4: - movs r4, 0 - cmp r4, r9 - bge _0804F25A - mov r2, r12 - mov r5, r12 -_0804F1DE: - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0x11] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804F250 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804F250 - ldrb r0, [r2, 0xC] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0xF] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0xE] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0x9] - cmp r0, 0 - bne _0804F250 - movs r1, 0x4 - ldrsh r0, [r2, r1] - movs r3, 0 - ldrsh r1, [r2, r3] - subs r0, r1 - movs r3, 0x1 - ands r0, r3 - cmp r0, 0 - beq _0804F250 - movs r7, 0x6 - ldrsh r0, [r2, r7] - movs r7, 0x2 - ldrsh r1, [r2, r7] - subs r0, r1 - ands r0, r3 - cmp r0, 0 - beq _0804F250 - mov r0, sp - add r0, r8 - ldrb r0, [r0] - cmp r0, 0 - beq _0804F24C - adds r0, r5, 0 - movs r1, 0 - bl sub_804F278 - b _0804F266 - .align 2, 0 -_0804F244: .4byte gDungeon -_0804F248: .4byte 0x00003a16 -_0804F24C: - movs r0, 0x1 - add r8, r0 -_0804F250: - adds r2, 0x20 - adds r5, 0x20 - adds r4, 0x1 - cmp r4, r9 - blt _0804F1DE -_0804F25A: - movs r1, 0xF0 - lsls r1, 1 - add r12, r1 - adds r6, 0x1 - cmp r6, r10 - blt _0804F1D4 -_0804F266: - add sp, 0x104 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GenerateMazeRoom - thumb_func_start sub_804F278 -sub_804F278: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - adds r4, r0, 0 - lsls r1, 24 - lsrs r1, 24 - mov r8, r1 - ldr r1, _0804F2B0 - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x1 - strb r0, [r4, 0x10] - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r9, r0 - movs r5, 0 - ldrsh r0, [r4, r5] - adds r6, r0, 0x1 - b _0804F2F0 - .align 2, 0 -_0804F2B0: .4byte gUnknown_202F1AC -_0804F2B4: - movs r2, 0x2 - ldrsh r1, [r4, r2] - subs r1, 0x1 - adds r0, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F2EE - movs r5, 0x2 - ldrsh r3, [r4, r5] - subs r1, r3, 0x1 - movs r0, 0 - ldrsh r2, [r4, r0] - movs r5, 0x4 - ldrsh r0, [r4, r5] - str r0, [sp] - movs r5, 0x6 - ldrsh r0, [r4, r5] - str r0, [sp, 0x4] - mov r0, r8 - str r0, [sp, 0x8] - mov r5, r9 - str r5, [sp, 0xC] - adds r0, r6, 0 - bl sub_804F494 -_0804F2EE: - adds r6, 0x2 -_0804F2F0: - movs r1, 0x4 - ldrsh r0, [r4, r1] - subs r0, 0x1 - cmp r6, r0 - blt _0804F2B4 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r5, r0, 0x1 - movs r6, 0x6 - ldrsh r0, [r4, r6] - b _0804F342 -_0804F306: - movs r1, 0x4 - ldrsh r0, [r4, r1] - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F33C - movs r2, 0x4 - ldrsh r0, [r4, r2] - movs r6, 0 - ldrsh r2, [r4, r6] - movs r1, 0x2 - ldrsh r3, [r4, r1] - str r0, [sp] - movs r6, 0x6 - ldrsh r1, [r4, r6] - str r1, [sp, 0x4] - mov r1, r8 - str r1, [sp, 0x8] - mov r6, r9 - str r6, [sp, 0xC] - adds r1, r5, 0 - bl sub_804F494 -_0804F33C: - adds r5, 0x2 - movs r1, 0x6 - ldrsh r0, [r4, r1] -_0804F342: - subs r0, 0x1 - cmp r5, r0 - blt _0804F306 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r6, r0, 0x1 - movs r5, 0x4 - ldrsh r0, [r4, r5] - b _0804F392 -_0804F354: - movs r0, 0x6 - ldrsh r1, [r4, r0] - adds r0, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F38C - movs r2, 0x6 - ldrsh r1, [r4, r2] - movs r5, 0 - ldrsh r2, [r4, r5] - movs r0, 0x2 - ldrsh r3, [r4, r0] - movs r5, 0x4 - ldrsh r0, [r4, r5] - str r0, [sp] - adds r0, r1, 0 - str r0, [sp, 0x4] - mov r0, r8 - str r0, [sp, 0x8] - mov r5, r9 - str r5, [sp, 0xC] - adds r0, r6, 0 - bl sub_804F494 -_0804F38C: - adds r6, 0x2 - movs r1, 0x4 - ldrsh r0, [r4, r1] -_0804F392: - subs r0, 0x1 - cmp r6, r0 - blt _0804F354 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r5, r0, 0x1 - movs r6, 0x6 - ldrsh r0, [r4, r6] - b _0804F3E4 -_0804F3A4: - movs r1, 0 - ldrsh r0, [r4, r1] - subs r0, 0x1 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F3DE - movs r6, 0 - ldrsh r2, [r4, r6] - subs r0, r2, 0x1 - movs r1, 0x2 - ldrsh r3, [r4, r1] - movs r6, 0x4 - ldrsh r1, [r4, r6] - str r1, [sp] - movs r6, 0x6 - ldrsh r1, [r4, r6] - str r1, [sp, 0x4] - mov r1, r8 - str r1, [sp, 0x8] - mov r6, r9 - str r6, [sp, 0xC] - adds r1, r5, 0 - bl sub_804F494 -_0804F3DE: - adds r5, 0x2 - movs r1, 0x6 - ldrsh r0, [r4, r1] -_0804F3E4: - subs r0, 0x1 - cmp r5, r0 - blt _0804F3A4 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r6, r0, 0x3 - b _0804F478 -_0804F3F2: - movs r1, 0x2 - ldrsh r0, [r4, r1] - adds r5, r0, 0x3 - movs r2, 0x6 - ldrsh r0, [r4, r2] - subs r0, 0x3 - adds r1, r6, 0x2 - mov r10, r1 - cmp r5, r0 - bge _0804F476 - ldr r2, _0804F434 - adds r7, r2, 0 -_0804F40A: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0804F46A - mov r0, r8 - cmp r0, 0 - beq _0804F438 - subs r0, r6, 0x1 - adds r1, r5, 0 - bl GetTileSafe - ldrh r1, [r0] - ands r1, r7 - movs r2, 0x2 - orrs r1, r2 - b _0804F444 - .align 2, 0 -_0804F434: .4byte 0x0000fffc -_0804F438: - subs r0, r6, 0x1 - adds r1, r5, 0 - bl GetTileSafe - ldrh r1, [r0] - ands r1, r7 -_0804F444: - strh r1, [r0] - movs r1, 0 - ldrsh r2, [r4, r1] - movs r0, 0x2 - ldrsh r3, [r4, r0] - movs r1, 0x4 - ldrsh r0, [r4, r1] - str r0, [sp] - movs r1, 0x6 - ldrsh r0, [r4, r1] - str r0, [sp, 0x4] - mov r0, r8 - str r0, [sp, 0x8] - mov r1, r9 - str r1, [sp, 0xC] - adds r0, r6, 0 - adds r1, r5, 0 - bl sub_804F494 -_0804F46A: - adds r5, 0x2 - movs r2, 0x6 - ldrsh r0, [r4, r2] - subs r0, 0x3 - cmp r5, r0 - blt _0804F40A -_0804F476: - mov r6, r10 -_0804F478: - movs r5, 0x4 - ldrsh r0, [r4, r5] - subs r0, 0x3 - cmp r6, r0 - blt _0804F3F2 - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F278 - - thumb_func_start sub_804F494 -sub_804F494: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r5, r0, 0 - adds r4, r1, 0 - str r2, [sp] - str r3, [sp, 0x4] - ldr r0, [sp, 0x30] - ldr r1, [sp, 0x34] - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r1, 24 - mov r8, r1 - movs r0, 0x3 - mov r10, r0 -_0804F4BA: - movs r0, 0x4 - bl DungeonRandInt - adds r6, r0, 0 - movs r7, 0 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl SetTerrainObstacleChecked -_0804F4D6: - adds r0, r6, 0 - mov r1, r10 - ands r0, r1 - cmp r0, 0x1 - beq _0804F4F6 - cmp r0, 0x1 - bgt _0804F4EA - cmp r0, 0 - beq _0804F4F0 - b _0804F506 -_0804F4EA: - cmp r0, 0x2 - beq _0804F4FE - b _0804F506 -_0804F4F0: - movs r0, 0x2 - movs r1, 0 - b _0804F50A -_0804F4F6: - movs r0, 0 - movs r1, 0x2 - negs r1, r1 - b _0804F50A -_0804F4FE: - movs r0, 0x2 - negs r0, r0 - movs r1, 0 - b _0804F50A -_0804F506: - movs r0, 0 - movs r1, 0x2 -_0804F50A: - adds r0, r5, r0 - ldr r2, [sp] - cmp r2, r0 - bgt _0804F534 - ldr r3, [sp, 0x28] - cmp r3, r0 - ble _0804F534 - adds r1, r4, r1 - ldr r2, [sp, 0x4] - cmp r2, r1 - bgt _0804F534 - ldr r3, [sp, 0x2C] - cmp r3, r1 - ble _0804F534 - bl GetTile - ldrh r1, [r0] - mov r0, r10 - ands r0, r1 - cmp r0, 0x1 - beq _0804F53E -_0804F534: - adds r6, 0x1 - adds r7, 0x1 - cmp r7, 0x3 - bgt _0804F5B2 - b _0804F4D6 -_0804F53E: - mov r0, r10 - ands r0, r6 - cmp r0, 0x1 - beq _0804F570 - cmp r0, 0x1 - bgt _0804F550 - cmp r0, 0 - beq _0804F55A - b _0804F4BA -_0804F550: - cmp r0, 0x2 - beq _0804F586 - cmp r0, 0x3 - beq _0804F59C - b _0804F4BA -_0804F55A: - adds r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileSafe - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl SetTerrainObstacleChecked - adds r5, 0x2 - b _0804F4BA -_0804F570: - subs r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileSafe - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl SetTerrainObstacleChecked - subs r4, 0x2 - b _0804F4BA -_0804F586: - subs r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileSafe - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl SetTerrainObstacleChecked - subs r5, 0x2 - b _0804F4BA -_0804F59C: - adds r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileSafe - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl SetTerrainObstacleChecked - adds r4, 0x2 - b _0804F4BA -_0804F5B2: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F494 - - thumb_func_start sub_804F5C4 -sub_804F5C4: - ldrh r3, [r0] - ldr r2, _0804F5D4 - ands r2, r3 - movs r3, 0x2 - orrs r2, r3 - orrs r2, r1 - strh r2, [r0] - bx lr - .align 2, 0 -_0804F5D4: .4byte 0x0000fffc - thumb_func_end sub_804F5C4 - - thumb_func_start sub_804F5D8 -sub_804F5D8: - push {r4-r7,lr} - adds r5, r0, 0 - movs r0, 0 - ldrsh r6, [r5, r0] - b _0804F60C -_0804F5E2: - movs r0, 0x2 - ldrsh r4, [r5, r0] - movs r1, 0x6 - ldrsh r0, [r5, r1] - adds r7, r6, 0x1 - cmp r4, r0 - bge _0804F60A -_0804F5F0: - adds r0, r6, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x20 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x1 - movs r1, 0x6 - ldrsh r0, [r5, r1] - cmp r4, r0 - blt _0804F5F0 -_0804F60A: - adds r6, r7, 0 -_0804F60C: - movs r1, 0x4 - ldrsh r0, [r5, r1] - cmp r6, r0 - blt _0804F5E2 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F5D8 - - thumb_func_start sub_804F61C -sub_804F61C: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - mov r9, r0 - mov r8, r1 - movs r7, 0x1 - negs r7, r7 - b _0804F67A -_0804F62E: - movs r5, 0x1 - negs r5, r5 - b _0804F666 -_0804F634: - cmp r7, 0 - beq _0804F63C - cmp r5, 0 - bne _0804F660 -_0804F63C: - adds r0, r6, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0804F660 - adds r0, r6, 0 - adds r1, r4, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r0, 0xFF - bne _0804F660 - movs r0, 0x1 - b _0804F686 -_0804F660: - adds r5, 0x1 - cmp r5, 0x1 - bgt _0804F672 -_0804F666: - mov r0, r8 - adds r4, r0, r5 - cmp r4, 0 - blt _0804F660 - cmp r4, 0x1F - ble _0804F634 -_0804F672: - adds r7, 0x1 - cmp r7, 0x1 - bgt _0804F684 - mov r0, r9 -_0804F67A: - adds r6, r0, r7 - cmp r6, 0 - blt _0804F672 - cmp r6, 0x37 - ble _0804F62E -_0804F684: - movs r0, 0 -_0804F686: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_804F61C thumb_func_start GenerateSecondaryStructure GenerateSecondaryStructure: @@ -832,7 +47,7 @@ _0804F6DE: subs r0, 0x1 str r0, [r1] adds r0, r7, 0 - bl sub_804F5D8 + bl SetSpawnFlag5 movs r0, 0x2 bl DungeonRandInt cmp r0, 0 @@ -861,7 +76,7 @@ _0804F712: bge _0804F72A mov r0, r8 adds r1, r4, 0 - bl sub_804F61C + bl IsNextToHallway lsls r0, 24 cmp r0, 0 beq _0804F710 @@ -943,7 +158,7 @@ _0804F7AA: bge _0804F7C2 adds r0, r4, 0 mov r1, r8 - bl sub_804F61C + bl IsNextToHallway lsls r0, 24 cmp r0, 0 beq _0804F7A8 @@ -1040,7 +255,7 @@ _0804F864: subs r0, 0x1 str r0, [r1] adds r0, r7, 0 - bl sub_804F5D8 + bl SetSpawnFlag5 ldr r5, [sp] subs r5, 0x2 ldr r0, [sp, 0x4] @@ -1243,7 +458,7 @@ _0804FA46: subs r0, 0x1 str r0, [r1] adds r0, r7, 0 - bl sub_804F5D8 + bl SetSpawnFlag5 cmp r4, r9 ble _0804FA5A adds r0, r4, 0 @@ -1313,7 +528,7 @@ _0804FAC8: subs r0, 0x1 str r0, [r1] adds r0, r7, 0 - bl sub_804F5D8 + bl SetSpawnFlag5 movs r6, 0x3F _0804FAD4: movs r4, 0x4 @@ -1426,10 +641,10 @@ _0804FBAE: _0804FBC0: .4byte gUnknown_202F1C8 _0804FBC4: adds r0, r7, 0 - bl sub_804F5D8 + bl SetSpawnFlag5 adds r0, r7, 0 movs r1, 0x1 - bl sub_804F278 + bl GenerateMaze _0804FBD2: movs r0, 0x1 strb r0, [r7, 0x9] diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index 06992aad3..635a4a6b5 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -13,7 +13,7 @@ extern struct FileArchive gDungeonFileArchive; extern bool8 gUnknown_202F1AA; extern u8 gUnknown_202F1AB; -extern u8 gUnknown_202F1AC; +extern bool8 gUnknown_202F1AC; extern u8 gUnknown_202F1A8; extern u8 gUnknown_202F1B4; extern u8 gUnknown_202F1AE; @@ -103,7 +103,7 @@ void sub_804AFAC(void) gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); gUnknown_202F1AA = FALSE; gUnknown_202F1AB = 0; - gUnknown_202F1AC = 0; + gUnknown_202F1AC = FALSE; gUnknown_202F1A8 = (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_WATER); gUnknown_202F1B4 = 0xFF; gUnknown_202F1AE = 0; @@ -1035,11 +1035,12 @@ struct GridCell void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 x2, s32 y2); -void sub_8051438(struct GridCell *cell, s32 a1); +void sub_8051438(struct GridCell *gridCell, s32 a1); extern void sub_8051288(s32 a0); void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +void GenerateSecondaryStructure(struct GridCell *gridCell); void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber); void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); @@ -1048,6 +1049,8 @@ void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr); void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr); void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain); +void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex); void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); @@ -2312,8 +2315,6 @@ void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s } } -void GenerateSecondaryStructure(struct GridCell *cell); - void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) { s32 x, y; @@ -3885,4 +3886,346 @@ void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s3 } } +/* + * GenerateMazeRoom - Determines and calls for whether to generate a maze room on the floor. + * + * A maze room can be generated by the probability specified in the maze_chance parameter, usually in vanilla + * this parameter is set to either 0 or 1, giving a 0-1% chance for trying to spawn a maze room. + * + * Then, a strange check occurs for whether the floor_generation_attempts is < 0, which will always fail, resulting + * in no maze rooms ever being generated under normal conditions. + * + * Candidate maze rooms have to be valid, connected, have odd dimensions, and not have any other features. + * If any candidates are found, the game will select one of these rooms and call GenerateMaze. + */ +void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) +{ + bool8 values[256]; + s32 i; + s32 x, y; + s32 numValid; + Dungeon *dungeon = gDungeon; + if (chance == 0) // No chance for maze, stop + return; + if (chance <= DungeonRandInt(100)) // Need to roll the probability chance (which is usually 0-1%...) + return; + if (dungeon->unk3A16 >= 0) // This bizarre check prevents maze rooms from ever being created + return; + + // Count the number of rooms that can be mazified: + // - Valid + // - Not a Merged Room + // - Connected + // - Not a Monster House + // - Both Dimensions are Odd + + numValid = 0; + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + if (grid[x][y].isInvalid) + continue; + if (grid[x][y].hasBeenMerged) + continue; + if (!grid[x][y].isConnected) + continue; + if (!grid[x][y].isRoom) + continue; + if (grid[x][y].isKecleonShop) + continue; + if (grid[x][y].unk15) + continue; + if (grid[x][y].isMonsterHouse) + continue; + if (grid[x][y].hasSecondaryStructure) + continue; + + if ((grid[x][y].end.x - grid[x][y].start.x) % 2 != 0 && (grid[x][y].end.y - grid[x][y].start.y) % 2 != 0) { + numValid++; + } + } + } + + if (numValid == 0) + return; + + // Have a single 1, the rest as 0's + for (i = 0; i < 256; i++) { + values[i] = FALSE; + } + values[0] = TRUE; + + // Shuffle values + for (i = 0; i < 64; i++) { + s32 temp; + s32 a = DungeonRandInt(numValid); + s32 b = DungeonRandInt(numValid); + + SWAP(values[a], values[b], temp); + } + + // Counter + i = 0; + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + if (grid[x][y].isInvalid) + continue; + if (grid[x][y].hasBeenMerged) + continue; + if (!grid[x][y].isConnected) + continue; + if (!grid[x][y].isRoom) + continue; + if (grid[x][y].isKecleonShop) + continue; + if (grid[x][y].unk15) + continue; + if (grid[x][y].isMonsterHouse) + continue; + if (grid[x][y].hasSecondaryStructure) + continue; + + if ((grid[x][y].end.x - grid[x][y].start.x) % 2 != 0 && (grid[x][y].end.y - grid[x][y].start.y) % 2 != 0) { + // This room can be mazified + if (values[i]) { + GenerateMaze(&grid[x][y], FALSE); + return; + } + + i++; + } + } + } +} + +/* + * GenerateMaze - Generate a maze room within the given grid cell. + * + * A "maze" is generated using a series of random walks whiich place obstacle terrain (walls / secondary terrain) + * in a maze-like arrangement. "Maze lines" (see: GenerateMazeLine) are generated using every other tile around the + * room's border, and every other interior tile as a starting point, ensuring there are stripes of walkable open terrain + * surrounded by striples of obstacles (maze walls). + * + */ +void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) +{ + s32 curX, curY; + u8 roomIndex; + + gUnknown_202F1AC = TRUE; + gridCell->isMazeRoom = TRUE; + + roomIndex = GetTile(gridCell->start.x, gridCell->start.y)->room; + + // Random walks from upper border + for (curX = gridCell->start.x + 1; curX < gridCell->end.x - 1; curX += 2) { + if (GetTerrainType(GetTile(curX, gridCell->start.y - 1)) != TERRAIN_TYPE_NORMAL) { + GenerateMazeLine(curX, + gridCell->start.y - 1, + gridCell->start.x, + gridCell->start.y, + gridCell->end.x, + gridCell->end.y, + useSecondaryTerrain, + roomIndex + ); + } + } + + // Random walks from right border + for (curY = gridCell->start.y + 1; curY < gridCell->end.y - 1; curY += 2) { + if (GetTerrainType(GetTile(gridCell->end.x, curY)) != TERRAIN_TYPE_NORMAL) { + GenerateMazeLine(gridCell->end.x, curY, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); + } + } + + // Random walks from lower border + for (curX = gridCell->start.x + 1; curX < gridCell->end.x - 1; curX += 2) { + if (GetTerrainType(GetTile(curX, gridCell->end.y)) != TERRAIN_TYPE_NORMAL) { + GenerateMazeLine(curX, gridCell->end.y, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); + } + } + + // Random walks from left border + for (curY = gridCell->start.y + 1; curY < gridCell->end.y - 1; curY += 2) { + if (GetTerrainType(GetTile(gridCell->start.x - 1, curY)) != TERRAIN_TYPE_NORMAL) { + GenerateMazeLine(gridCell->start.x - 1, + curY, + gridCell->start.x, + gridCell->start.y, + gridCell->end.x, + gridCell->end.y, + useSecondaryTerrain, + roomIndex); + } + } + + // Fill in all the inner tiles with a stride of 2 + for (curX = gridCell->start.x + 3; curX < gridCell->end.x - 3; curX += 2) { + for (curY = gridCell->start.y + 3; curY < gridCell->end.y - 3; curY += 2) { + if (GetTerrainType(GetTile(curX, curY)) == TERRAIN_TYPE_NORMAL) { + if (useSecondaryTerrain) { + SetTerrainSecondary(GetTileSafe(curX - 1, curY)); + } + else { + SetTerrainWall(GetTileSafe(curX - 1, curY)); + } + + // More random walks + GenerateMazeLine(curX, curY, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); + } + } + } +} + +/* + * GenerateMazeLine - Generates a "maze line" from the given start point, within the given bounds. + * + * A "maze line" is a random walk starting from (x0, y0). The random walk moves in strides of 2 + * in a random direction, placing down obstacles as it goes. + * + * The walk will terminate when the random walk has no available open tiles it can walk to. + * + * [ ^ ] [ ] [ ] [ o ] [ - ] [ > ] + * [ | ] [ ] [ ] => [ W ] [ ] [ ] => etc. + * [ o ] [ ] [ W ] [ W ] [ ] [ W ] + * + * First, an obstacle is placed at the given position (see: SetTerrainObstacleChecked) + * + * Then, a random direction is selected, searching for an open tile distance 2 away from (x0, y0). + * Each direction is attempted rotating counter-clockwise until an open tile is found or all directions are exhausted. + * + * If an open tile is found, an obstacle is placed between the two tiles, and (x0, y0) moves to the new open tile. + * This process continues until no valid open tile can be found. + */ +void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex) +{ + while (1) { + s32 direction = DungeonRandInt(NUM_CARDINAL_DIRECTIONS); + s32 i = 0; + + SetTerrainObstacleChecked(GetTileSafe(x0, y0), useSecondaryTerrain, roomIndex); + + while (1) { + s32 offsetX, offsetY; + s32 posX, posY; + + // Offset from our current position to look 2 tiles in a given direction + switch (direction & CARDINAL_DIRECTION_MASK) { + case CARDINAL_DIR_RIGHT: + offsetX = 2; + offsetY = 0; + break; + case CARDINAL_DIR_UP: + offsetX = 0; + offsetY = -2; + break; + case CARDINAL_DIR_LEFT: + offsetX = -2; + offsetY = 0; + break; + default: + case CARDINAL_DIR_DOWN: + offsetX = 0; + offsetY = 2; + break; + } + + posX = x0 + offsetX; + + // Check that this position is in-bounds + if (xMin <= posX && xMax > posX) { + posY = y0 + offsetY; + if (yMin <= posY && yMax > posY) { + // Check that this tile is open ground + if (GetTerrainType(GetTile(posX, posY)) == TERRAIN_TYPE_NORMAL) { + // We found open ground, we're done! + break; + } + } + } + + // We didn't find any, try a different direction + direction++; + if (++i >= 4) + return; + } + + // If we found some open terrain, set an obstacle for the terrain in between those two, + // then move to the open terrain we found. + switch (direction & CARDINAL_DIRECTION_MASK) { + case CARDINAL_DIR_RIGHT: + SetTerrainObstacleChecked(GetTileSafe(x0 + 1, y0), useSecondaryTerrain, roomIndex); + + x0 += 2; + break; + case CARDINAL_DIR_UP: + SetTerrainObstacleChecked(GetTileSafe(x0, y0 - 1), useSecondaryTerrain, roomIndex); + + y0 -= 2; + break; + case CARDINAL_DIR_LEFT: + SetTerrainObstacleChecked(GetTileSafe(x0 - 1, y0), useSecondaryTerrain, roomIndex); + + x0 -= 2; + break; + case CARDINAL_DIR_DOWN: + SetTerrainObstacleChecked(GetTileSafe(x0, y0 + 1), useSecondaryTerrain, roomIndex); + + y0 += 2; + break; + } + } +} + +void sub_804F5C4(Tile *tile, u32 terrainFlag) +{ + SetTerrainSecondary(tile); + tile->terrainType |= terrainFlag; +} + +/* + * SetSpawnFlag5 - Sets unknown spawn flag 0x5 on all tiles in a room + */ +void SetSpawnFlag5(struct GridCell *gridCell) { + s32 x, y; + + for (x = gridCell->start.x; x < gridCell->end.x; x++) { + for (y = gridCell->start.y; y < gridCell->end.y; y++) { + GetTileSafe(x, y)->unk4 |= 0x20; + } + } +} + +/* + * IsNextToHallway - Checks if a tile position is either in a hallway or next to one. + */ +bool8 IsNextToHallway(s32 x, s32 y) +{ + s32 offsetX, offsetY; + s32 posX, posY; + + for (offsetX = -1; offsetX <= 1; offsetX++) { + posX = x + offsetX; + if (posX < 0) + continue; + if (posX >= DUNGEON_MAX_SIZE_X) + break; + + for (offsetY = -1; offsetY <= 1; offsetY++) { + posY = y + offsetY; + if (posY < 0) + continue; + if (posY >= DUNGEON_MAX_SIZE_Y) + break; + if (offsetX != 0 && offsetY != 0) + continue; + + if (GetTerrainType(GetTile(posX, posY)) == TERRAIN_TYPE_NORMAL && GetTile(posX, posY)->room == CORRIDOR_ROOM) + return TRUE; + } + } + + return FALSE; +} + // From 102403cd9ae2cadca0dfd81e8aac915bc16b7d80 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 12 Nov 2024 12:30:12 +0100 Subject: [PATCH 15/30] decompile dungeon_generation --- asm/code_804AFAC.s | 662 ------------------ include/dungeon_generation.h | 11 + include/structs/map.h | 1 + ld_script.txt | 3 +- ...{code_804AFAC_1.c => dungeon_generation.c} | 216 +++++- 5 files changed, 226 insertions(+), 667 deletions(-) delete mode 100644 asm/code_804AFAC.s rename src/{code_804AFAC_1.c => dungeon_generation.c} (93%) diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s deleted file mode 100644 index be57e660a..000000000 --- a/asm/code_804AFAC.s +++ /dev/null @@ -1,662 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - - - thumb_func_start GenerateSecondaryStructure -GenerateSecondaryStructure: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r7, r0, 0 - movs r0, 0x6 - bl DungeonRandInt - subs r0, 0x1 - cmp r0, 0x4 - bls _0804F6B0 - b _0804FBD6 -_0804F6B0: - lsls r0, 2 - ldr r1, _0804F6BC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_0804F6BC: .4byte _0804F6C0 - .align 2, 0 -_0804F6C0: - .4byte _0804FB24 - .4byte _0804FA98 - .4byte _0804F9DC - .4byte _0804F826 - .4byte _0804F6D4 -_0804F6D4: - ldr r1, _0804F70C - ldr r0, [r1] - cmp r0, 0 - bne _0804F6DE - b _0804FBD6 -_0804F6DE: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl SetSpawnFlag5 - movs r0, 0x2 - bl DungeonRandInt - cmp r0, 0 - beq _0804F78E - movs r5, 0 - movs r1, 0 - ldrsh r0, [r7, r1] - movs r2, 0x4 - ldrsh r1, [r7, r2] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - mov r8, r0 - movs r3, 0x2 - ldrsh r4, [r7, r3] - b _0804F712 - .align 2, 0 -_0804F70C: .4byte gUnknown_202F1C8 -_0804F710: - adds r4, 0x1 -_0804F712: - movs r1, 0x6 - ldrsh r0, [r7, r1] - cmp r4, r0 - bge _0804F72A - mov r0, r8 - adds r1, r4, 0 - bl IsNextToHallway - lsls r0, 24 - cmp r0, 0 - beq _0804F710 - movs r5, 0x1 -_0804F72A: - cmp r5, 0 - beq _0804F730 - b _0804FBD6 -_0804F730: - movs r2, 0x2 - ldrsh r4, [r7, r2] - movs r3, 0x6 - ldrsh r0, [r7, r3] - cmp r4, r0 - bge _0804F754 -_0804F73C: - mov r0, r8 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 - adds r4, 0x1 - movs r5, 0x6 - ldrsh r0, [r7, r5] - cmp r4, r0 - blt _0804F73C -_0804F754: - movs r0, 0 - ldrsh r5, [r7, r0] - cmp r5, r8 - blt _0804F75E - b _0804FBD2 -_0804F75E: - movs r1, 0x2 - ldrsh r4, [r7, r1] - movs r2, 0x6 - ldrsh r0, [r7, r2] - adds r6, r5, 0x1 - cmp r4, r0 - bge _0804F786 -_0804F76C: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r2, [r0] - movs r1, 0x80 - orrs r1, r2 - strh r1, [r0] - adds r4, 0x1 - movs r3, 0x6 - ldrsh r0, [r7, r3] - cmp r4, r0 - blt _0804F76C -_0804F786: - adds r5, r6, 0 - cmp r5, r8 - blt _0804F75E - b _0804FBD2 -_0804F78E: - movs r5, 0 - movs r4, 0x2 - ldrsh r0, [r7, r4] - movs r2, 0x6 - ldrsh r1, [r7, r2] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - mov r8, r0 - movs r3, 0 - ldrsh r4, [r7, r3] - b _0804F7AA -_0804F7A8: - adds r4, 0x1 -_0804F7AA: - movs r1, 0x4 - ldrsh r0, [r7, r1] - cmp r4, r0 - bge _0804F7C2 - adds r0, r4, 0 - mov r1, r8 - bl IsNextToHallway - lsls r0, 24 - cmp r0, 0 - beq _0804F7A8 - movs r5, 0x1 -_0804F7C2: - cmp r5, 0 - beq _0804F7C8 - b _0804FBD6 -_0804F7C8: - movs r2, 0 - ldrsh r4, [r7, r2] - movs r3, 0x4 - ldrsh r0, [r7, r3] - cmp r4, r0 - bge _0804F7EC -_0804F7D4: - adds r0, r4, 0 - mov r1, r8 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 - adds r4, 0x1 - movs r5, 0x4 - ldrsh r0, [r7, r5] - cmp r4, r0 - blt _0804F7D4 -_0804F7EC: - movs r0, 0x2 - ldrsh r5, [r7, r0] - cmp r5, r8 - blt _0804F7F6 - b _0804FBD2 -_0804F7F6: - movs r1, 0 - ldrsh r4, [r7, r1] - movs r2, 0x4 - ldrsh r0, [r7, r2] - adds r6, r5, 0x1 - cmp r4, r0 - bge _0804F81E -_0804F804: - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileSafe - ldrh r2, [r0] - movs r1, 0x80 - orrs r1, r2 - strh r1, [r0] - adds r4, 0x1 - movs r3, 0x4 - ldrsh r0, [r7, r3] - cmp r4, r0 - blt _0804F804 -_0804F81E: - adds r5, r6, 0 - cmp r5, r8 - blt _0804F7F6 - b _0804FBD2 -_0804F826: - movs r4, 0x4 - ldrsh r3, [r7, r4] - movs r5, 0 - ldrsh r1, [r7, r5] - subs r0, r3, r1 - cmp r0, 0x5 - bgt _0804F836 - b _0804FBD6 -_0804F836: - movs r0, 0x6 - ldrsh r4, [r7, r0] - movs r5, 0x2 - ldrsh r2, [r7, r5] - subs r0, r4, r2 - cmp r0, 0x5 - bgt _0804F846 - b _0804FBD6 -_0804F846: - adds r0, r1, r3 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - str r0, [sp] - adds r0, r2, r4 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - str r0, [sp, 0x4] - ldr r1, _0804F9D8 - ldr r0, [r1] - cmp r0, 0 - bne _0804F864 - b _0804FBD6 -_0804F864: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl SetSpawnFlag5 - ldr r5, [sp] - subs r5, 0x2 - ldr r0, [sp, 0x4] - subs r0, 0x2 - mov r10, r0 - adds r0, r5, 0 - mov r1, r10 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - ldr r1, [sp] - subs r1, 0x1 - mov r9, r1 - mov r0, r9 - mov r1, r10 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - ldr r0, [sp] - mov r1, r10 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - ldr r2, [sp] - adds r2, 0x1 - mov r8, r2 - mov r0, r8 - mov r1, r10 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - ldr r6, [sp, 0x4] - subs r6, 0x1 - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - adds r0, r5, 0 - ldr r1, [sp, 0x4] - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - ldr r4, [sp, 0x4] - adds r4, 0x1 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r9 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - ldr r0, [sp] - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - mov r1, r10 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - adds r1, r6, 0 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - ldr r1, [sp, 0x4] - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r9 - adds r1, r6, 0 - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x4 - orrs r1, r2 - strh r1, [r0, 0x4] - mov r0, r9 - adds r1, r6, 0 - bl GetTileSafe - ldrh r1, [r0, 0x4] - movs r2, 0x40 - orrs r1, r2 - strh r1, [r0, 0x4] - ldr r0, [sp] - adds r1, r6, 0 - bl GetTileSafe - ldrh r1, [r0, 0x4] - movs r4, 0x2 - orrs r1, r4 - strh r1, [r0, 0x4] - mov r0, r9 - ldr r1, [sp, 0x4] - bl GetTileSafe - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - ldr r0, [sp] - ldr r1, [sp, 0x4] - bl GetTileSafe - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - mov r0, r9 - adds r1, r6, 0 - bl GetTileSafe - ldrh r1, [r0, 0x4] - movs r4, 0x10 - orrs r1, r4 - strh r1, [r0, 0x4] - ldr r0, [sp] - adds r1, r6, 0 - bl GetTileSafe - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - mov r0, r9 - ldr r1, [sp, 0x4] - bl GetTileSafe - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - ldr r0, [sp] - ldr r1, [sp, 0x4] - bl GetTileSafe - ldrh r1, [r0, 0x4] - orrs r4, r1 - strh r4, [r0, 0x4] - b _0804FBD2 - .align 2, 0 -_0804F9D8: .4byte gUnknown_202F1C8 -_0804F9DC: - movs r4, 0x4 - ldrsh r3, [r7, r4] - movs r5, 0 - ldrsh r2, [r7, r5] - subs r0, r3, r2 - cmp r0, 0x4 - bgt _0804F9EC - b _0804FBD6 -_0804F9EC: - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r4, 0x2 - ldrsh r1, [r7, r4] - subs r0, r1 - cmp r0, 0x4 - bgt _0804F9FC - b _0804FBD6 -_0804F9FC: - adds r0, r2, 0x2 - subs r1, r3, 0x3 - bl DungeonRandRange - adds r4, r0, 0 - movs r5, 0x2 - ldrsh r0, [r7, r5] - adds r0, 0x2 - movs r2, 0x6 - ldrsh r1, [r7, r2] - subs r1, 0x3 - bl DungeonRandRange - mov r10, r0 - movs r3, 0 - ldrsh r0, [r7, r3] - adds r0, 0x2 - movs r5, 0x4 - ldrsh r1, [r7, r5] - subs r1, 0x3 - bl DungeonRandRange - mov r9, r0 - movs r1, 0x2 - ldrsh r0, [r7, r1] - adds r0, 0x2 - movs r2, 0x6 - ldrsh r1, [r7, r2] - subs r1, 0x3 - bl DungeonRandRange - adds r6, r0, 0 - ldr r1, _0804FA94 - ldr r0, [r1] - cmp r0, 0 - bne _0804FA46 - b _0804FBD6 -_0804FA46: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl SetSpawnFlag5 - cmp r4, r9 - ble _0804FA5A - adds r0, r4, 0 - mov r4, r9 - mov r9, r0 -_0804FA5A: - cmp r10, r6 - ble _0804FA64 - mov r0, r10 - mov r10, r6 - adds r6, r0, 0 -_0804FA64: - adds r5, r4, 0 - cmp r5, r9 - ble _0804FA6C - b _0804FBD2 -_0804FA6C: - mov r4, r10 - adds r3, r5, 0x1 - mov r8, r3 - cmp r4, r6 - bgt _0804FA8A -_0804FA76: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 - adds r4, 0x1 - cmp r4, r6 - ble _0804FA76 -_0804FA8A: - mov r5, r8 - cmp r5, r9 - ble _0804FA6C - b _0804FBD2 - .align 2, 0 -_0804FA94: .4byte gUnknown_202F1C8 -_0804FA98: - movs r4, 0x4 - ldrsh r0, [r7, r4] - movs r5, 0 - ldrsh r1, [r7, r5] - subs r0, r1 - movs r2, 0x1 - ands r0, r2 - cmp r0, 0 - bne _0804FAAC - b _0804FBD6 -_0804FAAC: - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r3, 0x2 - ldrsh r1, [r7, r3] - subs r0, r1 - ands r0, r2 - cmp r0, 0 - bne _0804FABE - b _0804FBD6 -_0804FABE: - ldr r1, _0804FB20 - ldr r0, [r1] - cmp r0, 0 - bne _0804FAC8 - b _0804FBD6 -_0804FAC8: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl SetSpawnFlag5 - movs r6, 0x3F -_0804FAD4: - movs r4, 0x4 - ldrsh r0, [r7, r4] - movs r5, 0 - ldrsh r1, [r7, r5] - subs r0, r1 - bl DungeonRandInt - adds r4, r0, 0 - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r2, 0x2 - ldrsh r1, [r7, r2] - subs r0, r1 - bl DungeonRandInt - adds r2, r0, 0 - adds r0, r4, r2 - movs r5, 0x1 - ands r0, r5 - cmp r0, 0 - beq _0804FB14 - movs r3, 0 - ldrsh r0, [r7, r3] - adds r0, r4 - movs r4, 0x2 - ldrsh r1, [r7, r4] - adds r1, r2 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 -_0804FB14: - subs r6, 0x1 - cmp r6, 0 - bge _0804FAD4 - strb r5, [r7, 0x9] - b _0804FBD6 - .align 2, 0 -_0804FB20: .4byte gUnknown_202F1C8 -_0804FB24: - ldr r1, _0804FBC0 - ldr r0, [r1] - cmp r0, 0 - beq _0804FBD6 - subs r0, 0x1 - str r0, [r1] - movs r5, 0x4 - ldrsh r3, [r7, r5] - movs r0, 0 - ldrsh r2, [r7, r0] - subs r6, r3, r2 - movs r4, 0x1 - adds r0, r6, 0 - ands r0, r4 - cmp r0, 0 - beq _0804FB54 - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r5, 0x2 - ldrsh r1, [r7, r5] - subs r0, r1 - ands r0, r4 - cmp r0, 0 - bne _0804FBC4 -_0804FB54: - adds r0, r2, r3 - lsrs r1, r0, 31 - adds r0, r1 - asrs r5, r0, 1 - movs r0, 0x2 - ldrsh r3, [r7, r0] - movs r1, 0x6 - ldrsh r2, [r7, r1] - adds r0, r3, r2 - lsrs r1, r0, 31 - adds r0, r1 - asrs r4, r0, 1 - cmp r6, 0x4 - ble _0804FBAE - subs r0, r2, r3 - cmp r0, 0x4 - ble _0804FBAE - adds r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 - adds r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 - subs r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 - subs r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 -_0804FBAE: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0 - bl sub_804F5C4 - b _0804FBD2 - .align 2, 0 -_0804FBC0: .4byte gUnknown_202F1C8 -_0804FBC4: - adds r0, r7, 0 - bl SetSpawnFlag5 - adds r0, r7, 0 - movs r1, 0x1 - bl GenerateMaze -_0804FBD2: - movs r0, 0x1 - strb r0, [r7, 0x9] -_0804FBD6: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GenerateSecondaryStructure - - .align 2,0 diff --git a/include/dungeon_generation.h b/include/dungeon_generation.h index fd49803bb..777d3693d 100644 --- a/include/dungeon_generation.h +++ b/include/dungeon_generation.h @@ -15,4 +15,15 @@ enum FloorType { FLOOR_TYPE_RESCUE, // Rescuing another player }; +// Helper type used to make explicit the possible secondary structures which can be randomly rolled to generate in the dungeon algorithm. +enum SecondaryStructureType { + SECONDARY_STRUCTURE_NONE, // No secondary structure will be generated. + SECONDARY_STRUCTURE_MAZE_PLUS_DOT, // One of 3 secondary structures depending on the dimensions of the room. If the room has odd dimensions, the result is a maze room. Otherwise, if the room has dimensions of at least `5x5`, a cross or plus pattern is made instead. If both fail, a single tile of secondary terrain will be placed in the center of the room. + SECONDARY_STRUCTURE_CHECKERBOARD, // If the room has odd dimensions, a checkerboard pattern made of randomly placed diagonal stripes of secondary terrain will be generated. If not, no secondary structure will be generated. + SECONDARY_STRUCTURE_POOL, // If the room has dimensions of at least `5x5`, a rectangular pool of secondary terrain will be generated. If not, no secondary structure will be generated. + SECONDARY_STRUCTURE_ISLAND, // If the room has dimensions of at least `6x6`, an island of items and a warp tile surrounded by secondary terrain will be generated. If not, no secondary structure will be generated. + SECONDARY_STRUCTURE_DIVIDER, // A "divider" of secondary terrain will split the room in half randomly either horizontally or vertically. +}; + + #endif diff --git a/include/structs/map.h b/include/structs/map.h index 1f0c4c92c..287a7deda 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -18,6 +18,7 @@ enum TerrainType TERRAIN_TYPE_IMPASSABLE_WALL = 1 << 4, // x10 TERRAIN_TYPE_SHOP = 1 << 5, // x20 TERRAIN_TYPE_IN_MONSTER_HOUSE = 1 << 6, // x40 + TERRAIN_TYPE_UNK_7 = 1 << 7, // x80 TERRAIN_TYPE_UNK_8 = 1 << 8, // x100 TERRAIN_TYPE_STAIRS = 1 << 9, // x200 TERRAIN_TYPE_UNK_x400 = 1 << 10, diff --git a/ld_script.txt b/ld_script.txt index 8afa0922a..7482d6939 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -228,8 +228,7 @@ SECTIONS { src/dungeon_ai_item_weight.o(.text); src/dungeon_map_access.o(.text); src/tile_types.o(.text); - src/code_804AFAC_1.o(.text); - asm/code_804AFAC.o(.text); + src/dungeon_generation.o(.text); src/code_804AFAC.o(.text); asm/code_804FD30.o(.text); src/dungeon_message.o(.text); diff --git a/src/code_804AFAC_1.c b/src/dungeon_generation.c similarity index 93% rename from src/code_804AFAC_1.c rename to src/dungeon_generation.c index 635a4a6b5..959b5e349 100644 --- a/src/code_804AFAC_1.c +++ b/src/dungeon_generation.c @@ -2315,6 +2315,19 @@ void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s } } +/* + * GenerateSecondaryStructures - Attempt to generate secondary structures in flagged rooms. + * + * For a valid flagged room with no extra features, one of the following will attempt to generate: + * 0. No Secondary Structure + * 1. A maze (made of water/lava walls), or a "plus" sign fallback, or a single dot in the center fallback + * 2. Checkerboard pattern of water/lava + * 3. A central pool in the room made of water/lava + * 4. A central island with items and a warp tile, surrounded by water/lava + * 5. A horizontal or vertical line of water/lava splitting the room in two. + * + * If a room doesn't meet the conditions for the secondary structure chosen, it will be left unchanged. + */ void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) { s32 x, y; @@ -4177,16 +4190,17 @@ void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bo } } -void sub_804F5C4(Tile *tile, u32 terrainFlag) +void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag) { SetTerrainSecondary(tile); - tile->terrainType |= terrainFlag; + tile->terrainType |= additionalFlag; } /* * SetSpawnFlag5 - Sets unknown spawn flag 0x5 on all tiles in a room */ -void SetSpawnFlag5(struct GridCell *gridCell) { +void SetSpawnFlag5(struct GridCell *gridCell) +{ s32 x, y; for (x = gridCell->start.x; x < gridCell->end.x; x++) { @@ -4228,4 +4242,200 @@ bool8 IsNextToHallway(s32 x, s32 y) return FALSE; } +// See GenerateSecondaryStructures for more information. +void GenerateSecondaryStructure(struct GridCell *gridCell) +{ + switch (DungeonRandInt(6)) { + // Generate a "split room" with two sides separated by a line of water/lava + case SECONDARY_STRUCTURE_DIVIDER: + if (gUnknown_202F1C8 != 0) { + s32 i; + + gUnknown_202F1C8--; + + SetSpawnFlag5(gridCell); + if (DungeonRandInt(2) != 0) { + // Split the room with a vertical line + s32 curX, curY; + bool8 invalid = FALSE; + s32 middleX = (gridCell->start.x + gridCell->end.x) / 2; + + for (i = gridCell->start.y; i < gridCell->end.y; i++) { + if (IsNextToHallway(middleX, i)) { + invalid = TRUE; + break; + } + } + + if (!invalid) { + for (i = gridCell->start.y; i < gridCell->end.y; i++) { + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, i), 0); + } + + for (curX = gridCell->start.x; curX < middleX; curX++) { + for (curY = gridCell->start.y; curY < gridCell->end.y; curY++) { + GetTileSafe(curX, curY)->terrainType |= TERRAIN_TYPE_UNK_7; + } + } + + gridCell->hasSecondaryStructure = TRUE; + } + } + else { + // Split the room with a horizontal line + s32 curX, curY; + bool8 invalid = FALSE; + s32 middleY = (gridCell->start.y + gridCell->end.y) / 2; + + for (i = gridCell->start.x; i < gridCell->end.x; i++) { + if (IsNextToHallway(i, middleY)) { + invalid = TRUE; + break; + } + } + + if (!invalid) { + for (i = gridCell->start.x; i < gridCell->end.x; i++) { + SetTerrainSecondaryWithFlag(GetTileSafe(i, middleY), 0); + } + + for (curY = gridCell->start.y; curY < middleY; curY++) { + for (curX = gridCell->start.x; curX < gridCell->end.x; curX++) { + GetTileSafe(curX, curY)->terrainType |= TERRAIN_TYPE_UNK_7; + } + } + + gridCell->hasSecondaryStructure = TRUE; + } + } + } + break; + case SECONDARY_STRUCTURE_ISLAND: + if ((gridCell->end.x - gridCell->start.x) >= 6 && (gridCell->end.y - gridCell->start.y) >= 6) { + s32 middleX = (gridCell->start.x + gridCell->end.x) / 2; + s32 middleY = (gridCell->start.y + gridCell->end.y) / 2; + // Both dimensions are at least 6. Generate an "island" with lava, items, and a Warp Tile at the center + if (gUnknown_202F1C8 != 0) { + gUnknown_202F1C8--; + + SetSpawnFlag5(gridCell); + + // Water "Moat" + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY - 2), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 1, middleY - 2), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY - 2), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 2), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY - 1), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY + 1), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY + 1), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 1, middleY + 1), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY + 1), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 2), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 1), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY + 1), TERRAIN_TYPE_UNK_2); + + // Warp Tile ? + GetTileSafe(middleX - 1, middleY - 1)->unk4 |= 0x4; + GetTileSafe(middleX - 1, middleY - 1)->unk4 |= 0x40; + + // Items ? + GetTileSafe(middleX, middleY - 1)->unk4 |= 0x2; + GetTileSafe(middleX - 1, middleY)->unk4 |= 0x2; + GetTileSafe(middleX, middleY)->unk4 |= 0x2; + GetTileSafe(middleX - 1, middleY - 1)->unk4 |= 0x10; + GetTileSafe(middleX, middleY - 1)->unk4 |= 0x10; + GetTileSafe(middleX - 1, middleY)->unk4 |= 0x10; + GetTileSafe(middleX, middleY)->unk4 |= 0x10; + + gridCell->hasSecondaryStructure = TRUE; + } + } + break; + case SECONDARY_STRUCTURE_POOL: + if ((gridCell->end.x - gridCell->start.x) >= 5 && (gridCell->end.y - gridCell->start.y) >= 5) { + s32 curX, curY; + // Both dimensions are at least 5, generate a "pool" of water/lava + + s32 randX1 = DungeonRandRange(gridCell->start.x + 2, gridCell->end.x - 3); + s32 randY1 = DungeonRandRange(gridCell->start.y + 2, gridCell->end.y - 3); + s32 randX2 = DungeonRandRange(gridCell->start.x + 2, gridCell->end.x - 3); + s32 randY2 = DungeonRandRange(gridCell->start.y + 2, gridCell->end.y - 3); + + if (gUnknown_202F1C8 != 0) { + gUnknown_202F1C8--; + + SetSpawnFlag5(gridCell); + + if (randX1 > randX2) { + s32 temp; + SWAP(randX1, randX2, temp); + } + + if (randY1 > randY2) { + s32 temp; + SWAP(randY1, randY2, temp); + } + + for (curX = randX1; curX <= randX2; curX++) { + for (curY = randY1; curY <= randY2; curY++) { + SetTerrainSecondaryWithFlag(GetTileSafe(curX, curY), 0); + } + } + + gridCell->hasSecondaryStructure = TRUE; + } + } + break; + case SECONDARY_STRUCTURE_CHECKERBOARD: + if ((gridCell->end.x - gridCell->start.x) % 2 != 0 && (gridCell->end.y - gridCell->start.y) % 2 != 0 && gUnknown_202F1C8 != 0) { + s32 i; + // Dimensions are odd, generate diagonal stripes/checkerboard of water/lava + gUnknown_202F1C8--; + + SetSpawnFlag5(gridCell); + + for (i = 0; i < 64; i++) { + s32 randX = DungeonRandInt(gridCell->end.x - gridCell->start.x); + s32 randY = DungeonRandInt(gridCell->end.y - gridCell->start.y); + if ((randX + randY) % 2 != 0) { + SetTerrainSecondaryWithFlag(GetTileSafe(gridCell->start.x + randX, gridCell->start.y + randY), 0); + } + } + + gridCell->hasSecondaryStructure = TRUE; + } + break; + case SECONDARY_STRUCTURE_MAZE_PLUS_DOT: + if (gUnknown_202F1C8 != 0) { + gUnknown_202F1C8--; + + // If the dimensions are odd, generate a maze room + if ((gridCell->end.x - gridCell->start.x) % 2 == 0 || (gridCell->end.y - gridCell->start.y) % 2 == 0) { + s32 middleX = (gridCell->start.x + gridCell->end.x) / 2; + s32 middleY = (gridCell->start.y + gridCell->end.y) / 2; + if ((gridCell->end.x - gridCell->start.x) >= 5 && (gridCell->end.y - gridCell->start.y) >= 5) { + // Both dimensions are at least 5, generate a water/lava cross in the center + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY), 0); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY + 1), 0); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 1, middleY), 0); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY - 1), 0); + } + + // Generate a single water/lava spot in the center + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY), 0); + } + else { + // Both dimensions are odd. Generate a maze room + SetSpawnFlag5(gridCell); + GenerateMaze(gridCell, TRUE); + } + + gridCell->hasSecondaryStructure = TRUE; + } + break; + } +} + // From a71b26de359a75169e983a0419988344be5e683f Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 12 Nov 2024 13:23:47 +0100 Subject: [PATCH 16/30] rename unk4 to spawnOrVisibilityFlags --- include/structs/map.h | 14 +++++- src/code_8040094.c | 2 +- src/code_8045A00.c | 2 +- src/code_804AFAC.c | 28 +----------- src/code_806CD90.c | 6 +-- src/dungeon_generation.c | 94 ++++++++++++++++++++++++++++------------ src/dungeon_map_access.c | 8 ++-- src/tile_types.c | 6 +-- src/trap_1.c | 4 +- 9 files changed, 94 insertions(+), 70 deletions(-) diff --git a/include/structs/map.h b/include/structs/map.h index 287a7deda..ef01b9c39 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -35,13 +35,25 @@ enum CrossableTerrain NUM_CROSSABLE_TERRAIN }; +enum SpawnFlags +{ + SPAWN_FLAG_STAIRS = 1 << 0, // x1 - This tile has the stairs. + SPAWN_FLAG_ITEM = 1 << 1, // x2 - This tile has an item on it. + SPAWN_FLAG_TRAP = 1 << 2, // x4 - This tile has a trap on it. + SPAWN_FLAG_MONSTER = 1 << 3, // x8 - This tile has a monster on it. + SPAWN_FLAG_SPECIAL_TILE = 1 << 4, // x10 - This is a special tile, such as for Kecleon Shops, items, and traps. + SPAWN_FLAG_UNK5 = 1 << 5, // 0x20 - Not fully understood field relating to Secondary Structures. Set to true for all tiles in secondary structure rooms except for Cross or Dot rooms. + SPAWN_FLAG_UNK6 = 1 << 6, // 0x40 - Not fully understood field. In the dungeon algorithm, it is set to true on a Warp tile. + SPAWN_FLAG_UNK7 = 1 << 7, // 0x80 - Not fully understood field. In the dungeon algorithm, it is set to true for all tiles in a Divider secondary structure room. +}; + // size: 0x18 typedef struct Tile { // Uses the TerrainType bit flags. /* 0x0 */ u16 terrainType; u8 fill2[0x4 - 0x2]; - u16 unk4; + u16 spawnOrVisibilityFlags; // Tracks the kinds of entities which should be spawned on this tile. See: SpawnFlags u16 unk6; u8 unk8; /* 0x9 */ u8 room; diff --git a/src/code_8040094.c b/src/code_8040094.c index e54661ade..6716336fe 100644 --- a/src/code_8040094.c +++ b/src/code_8040094.c @@ -38,7 +38,7 @@ void HandleLuminousOrbAction(Entity *pokemon) for(XCoord = 0; XCoord < DUNGEON_MAX_SIZE_X; XCoord++) { mapTile = GetTileSafe(XCoord, YCoord); - mapTile->unk4 = mapTile->unk4 | 1; + mapTile->spawnOrVisibilityFlags |= 1; } } sub_803F580(0); diff --git a/src/code_8045A00.c b/src/code_8045A00.c index 5afb1a738..b505fd082 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -157,7 +157,7 @@ void sub_8045CB0(void) } tile = GetTile(x,y); - if (((tile->terrainType & TERRAIN_TYPE_STAIRS) == 0) && ((tile->unk4 & 2) != 0)) { + if (((tile->terrainType & TERRAIN_TYPE_STAIRS) == 0) && ((tile->spawnOrVisibilityFlags & 2) != 0)) { shopFlag = FALSE; pos.x = x; pos.y = y; diff --git a/src/code_804AFAC.c b/src/code_804AFAC.c index 5f2549bc0..e34409e0d 100644 --- a/src/code_804AFAC.c +++ b/src/code_804AFAC.c @@ -3,33 +3,7 @@ #include "dungeon_random.h" #include "structs/str_dungeon.h" -void sub_804FBE8(void) -{ - Tile *tile; - int y; - int x; - for(x = 0; x < DUNGEON_MAX_SIZE_X; x++) - { - for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) - { - tile = GetTileSafe(x,y); - if ((tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) != TERRAIN_TYPE_NORMAL) { - if ((tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL)) != 0) { - tile->unk4 &= 0xfffd; - } - tile->unk4 &= 0xfffb; - } - if ((tile->unk4 & 1) != 0) { - tile->terrainType |= TERRAIN_TYPE_STAIRS; - tile->unk4 &= 0xfffb; - } - if ((tile->unk4 & 2) != 0) { - tile->unk4 &= 0xfffb; - } - } - } -} void sub_804FC74(void) { @@ -71,7 +45,7 @@ void sub_804FCCC(void) void sub_804FD10(Tile *tile) { tile->terrainType = 0; - tile->unk4 = 0; + tile->spawnOrVisibilityFlags = 0; tile->room = -1; tile->unk8 = 0; tile->walkableNeighborFlags[CROSSABLE_TERRAIN_REGULAR] = 0; diff --git a/src/code_806CD90.c b/src/code_806CD90.c index 5003b230e..9b2c9febf 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -590,7 +590,7 @@ static bool8 HandleDealingDamageInternal(Entity *attacker, Entity *target, struc if (arg8 != 0 && sub_8045888(target)) { unkTile = GetTileAtEntitySafe(target); sub_803E708(0x14, 0x18); - unkTile->unk4 |= 4; + unkTile->spawnOrVisibilityFlags |= 4; sub_8049ED4(); } if (targetData->unk152 == 0) { @@ -687,7 +687,7 @@ static bool8 HandleDealingDamageInternal(Entity *attacker, Entity *target, struc if (unkTile != NULL) { - unkTile->unk4 &= ~(0x4); + unkTile->spawnOrVisibilityFlags &= ~(0x4); sub_8049ED4(); } return FALSE; @@ -702,7 +702,7 @@ static bool8 HandleDealingDamageInternal(Entity *attacker, Entity *target, struc sub_803E708(0x14, 0x18); target->unk22 = 2; sub_803E708(0xA, 0x18); - unkTile->unk4 &= ~(0x4); + unkTile->spawnOrVisibilityFlags &= ~(0x4); sub_8049ED4(); } else if (var_24) { diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 959b5e349..dc5742bff 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -33,7 +33,7 @@ extern void sub_804FD30(void); extern void sub_80518F0(void); extern void sub_804FCCC(void); extern void GenerateOneRoomMonsterHouseFloor(void); -extern void sub_804FBE8(void); +extern void ResolveInvalidSpawns(void); extern void sub_804FC74(void); void sub_804EB30(void); void sub_804E9DC(void); @@ -43,6 +43,7 @@ extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); extern const Position gAdjacentTileOffsets[]; +extern const bool8 gUnknown_80F6DD5[][NUM_DIRECTIONS]; void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); @@ -283,7 +284,7 @@ void sub_804AFAC(void) r4 = (DungeonRandInt(100) < unkPtr->connectedToTop); sub_804FF08(unkPtr, r4); sub_8050438(unkPtr, r4); - sub_804FBE8(); + ResolveInvalidSpawns(); if (gDungeon->unkE218.x != -1 && gDungeon->unkE218.y != -1) { if (GetFloorType() == 1) @@ -302,7 +303,7 @@ void sub_804AFAC(void) sub_804E9DC(); sub_804FF08(unkPtr, FALSE); sub_8050438(unkPtr, FALSE); - sub_804FBE8(); + ResolveInvalidSpawns(); } if (gUnknown_202F1D8.x >= 0 && gUnknown_202F1D8.y >= 0) { @@ -812,7 +813,7 @@ void NAKED sub_804AFAC(void) " mov r0, r8\n" " adds r1, r4, 0\n" " bl sub_8050438\n" -" bl sub_804FBE8\n" +" bl ResolveInvalidSpawns\n" " ldr r5, _0804B4C0\n" " ldr r1, [r5]\n" " ldr r6, _0804B4C8\n" @@ -888,7 +889,7 @@ void NAKED sub_804AFAC(void) " mov r0, r8\n" " movs r1, 0\n" " bl sub_8050438\n" -" bl sub_804FBE8\n" +" bl ResolveInvalidSpawns\n" "_0804B474:\n" " ldr r1, _0804B4B8\n" " movs r2, 0\n" @@ -2984,8 +2985,6 @@ void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN } } -extern const bool8 gUnknown_80F6DD5[][NUM_DIRECTIONS]; - /* * GenerateRoomImperfections - Attempt to generate room imperfections for each room, if flagged to do so. * @@ -3479,10 +3478,9 @@ void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 SetTerrainWall(tile); // Also remove any spawn flags - // TODO: rename to spawn_or_visibility_flags stairs/item/trap - tile->unk4 &= ~(0x1); - tile->unk4 &= ~(0x2); - tile->unk4 &= ~(0x4); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); } } } @@ -3502,9 +3500,9 @@ void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 SetTerrainWall(tile); // Remove any spawn flags - tile->unk4 &= ~(0x2); - tile->unk4 &= ~(0x1); - tile->unk4 &= ~(0x4); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); // Set room index to 0xFF (not a room) tile->room = CORRIDOR_ROOM; @@ -3736,8 +3734,8 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 tile->terrainType |= TERRAIN_TYPE_SHOP; // Restrict monsters and stairs from spawning here - tile->unk4 &= ~(0x8); - tile->unk4 &= ~(0x1); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_MONSTER); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); // Ensure the borders are assigned properly if (dungeon->kecleonShopPos.minX > curX) { @@ -3761,7 +3759,7 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 // Sets an unknown spawn flag for all tiles in the room for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { - GetTileSafe(curX, curY)->unk4 |= 0x10; + GetTileSafe(curX, curY)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; } } @@ -4205,7 +4203,7 @@ void SetSpawnFlag5(struct GridCell *gridCell) for (x = gridCell->start.x; x < gridCell->end.x; x++) { for (y = gridCell->start.y; y < gridCell->end.y; y++) { - GetTileSafe(x, y)->unk4 |= 0x20; + GetTileSafe(x, y)->spawnOrVisibilityFlags |= SPAWN_FLAG_UNK5; } } } @@ -4336,18 +4334,19 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY), TERRAIN_TYPE_UNK_2); SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY + 1), TERRAIN_TYPE_UNK_2); + // Trap + GetTileSafe(middleX - 1, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_TRAP; // Warp Tile ? - GetTileSafe(middleX - 1, middleY - 1)->unk4 |= 0x4; - GetTileSafe(middleX - 1, middleY - 1)->unk4 |= 0x40; + GetTileSafe(middleX - 1, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_UNK6; - // Items ? - GetTileSafe(middleX, middleY - 1)->unk4 |= 0x2; - GetTileSafe(middleX - 1, middleY)->unk4 |= 0x2; - GetTileSafe(middleX, middleY)->unk4 |= 0x2; - GetTileSafe(middleX - 1, middleY - 1)->unk4 |= 0x10; - GetTileSafe(middleX, middleY - 1)->unk4 |= 0x10; - GetTileSafe(middleX - 1, middleY)->unk4 |= 0x10; - GetTileSafe(middleX, middleY)->unk4 |= 0x10; + // Items + GetTileSafe(middleX, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + GetTileSafe(middleX - 1, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + GetTileSafe(middleX, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + GetTileSafe(middleX - 1, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; + GetTileSafe(middleX, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; + GetTileSafe(middleX - 1, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; + GetTileSafe(middleX, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; gridCell->hasSecondaryStructure = TRUE; } @@ -4438,4 +4437,43 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) } } +/* + * ResolveInvalidSpawns - Resolve any potentially invalid spawns on tiles. + * + * Obstacles can't spawn traps, impassable obstacles can't spawn items (you aren't able to reach them) + * + * A tile marked for the stairs must not have a trap there + * + * A tile marked for an item also must not have a trap there + */ +void ResolveInvalidSpawns(void) +{ + s32 x, y; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + Tile *tile = GetTileSafe(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) { + if (tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL)) { + // This tile is an impassable obstacle, make sure no items spawn here + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + } + // This tile is an obstacle, make sure no traps spawn here + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); + } + + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_STAIRS) { + // This tile has the stairs, make sure the stairs bit is set and + // make sure no traps spawn here + tile->terrainType |= TERRAIN_TYPE_STAIRS; + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); + } + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_ITEM) { + //This tile is an item spawn, make sure no traps spawn here + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); + } + } + } +} + // diff --git a/src/dungeon_map_access.c b/src/dungeon_map_access.c index 4c377963d..8aa0083f7 100644 --- a/src/dungeon_map_access.c +++ b/src/dungeon_map_access.c @@ -479,7 +479,7 @@ void sub_8049ED4(void) else if (hallucinating) { src = &dungeon->unk11884[tile->unk8][r7]; } - else if (tile->unk4 & 4) { + else if (tile->spawnOrVisibilityFlags & 4) { src = &dungeon->unk12BFE[r7]; } else @@ -524,7 +524,7 @@ void sub_8049ED4(void) else if (hallucinating) { src = &dungeon->unk11884[tile->unk8][r7]; } - else if (tile->unk4 & 4) { + else if (tile->spawnOrVisibilityFlags & 4) { src = &dungeon->unk12BFE[r7]; } else @@ -912,7 +912,7 @@ void sub_804AAAC(void) for(x = 0; x < DUNGEON_MAX_SIZE_X; x++) { tile = GetTileSafe(x,y); - tile->unk4 = 0; + tile->spawnOrVisibilityFlags = 0; } } } @@ -1024,7 +1024,7 @@ void sub_804AC20(Position *pos) for (y = yMin; y <= yMax; y++) { for (x = xMin; x <= xMax; x++) { tile = GetTileSafe(x,y); - tile->unk4 = tile->unk4 | 3; + tile->spawnOrVisibilityFlags = tile->spawnOrVisibilityFlags | 3; sub_80402AC(x,y); } } diff --git a/src/tile_types.c b/src/tile_types.c index 81692b41f..f00c7a4ba 100644 --- a/src/tile_types.c +++ b/src/tile_types.c @@ -170,7 +170,7 @@ bool8 sub_804AE08(Position *pos) if(!(tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL))) { uVar6 = TRUE; tile->terrainType = (tile->terrainType & ~(TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL)) | TERRAIN_TYPE_NORMAL; - tile->unk4 = tile->unk4 | 0x10; + tile->spawnOrVisibilityFlags = tile->spawnOrVisibilityFlags | 0x10; for(y = -1; y < 2; y++) { @@ -192,8 +192,8 @@ void sub_804AE84(Position *pos) s32 y; tile = GetTileSafe(pos->x,pos->y); - if ((tile->unk4 & 0x10) != 0) { - tile->unk4 = tile->unk4 & 0xffef; + if ((tile->spawnOrVisibilityFlags & 0x10) != 0) { + tile->spawnOrVisibilityFlags = tile->spawnOrVisibilityFlags & 0xffef; for(y = -1; y < 2; y++) { diff --git a/src/trap_1.c b/src/trap_1.c index 04c7e0134..ee7262aff 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -767,7 +767,7 @@ void SaveIQFlags(unkStruct_8094924 *r0, u8 *r1) void SaveTile(unkStruct_8094924 *r0, Tile *tile) { sub_8083030(r0, tile->terrainType); - sub_8083030(r0, tile->unk4); + sub_8083030(r0, tile->spawnOrVisibilityFlags); sub_8082FA8(r0, &tile->room, 1); sub_8082FA8(r0, &tile->unkE, 1); } @@ -866,7 +866,7 @@ void RestoreTile(unkStruct_8094924 *r0, Tile *tile) { memset(tile, 0, sizeof(Tile)); tile->terrainType = sub_8083158(r0); - tile->unk4 = sub_8083158(r0); + tile->spawnOrVisibilityFlags = sub_8083158(r0); sub_8082FE0(r0, (u32 *)&tile->room, 1); sub_8082FE0(r0, (u32 *)&tile->unkE, 1); From cb5242ba6c2f0cf361c08356f15d06a56addf0dc Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 12 Nov 2024 17:41:53 +0100 Subject: [PATCH 17/30] SpawnNonEnemies --- asm/code_804FD30.s | 687 +------------------------- include/dungeon_generation.h | 6 + include/structs/map.h | 2 +- include/structs/str_dungeon.h | 35 +- ld_script.txt | 1 - src/code_8045A00.c | 2 +- src/code_804AFAC.c | 126 ----- src/code_80718D8.c | 2 +- src/code_807CD9C.c | 7 +- src/dungeon_generation.c | 890 ++++++++++++++++++++++++++-------- src/dungeon_util.c | 2 +- src/tile_types.c | 4 +- src/trap_1.c | 12 +- sym_ewram.txt | 29 +- 14 files changed, 725 insertions(+), 1080 deletions(-) delete mode 100644 src/code_804AFAC.c diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index 350c44135..1801adf9b 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -5,679 +5,6 @@ .text - thumb_func_start sub_804FF08 -sub_804FF08: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _08050234 - add sp, r4 - mov r10, r0 - lsls r1, 24 - lsrs r1, 24 - movs r0, 0xE0 - lsls r0, 5 - add r0, sp - str r1, [r0] - ldr r0, _08050238 - ldr r0, [r0] - mov r9, r0 - ldr r0, _0805023C - add r0, r9 - movs r1, 0 - ldrsh r0, [r0, r1] - movs r1, 0x1 - negs r1, r1 - cmp r0, r1 - beq _0804FF46 - ldr r0, _08050240 - add r0, r9 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, r1 - bne _08050038 -_0804FF46: - movs r0, 0 - mov r8, r0 - movs r6, 0 -_0804FF4C: - movs r5, 0 - mov r1, r8 - lsls r0, r1, 2 - mov r2, sp - adds r4, r0, r2 -_0804FF56: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - adds r1, r0, 0 - ldrh r2, [r1] - movs r0, 0x3 - ands r0, r2 - cmp r0, 0x1 - bne _0804FFAA - ldrb r0, [r1, 0x9] - cmp r0, 0xFF - beq _0804FFAA - movs r0, 0x20 - ands r0, r2 - cmp r0, 0 - bne _0804FFAA - ldrh r1, [r1, 0x4] - movs r3, 0x8 - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - bne _0804FFAA - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - bne _0804FFAA - adds r0, r3, 0 - ands r0, r2 - cmp r0, 0 - bne _0804FFAA - movs r1, 0x80 - lsls r1, 1 - adds r0, r1, 0 - ands r0, r2 - cmp r0, 0 - bne _0804FFAA - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r2, 0x1 - add r8, r2 -_0804FFAA: - adds r5, 0x1 - cmp r5, 0x1F - ble _0804FF56 - adds r6, 0x1 - cmp r6, 0x37 - ble _0804FF4C - mov r0, r8 - cmp r0, 0 - beq _08050038 - bl DungeonRandInt - lsls r0, 2 - mov r1, sp - adds r4, r1, r0 - ldrb r0, [r4] - ldrb r1, [r4, 0x1] - bl GetTileSafe - adds r5, r0, 0 - ldrh r1, [r5, 0x4] - movs r0, 0x1 - orrs r0, r1 - ldr r1, _08050244 - ands r0, r1 - strh r0, [r5, 0x4] - ldr r1, _08050248 - ldrb r0, [r5, 0x9] - strb r0, [r1] - ldrb r1, [r4] - ldr r0, _0805023C - add r0, r9 - strh r1, [r0] - ldrb r1, [r4, 0x1] - ldr r0, _08050240 - add r0, r9 - strh r1, [r0] - bl GetFloorType - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _08050038 - ldrb r4, [r5, 0x9] - movs r6, 0 -_08050002: - movs r5, 0 -_08050004: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTileSafe - adds r1, r0, 0 - ldrh r2, [r1] - movs r0, 0x3 - ands r0, r2 - cmp r0, 0x1 - bne _0805002C - ldrb r0, [r1, 0x9] - cmp r0, r4 - bne _0805002C - movs r0, 0x40 - orrs r0, r2 - strh r0, [r1] - ldrb r1, [r1, 0x9] - ldr r0, _0805024C - add r0, r9 - strb r1, [r0] -_0805002C: - adds r5, 0x1 - cmp r5, 0x1F - ble _08050004 - adds r6, 0x1 - cmp r6, 0x37 - ble _08050002 -_08050038: - movs r2, 0 - mov r8, r2 - movs r6, 0 -_0805003E: - movs r5, 0 - adds r7, r6, 0x1 - mov r1, r8 - lsls r0, r1, 2 - mov r2, sp - adds r4, r0, r2 -_0805004A: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - adds r1, r0, 0 - ldrh r2, [r1] - movs r0, 0x3 - ands r0, r2 - cmp r0, 0x1 - bne _08050092 - ldrb r0, [r1, 0x9] - cmp r0, 0xFF - beq _08050092 - movs r0, 0x20 - ands r0, r2 - cmp r0, 0 - bne _08050092 - movs r0, 0x40 - ands r0, r2 - cmp r0, 0 - bne _08050092 - movs r0, 0x8 - ands r0, r2 - cmp r0, 0 - bne _08050092 - movs r1, 0x80 - lsls r1, 1 - adds r0, r1, 0 - ands r0, r2 - cmp r0, 0 - bne _08050092 - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r2, 0x1 - add r8, r2 -_08050092: - adds r5, 0x1 - cmp r5, 0x1F - ble _0805004A - adds r6, r7, 0 - cmp r6, 0x37 - ble _0805003E - mov r0, r8 - cmp r0, 0 - beq _080500FA - mov r1, r10 - ldrb r4, [r1, 0xF] - cmp r4, 0 - beq _080500FA - subs r0, r4, 0x2 - adds r1, r4, 0x2 - bl DungeonRandRange - adds r4, r0, 0 - cmp r4, 0 - bgt _080500BC - movs r4, 0x1 -_080500BC: - mov r0, sp - mov r1, r8 - bl sub_804FED0 - mov r0, r8 - bl DungeonRandInt - adds r5, r0, 0 - cmp r4, 0 - ble _080500FA - adds r6, r4, 0 - lsls r0, r5, 2 - mov r2, sp - adds r4, r0, r2 -_080500D8: - ldrb r0, [r4] - ldrb r1, [r4, 0x1] - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x2 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x4 - adds r5, 0x1 - cmp r5, r8 - bne _080500F4 - mov r4, sp - movs r5, 0 -_080500F4: - subs r6, 0x1 - cmp r6, 0 - bne _080500D8 -_080500FA: - movs r0, 0 - mov r8, r0 - movs r6, 0 -_08050100: - movs r5, 0 - adds r7, r6, 0x1 - mov r1, r8 - lsls r0, r1, 2 - mov r2, sp - adds r4, r0, r2 -_0805010C: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - bne _08050128 - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r0, 0x1 - add r8, r0 -_08050128: - adds r5, 0x1 - cmp r5, 0x1F - ble _0805010C - adds r6, r7, 0 - cmp r6, 0x37 - ble _08050100 - mov r1, r8 - cmp r1, 0 - beq _0805018E - mov r2, r10 - ldrb r4, [r2, 0x14] - cmp r4, 0 - beq _0805018E - subs r0, r4, 0x2 - adds r1, r4, 0x2 - bl DungeonRandRange - adds r4, r0, 0 - cmp r4, 0 - ble _0805018E - mov r0, sp - mov r1, r8 - bl sub_804FED0 - mov r0, r8 - bl DungeonRandInt - adds r5, r0, 0 - cmp r4, 0 - ble _0805018E - adds r6, r4, 0 - lsls r0, r5, 2 - mov r1, sp - adds r4, r0, r1 -_0805016C: - ldrb r0, [r4] - ldrb r1, [r4, 0x1] - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x2 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x4 - adds r5, 0x1 - cmp r5, r8 - bne _08050188 - mov r4, sp - movs r5, 0 -_08050188: - subs r6, 0x1 - cmp r6, 0 - bne _0805016C -_0805018E: - movs r2, 0 - mov r8, r2 - movs r0, 0xE0 - lsls r0, 5 - add r0, sp - ldr r0, [r0] - cmp r0, 0 - bne _080501E4 - movs r6, 0 -_080501A0: - movs r5, 0 - adds r7, r6, 0x1 - mov r1, r8 - lsls r0, r1, 2 - mov r2, sp - adds r4, r0, r2 -_080501AC: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - bne _080501D8 - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _080501D8 - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - bne _080501D8 - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r0, 0x1 - add r8, r0 -_080501D8: - adds r5, 0x1 - cmp r5, 0x1F - ble _080501AC - adds r6, r7, 0 - cmp r6, 0x37 - ble _080501A0 -_080501E4: - mov r1, r8 - cmp r1, 0 - beq _08050294 - lsrs r4, r1, 31 - add r4, r8 - asrs r4, 1 - lsls r0, r1, 3 - movs r1, 0xA - bl __divsi3 - adds r1, r0, 0 - adds r0, r4, 0 - bl DungeonRandRange - adds r4, r0, 0 - cmp r4, 0x5 - bgt _08050208 - movs r4, 0x6 -_08050208: - ldr r0, _08050250 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r4, r0 - blt _08050214 - adds r4, r0, 0 -_08050214: - mov r0, sp - mov r1, r8 - bl sub_804FED0 - mov r0, r8 - bl DungeonRandInt - adds r5, r0, 0 - cmp r4, 0 - ble _08050294 - adds r6, r4, 0 - lsls r0, r5, 2 - mov r1, sp - adds r7, r0, r1 -_08050230: - ldrb r0, [r7] - b _08050254 - .align 2, 0 -_08050234: .4byte 0xffffe3fc -_08050238: .4byte gDungeon -_0805023C: .4byte 0x0000e21c -_08050240: .4byte 0x0000e21e -_08050244: .4byte 0x0000fffd -_08050248: .4byte gUnknown_202F1B4 -_0805024C: .4byte 0x00003a0c -_08050250: .4byte gUnknown_80F4DA0 -_08050254: - ldrb r1, [r7, 0x1] - bl GetTileSafe - adds r4, r0, 0 - movs r0, 0x2 - bl DungeonRandInt - cmp r0, 0 - beq _0805026C - ldrh r0, [r4, 0x4] - movs r1, 0x2 - b _0805027E -_0805026C: - ldr r0, _08050424 - ldr r0, [r0] - ldr r2, _08050428 - adds r0, r2 - ldrb r0, [r0] - cmp r0, 0 - beq _08050282 - ldrh r0, [r4, 0x4] - movs r1, 0x4 -_0805027E: - orrs r0, r1 - strh r0, [r4, 0x4] -_08050282: - adds r7, 0x4 - adds r5, 0x1 - cmp r5, r8 - bne _0805028E - mov r7, sp - movs r5, 0 -_0805028E: - subs r6, 0x1 - cmp r6, 0 - bne _08050230 -_08050294: - movs r0, 0 - mov r8, r0 - movs r6, 0 -_0805029A: - movs r5, 0 - adds r7, r6, 0x1 - mov r1, r8 - lsls r0, r1, 2 - mov r2, sp - adds r4, r0, r2 -_080502A6: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - adds r1, r0, 0 - ldrh r2, [r1] - movs r0, 0x3 - ands r0, r2 - cmp r0, 0x1 - bne _080502F0 - ldrb r0, [r1, 0x9] - cmp r0, 0xFF - beq _080502F0 - movs r0, 0x20 - ands r0, r2 - cmp r0, 0 - bne _080502F0 - ldrh r1, [r1, 0x4] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _080502F0 - movs r0, 0x8 - ands r0, r2 - cmp r0, 0 - bne _080502F0 - movs r1, 0x80 - lsls r1, 1 - adds r0, r1, 0 - ands r0, r2 - cmp r0, 0 - bne _080502F0 - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r2, 0x1 - add r8, r2 -_080502F0: - adds r5, 0x1 - cmp r5, 0x1F - ble _080502A6 - adds r6, r7, 0 - cmp r6, 0x37 - ble _0805029A - mov r0, r8 - cmp r0, 0 - beq _08050356 - mov r2, r10 - ldrb r1, [r2, 0x10] - lsrs r0, r1, 1 - bl DungeonRandRange - adds r4, r0, 0 - cmp r4, 0 - ble _08050356 - cmp r4, 0x37 - ble _08050318 - movs r4, 0x38 -_08050318: - mov r0, sp - mov r1, r8 - bl sub_804FED0 - mov r0, r8 - bl DungeonRandInt - adds r5, r0, 0 - cmp r4, 0 - ble _08050356 - adds r6, r4, 0 - lsls r0, r5, 2 - mov r1, sp - adds r4, r0, r1 -_08050334: - ldrb r0, [r4] - ldrb r1, [r4, 0x1] - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x4 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x4 - adds r5, 0x1 - cmp r5, r8 - bne _08050350 - mov r4, sp - movs r5, 0 -_08050350: - subs r6, 0x1 - cmp r6, 0 - bne _08050334 -_08050356: - ldr r0, _0805042C - add r0, r9 - movs r2, 0 - ldrsh r0, [r0, r2] - movs r1, 0x1 - negs r1, r1 - cmp r0, r1 - beq _08050372 - ldr r0, _08050430 - add r0, r9 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, r1 - bne _08050410 -_08050372: - movs r0, 0 - mov r8, r0 - movs r6, 0 -_08050378: - movs r5, 0 - adds r7, r6, 0x1 - mov r1, r8 - lsls r0, r1, 2 - mov r2, sp - adds r4, r0, r2 -_08050384: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - adds r2, r0, 0 - ldrh r1, [r2] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _080503E2 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _080503E2 - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - bne _080503E2 - movs r3, 0x8 - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - bne _080503E2 - movs r0, 0x80 - lsls r0, 1 - mov r10, r0 - mov r0, r10 - ands r0, r1 - cmp r0, 0 - bne _080503E2 - ldrh r1, [r2, 0x4] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _080503E2 - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - bne _080503E2 - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - bne _080503E2 - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r1, 0x1 - add r8, r1 -_080503E2: - adds r5, 0x1 - cmp r5, 0x1F - ble _08050384 - adds r6, r7, 0 - cmp r6, 0x37 - ble _08050378 - mov r2, r8 - cmp r2, 0 - beq _08050410 - mov r0, r8 - bl DungeonRandInt - lsls r0, 2 - mov r1, sp - adds r2, r1, r0 - ldrb r1, [r2] - ldr r0, _0805042C - add r0, r9 - strh r1, [r0] - ldrb r1, [r2, 0x1] - ldr r0, _08050430 - add r0, r9 - strh r1, [r0] -_08050410: - ldr r3, _08050434 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08050424: .4byte gDungeon -_08050428: .4byte 0x0000065c -_0805042C: .4byte 0x0000e218 -_08050430: .4byte 0x0000e21a -_08050434: .4byte 0x00001c04 - thumb_func_end sub_804FF08 - thumb_func_start sub_8050438 sub_8050438: push {r4-r7,lr} @@ -801,7 +128,7 @@ _0805051C: beq _0805055E mov r0, sp mov r1, r8 - bl sub_804FED0 + bl ShuffleSpawnPositions mov r0, r8 bl DungeonRandInt adds r5, r0, 0 @@ -956,7 +283,7 @@ _0805063E: _0805064E: mov r0, sp mov r1, r8 - bl sub_804FED0 + bl ShuffleSpawnPositions mov r0, r8 bl DungeonRandInt adds r5, r0, 0 @@ -3169,7 +2496,7 @@ _080516E4: str r0, [r6] b _08051724 .align 2, 0 -_080516EC: .4byte gUnknown_202F1B8 +_080516EC: .4byte sKecleonShopPosition _080516F0: .4byte 0x0000ffdf _080516F4: ldr r0, [r6, 0x8] @@ -3248,7 +2575,7 @@ _0805177C: str r0, [r6, 0x4] b _080517BC .align 2, 0 -_08051784: .4byte gUnknown_202F1B8 +_08051784: .4byte sKecleonShopPosition _08051788: .4byte 0x0000ffdf _0805178C: ldr r0, [r6, 0xC] @@ -3432,7 +2759,7 @@ _080518D2: pop {r0} bx r0 .align 2, 0 -_080518E4: .4byte gUnknown_202F1B8 +_080518E4: .4byte sKecleonShopPosition _080518E8: .4byte 0x0000ffdf _080518EC: .4byte gUnknown_80F57D4 thumb_func_end sub_8051654 @@ -3448,7 +2775,7 @@ _080518F8: movs r1, 0x1 bl GetTileSafe adds r4, r0, 0 - bl sub_804FD10 + bl ResetTile cmp r5, 0 beq _0805190E cmp r5, 0x37 @@ -3462,7 +2789,7 @@ _08051914: movs r1, 0x1E bl GetTileSafe adds r4, r0, 0 - bl sub_804FD10 + bl ResetTile cmp r5, 0 beq _0805192A cmp r5, 0x37 diff --git a/include/dungeon_generation.h b/include/dungeon_generation.h index 777d3693d..509d410cf 100644 --- a/include/dungeon_generation.h +++ b/include/dungeon_generation.h @@ -9,6 +9,12 @@ #define GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE 60 // (0 to 100) probability that a room will not have imperfections, if it was already flagged for them #define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 // (0 to 100) probability that a room will be flagged to have a secondary structure. +enum FloorSize { + FLOOR_SIZE_LARGE, + FLOOR_SIZE_SMALL, + FLOOR_SIZE_MEDIUM, +}; + enum FloorType { FLOOR_TYPE_NORMAL, FLOOR_TYPE_FIXED, // Fixed room diff --git a/include/structs/map.h b/include/structs/map.h index ef01b9c39..9553558bb 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -19,7 +19,7 @@ enum TerrainType TERRAIN_TYPE_SHOP = 1 << 5, // x20 TERRAIN_TYPE_IN_MONSTER_HOUSE = 1 << 6, // x40 TERRAIN_TYPE_UNK_7 = 1 << 7, // x80 - TERRAIN_TYPE_UNK_8 = 1 << 8, // x100 + TERRAIN_TYPE_UNBREAKABLE = 1 << 8, // x100 // Cannot be broken by Absolute Mover. Set naturally on key doors. TERRAIN_TYPE_STAIRS = 1 << 9, // x200 TERRAIN_TYPE_UNK_x400 = 1 << 10, TERRAIN_TYPE_UNK_x800 = 1 << 11, diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 93871dfb8..e600e3d27 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -113,30 +113,33 @@ typedef struct UnkDungeonGlobal_unk181E8_sub s16 unk42; // x42 } UnkDungeonGlobal_unk181E8_sub; // x44 +#define ROOM_FLAG_ALLOW_SECONDARY_TERRAIN 0x1 +#define ROOM_FLAG_ALLOW_IMPERFECTIONS 0x4 + // Sizeof: 0x1C typedef struct UnkDungeonGlobal_unk1C574 { u8 unk0; - s8 unk1; + s8 roomDensity; u8 unk2; u8 unk3; u8 unk4; - u8 unk5; + u8 floorConnectivity; u8 unk6; - u8 unk7; - u8 unk8; - u8 unk9; + u8 kecleonShopChance; // Percentage chance 0-100% + u8 monsterHouseChance; // Percentage chance 0-100% + u8 mazeRoomChance; // Percentage chance 0-100% u8 unkA; - u8 unkB; - u8 unkC; - u8 unkD; + bool8 allowDeadEnds; + u8 secondaryStructuresBudget; // Maximum number of secondary structures that can be generated + u8 roomFlags; // See ROOM_FLAG_ u8 unkE; - u8 unkF; - u8 unk10; + u8 itemDensity; + u8 trapDensity; u8 unk11; u8 unk12; - u8 unk13; - u8 unk14; + u8 numExtraHallways; + u8 buriedItemDensity; // Density of buried items (in walls) u8 unk15; u8 unk16; u8 unk17; @@ -342,13 +345,13 @@ typedef struct Dungeon /* 0x37FE */ u8 unk37FF; s16 unk3800; u8 fill3802[0x3904 - 0x3802]; - /* 0x3904 */ s16 unk3904; + /* 0x3904 */ s16 numItems; u8 fill3906[0x3A08 - 0x3906]; /* 0x3A08 */ u8 unk3A08; /* 0x3A09 */ u8 unk3A09; /* 0x3A0A */ u8 unk3A0A; /* 0x3A0B */ u8 unk3A0B; - u8 unk3A0C; + /* 0x3A0C */ u8 monsterHouseRoom; // room index of monster house /* 0x3A0D */ u8 unk3A0D; /* 0x3A0E */ s16 tileset; /* 0x3A10 */ s16 unk3A10; @@ -356,8 +359,8 @@ typedef struct Dungeon /* 0x3A14 */ s16 bossBattleIndex; /* 0x3A16 */ s16 unk3A16; /* 0x3A18 */ Tile tiles[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X]; - Position unkE218; - Position unkE21C; // stair location? + /* 0xEA18 */ Position playerSpawn; + Position stairsSpawn; // stairs location Position unkE220[8]; struct MinMaxPosition kecleonShopPos; u32 unkE250; diff --git a/ld_script.txt b/ld_script.txt index 7482d6939..177f2b02e 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -229,7 +229,6 @@ SECTIONS { src/dungeon_map_access.o(.text); src/tile_types.o(.text); src/dungeon_generation.o(.text); - src/code_804AFAC.o(.text); asm/code_804FD30.o(.text); src/dungeon_message.o(.text); src/dungeon_move.o(.text); diff --git a/src/code_8045A00.c b/src/code_8045A00.c index b505fd082..84c307a43 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -140,7 +140,7 @@ void sub_8045CB0(void) x = DungeonRandInt(DUNGEON_MAX_SIZE_X); y = DungeonRandInt(DUNGEON_MAX_SIZE_Y); - gDungeon->unk3904 = 0; + gDungeon->numItems = 0; for(yCounter = 0; yCounter < DUNGEON_MAX_SIZE_Y; yCounter++) { y++; diff --git a/src/code_804AFAC.c b/src/code_804AFAC.c deleted file mode 100644 index e34409e0d..000000000 --- a/src/code_804AFAC.c +++ /dev/null @@ -1,126 +0,0 @@ -#include "global.h" -#include "dungeon_map_access.h" -#include "dungeon_random.h" -#include "structs/str_dungeon.h" - - - -void sub_804FC74(void) -{ - Tile *tile; - int y; - int x; - - for(x = 0; x < DUNGEON_MAX_SIZE_X; x++) - { - for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) - { - if ((GetTile(x, y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_SECONDARY) { - tile = GetTileSafe(x,y); - tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - tile->terrainType |= (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - } - } - } -} - -void sub_804FCCC(void) -{ - Tile *tile; - int y; - int x; - - for(x = 0; x < DUNGEON_MAX_SIZE_X; x++) - { - for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) - { - if ((GetTile(x, y)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) != 0) { - tile = GetTileSafe(x,y); - tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - } - } - } -} - -void sub_804FD10(Tile *tile) -{ - tile->terrainType = 0; - tile->spawnOrVisibilityFlags = 0; - tile->room = -1; - tile->unk8 = 0; - tile->walkableNeighborFlags[CROSSABLE_TERRAIN_REGULAR] = 0; - tile->walkableNeighborFlags[CROSSABLE_TERRAIN_LIQUID] = 0; - tile->walkableNeighborFlags[CROSSABLE_TERRAIN_CREVICE] = 0; - tile->walkableNeighborFlags[CROSSABLE_TERRAIN_WALL] = 0; - tile->unkE = 0; - tile->monster = NULL; - tile->object = NULL; -} - -bool8 static inline boundsCheck(int x, int y) -{ - if (x < 0 || (y < 0)) return TRUE; - if (DUNGEON_MAX_SIZE_X <= x) return TRUE; - if (DUNGEON_MAX_SIZE_Y <= y) return TRUE; - return FALSE; -} - -void sub_804FD30(void) -{ - int x; - int y; - - for(x = 0; x < DUNGEON_MAX_SIZE_X; x++) - { - for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) - { - sub_804FD10(GetTileSafe(x,y)); - - if ((boundsCheck(x, y - 1)) || - (boundsCheck(x + 1, y - 1)) || - (boundsCheck(x + 1, y - 1)) || - (boundsCheck(x + 1, y + 1)) || - (boundsCheck(x, y + 1)) || - (boundsCheck(x - 1, y + 1)) || - (boundsCheck(x - 1, y)) || - (boundsCheck(x - 1, y - 1))) - { - GetTileSafe(x,y)->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; - } - } - } - - gDungeon->unkE21C.x = -1; - gDungeon->unkE21C.y = -1; - - for(x = 0; x < 8; x++) - { - for(y = 0; y < 8; y++) - { - sub_804FD10(&gDungeon->unkE27C[x][y]); - } - } - - gDungeon->unk3904 = 0; - for(x = 0; x < 0x40; x++) - { - gDungeon->traps[x]->type = 0; - } -} - - -void sub_804FED0(s32 *param_1, s32 param_2) -{ - int idx1; - int idx2; - s32 temp; - int counter; - - for (counter = 0; counter < param_2 << 1; counter++) { - idx1 = DungeonRandInt(param_2); - idx2 = DungeonRandInt(param_2); - temp = param_1[idx1]; - param_1[idx1] = param_1[idx2]; - param_1[idx2] = temp; - } -} diff --git a/src/code_80718D8.c b/src/code_80718D8.c index 4865f5e23..2af04263f 100644 --- a/src/code_80718D8.c +++ b/src/code_80718D8.c @@ -118,7 +118,7 @@ void sub_8071B48(void) } } if (dungeon->unk66E == 0) { - if (gDungeon->unk3A0C == 0xff) { + if (gDungeon->monsterHouseRoom == 0xff) { if (counter >= gUnknown_80F4DA6) { return; } diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index de204c76b..19cb58310 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -220,7 +220,6 @@ void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, Position *pos) EntityInfo *info; u32 direction; Position local_2c; - Position pos2; bool8 flag; info = GetEntInfo(target); @@ -237,8 +236,8 @@ void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, Position *pos) } if (param_3 == 1) { - pos2 = gDungeon->unkE21C; - if(pos2.x == target->pos.x && pos2.y == target->pos.y) { + Position stairsPosition = gDungeon->stairsSpawn; + if(stairsPosition.x == target->pos.x && stairsPosition.y == target->pos.y) { TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC9A0); // It's already on the stairs! PetrifiedStatusTarget(pokemon,target); return; @@ -273,7 +272,7 @@ void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, Position *pos) } break; case 1: - if (!sub_808384C(&local_2c,&gDungeon->unkE21C)) { + if (!sub_808384C(&local_2c,&gDungeon->stairsSpawn)) { local_2c = target->pos; flag = TRUE; } diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index dc5742bff..c23e3dba6 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -11,32 +11,14 @@ extern const u8 gUnknown_80F6DCC[]; extern struct FileArchive gDungeonFileArchive; -extern bool8 gUnknown_202F1AA; -extern u8 gUnknown_202F1AB; -extern bool8 gUnknown_202F1AC; -extern u8 gUnknown_202F1A8; -extern u8 gUnknown_202F1B4; -extern u8 gUnknown_202F1AE; -extern u8 gUnknown_202F1AD; -extern u8 gUnknown_202F1A9; -extern s16 gUnknown_202F1B0; -extern s16 gUnknown_202F1B2; -extern s32 gUnknown_202F1C8; -extern s32 gUnknown_202F1D0; -extern s32 gUnknown_202F1CC; extern Position gUnknown_202F1D8; -extern struct MinMaxPosition gUnknown_202F1B8; -extern void sub_804FD30(void); -extern void sub_804FD30(void); +extern void ResetFloor(void); +extern void ResetFloor(void); extern void sub_80518F0(void); -extern void sub_804FCCC(void); extern void GenerateOneRoomMonsterHouseFloor(void); extern void ResolveInvalidSpawns(void); -extern void sub_804FC74(void); -void sub_804EB30(void); -void sub_804E9DC(void); extern void GenerateTwoRoomsWithMonsterHouseFloor(void); extern u8 GetFloorType(); extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); @@ -45,6 +27,76 @@ extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); extern const Position gAdjacentTileOffsets[]; extern const bool8 gUnknown_80F6DD5[][NUM_DIRECTIONS]; +enum CardinalDirection +{ + CARDINAL_DIR_RIGHT, + CARDINAL_DIR_UP, + CARDINAL_DIR_LEFT, + CARDINAL_DIR_DOWN, + NUM_CARDINAL_DIRECTIONS +}; + +#define CARDINAL_DIRECTION_MASK 3 + +struct GridCell +{ + Position start; + Position end; + bool8 isInvalid; + bool8 hasSecondaryStructure; + bool8 isRoom; + bool8 isConnected; + bool8 isKecleonShop; + bool8 unk13; + bool8 isMonsterHouse; + bool8 unk15; + bool8 isMazeRoom; + bool8 hasBeenMerged; + bool8 isMerged; + bool8 connectedToTop; + bool8 connectedToBottom; + bool8 connectedToLeft; + bool8 connectedToRight; + bool8 shouldConnectToTop; + bool8 shouldConnectToBottom; + bool8 shouldConnectToLeft; + bool8 shouldConnectToRight; + bool8 unk27; + bool8 flagImperfect; + bool8 flagSecondaryStructure; + bool8 unk30; + bool8 unk31; +}; + +#define GRID_CELL_LEN 15 + +void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); +void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 x2, s32 y2); +void sub_8051438(struct GridCell *gridCell, s32 a1); +extern void sub_8051288(s32 a0); +void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); +void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +void GenerateSecondaryStructure(struct GridCell *gridCell); +void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber); +void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); +void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); +void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY); +static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr); +void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr); +void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain); +void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex); +void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); +static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); +void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s32 turnX, s32 turnY); +void EnsureImpassableTilesAreWalls(void); +void sub_804FC74(void); +void sub_804EB30(void); +void sub_804E9DC(void); void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); void GenerateStandardFloor(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); @@ -56,10 +108,25 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr); void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); void sub_80506F0(s32 a0, UnkDungeonGlobal_unk1C574 *a1); -void sub_804FF08(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); -void sub_8050438(UnkDungeonGlobal_unk1C574 *a0, bool8 a1); +void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); +void sub_8050438(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); -struct FileFixedmapPosStruct +EWRAM_DATA u8 gUnknown_202F1A8 = 0; +EWRAM_DATA u8 gUnknown_202F1A9 = 0; +static EWRAM_DATA bool8 sHasKecleonShop = FALSE; +EWRAM_DATA bool8 sHasMonsterHouse = FALSE; +static EWRAM_DATA bool8 sHasMaze = FALSE; +static EWRAM_DATA bool8 sSecondSpawn = FALSE; +static EWRAM_DATA u8 sFloorSize = 0; +static EWRAM_DATA s16 sKecleonShopChance = 0; +static EWRAM_DATA s16 sMonsterHouseChance = 0; +static EWRAM_DATA u8 sStairsRoomIndex = 0; +EWRAM_DATA struct MinMaxPosition sKecleonShopPosition = {0}; +static EWRAM_DATA s32 sSecondaryStructuresBudget = 0; +static EWRAM_DATA s32 sNumRooms = 0; +EWRAM_DATA s32 gUnknown_202F1D0 = 0; + +struct PositionU8 { u8 x; u8 y; @@ -102,47 +169,47 @@ void sub_804AFAC(void) UnkDungeonGlobal_unk1C574 *unkPtr = &gDungeon->unk1C574; gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); - gUnknown_202F1AA = FALSE; - gUnknown_202F1AB = 0; - gUnknown_202F1AC = FALSE; + sHasKecleonShop = FALSE; + sHasMonsterHouse = 0; + sHasMaze = FALSE; gUnknown_202F1A8 = (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_WATER); - gUnknown_202F1B4 = 0xFF; - gUnknown_202F1AE = 0; - gUnknown_202F1B0 = unkPtr->unk7; - gUnknown_202F1B2 = unkPtr->unk8; - gUnknown_202F1AD = 1; - gUnknown_202F1B8.unk0 = -1; - gUnknown_202F1B8.unk8 = -1; - gUnknown_202F1B8.unk4 = -1; - gUnknown_202F1B8.unkC = -1; + sStairsRoomIndex = 0xFF; + sFloorSize = 0; + sKecleonShopChance = unkPtr->kecleonShopChance; + sMonsterHouseChance = unkPtr->monsterHouseChance; + sSecondSpawn = 1; + sKecleonShopPosition.unk0 = -1; + sKecleonShopPosition.unk8 = -1; + sKecleonShopPosition.unk4 = -1; + sKecleonShopPosition.unkC = -1; - sub_804FD30(); + ResetFloor(); gDungeon->unk664 = unkPtr->unk6; gDungeon->unk3A09 = 0; gDungeon->unk3A0A = 0; - gUnknown_202F1C8 = unkPtr->unkC; + sSecondaryStructuresBudget = unkPtr->secondaryStructuresBudget; for (i = 0; i < 10; i++) { bool32 r4 = 0; - gDungeon->unkE218.x = -1; - gDungeon->unkE218.y = -1; - gDungeon->unkE21C.x = -1; - gDungeon->unkE21C.y = -1; + gDungeon->playerSpawn.x = -1; + gDungeon->playerSpawn.y = -1; + gDungeon->stairsSpawn.x = -1; + gDungeon->stairsSpawn.y = -1; for (j = 0; j < 10; j++) { gDungeon->unk3A16 = j; if (j > 0) { - gUnknown_202F1C8 = 0; + sSecondaryStructuresBudget = 0; } gUnknown_202F1A9 = 0; gUnknown_202F1D8.x = -1; gUnknown_202F1D8.y = -1; - sub_804FD30(); - gDungeon->unkE218.x = -1; - gDungeon->unkE218.y = -1; + ResetFloor(); + gDungeon->playerSpawn.x = -1; + gDungeon->playerSpawn.y = -1; gDungeon->unk3A08 = 0; if (gDungeon->bossBattleIndex != 0) { if (sub_804C70C(gDungeon->bossBattleIndex, unkPtr)) { @@ -181,18 +248,18 @@ void sub_804AFAC(void) } gDungeon->unk3A08 = 0; - gDungeon->unk3A0C = 0xFF; + gDungeon->monsterHouseRoom = 0xFF; gUnknown_202F1D0 = r7; switch (r7 & 0xF) { case 1: y = DungeonRandInt(2) + 2; - gUnknown_202F1AE = 1; + sFloorSize = 1; GenerateStandardFloor(4, y, unkPtr); r10 = TRUE; break; case 11: y = DungeonRandInt(2) + 2; - gUnknown_202F1AE = 2; + sFloorSize = 2; GenerateStandardFloor(4, y, unkPtr); r10 = TRUE; break; @@ -235,7 +302,7 @@ void sub_804AFAC(void) } sub_80518F0(); - sub_804FCCC(); + EnsureImpassableTilesAreWalls(); if (gUnknown_202F1A9 == 0) { s32 countSp = 0; u8 spArray[64]; @@ -282,14 +349,14 @@ void sub_804AFAC(void) sub_80506F0(1, unkPtr); } r4 = (DungeonRandInt(100) < unkPtr->connectedToTop); - sub_804FF08(unkPtr, r4); + SpawnNonEnemies(unkPtr, r4); sub_8050438(unkPtr, r4); ResolveInvalidSpawns(); - if (gDungeon->unkE218.x != -1 && gDungeon->unkE218.y != -1) + if (gDungeon->playerSpawn.x != -1 && gDungeon->playerSpawn.y != -1) { if (GetFloorType() == 1) break; - if (gDungeon->unkE21C.x != -1 && gDungeon->unkE21C.y != -1 && sub_8050C30(gDungeon->unkE21C.x, gDungeon->unkE21C.y, 0)) + if (gDungeon->stairsSpawn.x != -1 && gDungeon->stairsSpawn.y != -1 && sub_8050C30(gDungeon->stairsSpawn.x, gDungeon->stairsSpawn.y, 0)) break; } } @@ -297,11 +364,11 @@ void sub_804AFAC(void) if (i == 10) { gUnknown_202F1D8.x = -1; gUnknown_202F1D8.y = -1; - sub_804FD30(); + ResetFloor(); GenerateOneRoomMonsterHouseFloor(); gDungeon->unk3A08 = 1; sub_804E9DC(); - sub_804FF08(unkPtr, FALSE); + SpawnNonEnemies(unkPtr, FALSE); sub_8050438(unkPtr, FALSE); ResolveInvalidSpawns(); } @@ -310,7 +377,7 @@ void sub_804AFAC(void) sub_806C330(gUnknown_202F1D8.x, gUnknown_202F1D8.y, 380, 0); } - if (gUnknown_202F1B8.unk0 >= 0) { + if (sKecleonShopPosition.unk0 >= 0) { sub_8051654(unkPtr); gDungeon->unk3A0A = 1; } @@ -392,7 +459,7 @@ void NAKED sub_804AFAC(void) " str r0, [r1, 0x8]\n" " str r0, [r1, 0x4]\n" " str r0, [r1, 0xC]\n" -" bl sub_804FD30\n" +" bl ResetFloor\n" " ldr r3, [r4]\n" " mov r6, r8\n" " ldrb r2, [r6, 0x6]\n" @@ -458,7 +525,7 @@ void NAKED sub_804AFAC(void) " movs r0, 0x1\n" " negs r0, r0\n" " strh r0, [r1, 0x2]\n" -" bl sub_804FD30\n" +" bl ResetFloor\n" " ldr r1, [r4]\n" " ldr r3, _0804B13C\n" " adds r2, r1, r3\n" @@ -492,22 +559,22 @@ void NAKED sub_804AFAC(void) "_0804B0F0: .4byte gUnknown_80F6DCC\n" "_0804B0F4: .4byte gDungeonFileArchive\n" "_0804B0F8: .4byte 0x00013568\n" -"_0804B0FC: .4byte gUnknown_202F1AA\n" -"_0804B100: .4byte gUnknown_202F1AB\n" -"_0804B104: .4byte gUnknown_202F1AC\n" +"_0804B0FC: .4byte sHasKecleonShop\n" +"_0804B100: .4byte sHasMonsterHouse\n" +"_0804B104: .4byte sHasMaze\n" "_0804B108: .4byte gUnknown_202F1A8\n" "_0804B10C: .4byte gDungeonWaterType\n" "_0804B110: .4byte 0x00003a0e\n" -"_0804B114: .4byte gUnknown_202F1B4\n" -"_0804B118: .4byte gUnknown_202F1AE\n" -"_0804B11C: .4byte gUnknown_202F1B0\n" -"_0804B120: .4byte gUnknown_202F1B2\n" -"_0804B124: .4byte gUnknown_202F1AD\n" -"_0804B128: .4byte gUnknown_202F1B8\n" +"_0804B114: .4byte sStairsRoomIndex\n" +"_0804B118: .4byte sFloorSize\n" +"_0804B11C: .4byte sKecleonShopChance\n" +"_0804B120: .4byte sMonsterHouseChance\n" +"_0804B124: .4byte sSecondSpawn\n" +"_0804B128: .4byte sKecleonShopPosition\n" "_0804B12C: .4byte 0x00000664\n" "_0804B130: .4byte 0x00003a09\n" "_0804B134: .4byte 0x00003a0a\n" -"_0804B138: .4byte gUnknown_202F1C8\n" +"_0804B138: .4byte sSecondaryStructuresBudget\n" "_0804B13C: .4byte 0x0000e218\n" "_0804B140: .4byte 0x0000ffff\n" "_0804B144: .4byte 0x0000e21a\n" @@ -622,7 +689,7 @@ void NAKED sub_804AFAC(void) " bl GenerateStandardFloor\n" " b _0804B2AA\n" " .align 2, 0\n" -"_0804B24C: .4byte gUnknown_202F1AE\n" +"_0804B24C: .4byte sFloorSize\n" "_0804B250:\n" " movs r0, 0x2\n" " bl DungeonRandInt\n" @@ -638,7 +705,7 @@ void NAKED sub_804AFAC(void) " mov r10, r6\n" " b _0804B2F6\n" " .align 2, 0\n" -"_0804B270: .4byte gUnknown_202F1AE\n" +"_0804B270: .4byte sFloorSize\n" "_0804B274:\n" " adds r0, r5, 0\n" " adds r1, r4, 0\n" @@ -705,7 +772,7 @@ void NAKED sub_804AFAC(void) " mov r10, r1\n" "_0804B2F6:\n" " bl sub_80518F0\n" -" bl sub_804FCCC\n" +" bl EnsureImpassableTilesAreWalls\n" " ldr r0, _0804B4B4\n" " ldrb r0, [r0]\n" " cmp r0, 0\n" @@ -809,7 +876,7 @@ void NAKED sub_804AFAC(void) "_0804B3BC:\n" " mov r0, r8\n" " adds r1, r4, 0\n" -" bl sub_804FF08\n" +" bl SpawnNonEnemies\n" " mov r0, r8\n" " adds r1, r4, 0\n" " bl sub_8050438\n" @@ -874,7 +941,7 @@ void NAKED sub_804AFAC(void) " movs r0, 0x1\n" " negs r0, r0\n" " strh r0, [r1, 0x2]\n" -" bl sub_804FD30\n" +" bl ResetFloor\n" " bl GenerateOneRoomMonsterHouseFloor\n" " ldr r0, _0804B4C0\n" " ldr r0, [r0]\n" @@ -885,7 +952,7 @@ void NAKED sub_804AFAC(void) " bl sub_804E9DC\n" " mov r0, r8\n" " movs r1, 0\n" -" bl sub_804FF08\n" +" bl SpawnNonEnemies\n" " mov r0, r8\n" " movs r1, 0\n" " bl sub_8050438\n" @@ -931,7 +998,7 @@ void NAKED sub_804AFAC(void) "_0804B4CC: .4byte 0x0000e21a\n" "_0804B4D0: .4byte 0x0000e21c\n" "_0804B4D4: .4byte 0x0000e21e\n" -"_0804B4D8: .4byte gUnknown_202F1B8\n" +"_0804B4D8: .4byte sKecleonShopPosition\n" "_0804B4DC: .4byte 0x00003a0a\n" "_0804B4E0:\n" " ldr r0, _0804B524\n" @@ -1002,62 +1069,6 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) } } -struct GridCell -{ - Position start; - Position end; - bool8 isInvalid; - bool8 hasSecondaryStructure; - bool8 isRoom; - bool8 isConnected; - bool8 isKecleonShop; - bool8 unk13; - bool8 isMonsterHouse; - bool8 unk15; - bool8 isMazeRoom; - bool8 hasBeenMerged; - bool8 isMerged; - bool8 connectedToTop; - bool8 connectedToBottom; - bool8 connectedToLeft; - bool8 connectedToRight; - bool8 shouldConnectToTop; - bool8 shouldConnectToBottom; - bool8 shouldConnectToLeft; - bool8 shouldConnectToRight; - bool8 unk27; - bool8 flagImperfect; - bool8 flagSecondaryStructure; - bool8 unk30; - bool8 unk31; -}; - -#define GRID_CELL_LEN 15 - -void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); -void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 x2, s32 y2); -void sub_8051438(struct GridCell *gridCell, s32 a1); -extern void sub_8051288(s32 a0); -void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); -void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); -void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); -void GenerateSecondaryStructure(struct GridCell *gridCell); -void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); -void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber); -void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); -void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); -void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY); -static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr); -void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr); -void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); -void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain); -void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex); -void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); -void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); -void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); -static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); -void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s32 turnX, s32 turnY); - /* * GenerateStandardFloor - Generates a standard, typical floor layout. * @@ -1080,20 +1091,20 @@ void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C5 InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->unk1); + AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->roomDensity); - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->unk9); - GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->mazeRoomChance); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } @@ -1237,10 +1248,10 @@ void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *unkPtr) EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } @@ -1371,10 +1382,10 @@ void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *unkPtr) CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } @@ -1401,18 +1412,18 @@ void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) gridSizeX = 5, gridSizeY = 1; InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->unk1); - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); + AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->roomDensity); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, disableRoomMerging); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } @@ -1450,7 +1461,7 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) grid[0][2].isInvalid = TRUE; grid[2][2].isInvalid = TRUE; - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); grid[0][1].connectedToRight = TRUE; grid[1][1].connectedToLeft = TRUE; @@ -1464,10 +1475,10 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } @@ -1499,7 +1510,7 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) } } - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); // Connect rooms in the same row together for (y = 0; y < 3; y++) { @@ -1516,10 +1527,10 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } @@ -1582,7 +1593,7 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un } } - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->unkD); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); // Maybe Todo: Add EpicYoshiMaster's fixed implementation of this function @@ -1625,18 +1636,18 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->unk9); - GenerateKecleonShop(grid, gridSizeX, gridSizeY, gUnknown_202F1B0); - GenerateMonsterHouse(grid, gridSizeX, gridSizeY, gUnknown_202F1B2); + GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->mazeRoomChance); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->unk13); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } bool8 sub_804C70C(s32 a0, UnkDungeonGlobal_unk1C574 *unkPtr) { - struct FileFixedmapPosStruct **fileData = (void *) gDungeon->unk13568->data; + struct PositionU8 **fileData = (void *) gDungeon->unk13568->data; s32 x1 = fileData[a0]->x; s32 y1 = fileData[a0]->y; s32 gridSizeX, gridSizeY; @@ -1672,7 +1683,7 @@ void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeo GetGridPositions(listX, listY, gridSizeX, gridSizeY); InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->unk1); + AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->roomDensity); for (cursorX = 0; cursorX < gridSizeX; cursorX++) { for (cursorY = 0; cursorY < gridSizeY; cursorY++) { grid[cursorX][cursorY].unk27 = 1; @@ -1995,8 +2006,8 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s // If we'd step into an invalid grid cell, stop // (We don't always utilize the entire floor space) direction &= DIRECTION_MASK_CARDINAL; - if (currX >= 32 && gUnknown_202F1AE == 1 && direction == DIRECTION_EAST) break; - if (currX >= 48 && gUnknown_202F1AE == 2 && direction == DIRECTION_EAST) break; + if (currX >= 32 && sFloorSize == FLOOR_SIZE_SMALL && direction == DIRECTION_EAST) break; + if (currX >= 48 && sFloorSize == FLOOR_SIZE_MEDIUM && direction == DIRECTION_EAST) break; } // Move in the current direction @@ -2036,10 +2047,10 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gri for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { - if (gUnknown_202F1AE == 1 && x >= gridSizeX / 2) { + if (sFloorSize == 1 && x >= gridSizeX / 2) { grid[x][y].isInvalid = TRUE; } - else if (gUnknown_202F1AE == 2 && x >= (gridSizeX * 3) / 4) { + else if (sFloorSize == 2 && x >= (gridSizeX * 3) / 4) { grid[x][y].isInvalid = TRUE; } else { @@ -2121,21 +2132,21 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz // Counter for randomRoomBits i = 0; - gUnknown_202F1CC = 0; + sNumRooms = 0; for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { if (grid[x][y].isInvalid) continue; // There are too many rooms, remove - if (gUnknown_202F1CC >= MAX_ROOM_COUNT) { + if (sNumRooms >= MAX_ROOM_COUNT) { grid[x][y].isRoom = FALSE; } // Using the randomly shuffled bits, create or remove the room if (randomRoomBits[i]) { grid[x][y].isRoom = TRUE; - gUnknown_202F1CC++; + sNumRooms++; // Don't make a room at (x_mid, 1) if (gridSizeX % 2 != 0 && x == (gridSizeX - 1) / 2 && y == 1 ) { @@ -2151,7 +2162,7 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz } // We have at least 2 rooms, we're done. - if (gUnknown_202F1CC >= 2) + if (sNumRooms >= 2) return; for (attempts = 0; attempts < 200; attempts++) { @@ -2174,7 +2185,7 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz break; } - gUnknown_202F1AD = FALSE; + sSecondSpawn = FALSE; } /* @@ -2247,12 +2258,12 @@ void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s flagImperfect = TRUE; // Randomly flag the room for a secondary structure flagSecondary = DungeonRandInt(100) < GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE; - if (gUnknown_202F1C8 == 0) { + if (sSecondaryStructuresBudget == 0) { flagSecondary = FALSE; } // Flag for imperfections if needed - if (!(roomFlags & 4)) { + if (!(roomFlags & ROOM_FLAG_ALLOW_IMPERFECTIONS)) { flagImperfect = FALSE; } @@ -2380,23 +2391,12 @@ static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][ * */ -enum CardinalDirection -{ - CARDINAL_DIR_RIGHT, - CARDINAL_DIR_UP, - CARDINAL_DIR_LEFT, - CARDINAL_DIR_DOWN, - NUM_CARDINAL_DIRECTIONS -}; - -#define CARDINAL_DIRECTION_MASK 3 - void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr) { s32 i; s32 x = cursorX; s32 y = cursorY; - s32 floorConnectivity = unkPtr->unk5; + s32 floorConnectivity = unkPtr->floorConnectivity; // Draw a random connection direction. // Connect the current cell with the cell to the: // 0: east @@ -2489,7 +2489,7 @@ void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN } } - if (unkPtr->unkB) + if (unkPtr->allowDeadEnds) return; // No dead ends, add some extra connections! @@ -3635,7 +3635,7 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gUnknown_202F1D8.x = -1; gUnknown_202F1D8.y = -1; - if (gUnknown_202F1AB || GetFloorType() == FLOOR_TYPE_RESCUE || chance == 0) + if (sHasMonsterHouse || GetFloorType() == FLOOR_TYPE_RESCUE || chance == 0) return; if (chance <= DungeonRandInt(100)) return; @@ -3705,18 +3705,18 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 continue; // This room can be a kecleon shop - gUnknown_202F1AA = TRUE; + sHasKecleonShop = TRUE; grid[x][y].isKecleonShop = TRUE; // Make the shop span the whole room - gUnknown_202F1B8.minX = grid[x][y].start.x + 1; - gUnknown_202F1B8.maxX = grid[x][y].end.x - 1; - gUnknown_202F1B8.minY = grid[x][y].start.y + 1; - gUnknown_202F1B8.maxY = grid[x][y].end.y - 1; + sKecleonShopPosition.minX = grid[x][y].start.x + 1; + sKecleonShopPosition.maxX = grid[x][y].end.x - 1; + sKecleonShopPosition.minY = grid[x][y].start.y + 1; + sKecleonShopPosition.maxY = grid[x][y].end.y - 1; - if (gUnknown_202F1B8.maxY - gUnknown_202F1B8.minY < 3) { + if (sKecleonShopPosition.maxY - sKecleonShopPosition.minY < 3) { // This should never happen? - gUnknown_202F1B8.maxY++; + sKecleonShopPosition.maxY++; } // Set to values that guarantee they'll be replaced later @@ -3727,8 +3727,8 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 // Generate the actual shop on the interior, leaving // a 1-tile border from the room walls - for (curX = gUnknown_202F1B8.minX; curX < gUnknown_202F1B8.maxX; curX++) { - for (curY = gUnknown_202F1B8.minY; curY < gUnknown_202F1B8.maxY; curY++) { + for (curX = sKecleonShopPosition.minX; curX < sKecleonShopPosition.maxX; curX++) { + for (curY = sKecleonShopPosition.minY; curY < sKecleonShopPosition.maxY; curY++) { Tile *tile = GetTileSafe(curX, curY); tile->terrainType |= TERRAIN_TYPE_SHOP; @@ -3763,8 +3763,8 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 } } - curX = (gUnknown_202F1B8.minX + gUnknown_202F1B8.maxX) / 2; - curY = (gUnknown_202F1B8.minY + gUnknown_202F1B8.maxY) / 2; + curX = (sKecleonShopPosition.minX + sKecleonShopPosition.maxX) / 2; + curY = (sKecleonShopPosition.minY + sKecleonShopPosition.maxY) / 2; gUnknown_202F1D8.x = curX; gUnknown_202F1D8.y = curY; @@ -3798,7 +3798,7 @@ void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s3 if (chance == 0 || chance <= DungeonRandInt(100)) return; - if (gUnknown_202F1AA) + if (sHasKecleonShop) return; if (gDungeon->unk688 != 0) return; @@ -3880,13 +3880,13 @@ void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s3 s32 curX, curY; // The selected room can support a monster house // Generate one! - gUnknown_202F1AB = TRUE; + sHasMonsterHouse = TRUE; grid[x][y].isMonsterHouse = TRUE; for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { GetTileSafe(curX, curY)->terrainType |= TERRAIN_TYPE_IN_MONSTER_HOUSE; - dungeon->unk3A0C = GetTile(curX, curY)->room; + dungeon->monsterHouseRoom = GetTile(curX, curY)->room; } } return; @@ -4022,7 +4022,7 @@ void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) s32 curX, curY; u8 roomIndex; - gUnknown_202F1AC = TRUE; + sHasMaze = TRUE; gridCell->isMazeRoom = TRUE; roomIndex = GetTile(gridCell->start.x, gridCell->start.y)->room; @@ -4246,10 +4246,10 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) switch (DungeonRandInt(6)) { // Generate a "split room" with two sides separated by a line of water/lava case SECONDARY_STRUCTURE_DIVIDER: - if (gUnknown_202F1C8 != 0) { + if (sSecondaryStructuresBudget != 0) { s32 i; - gUnknown_202F1C8--; + sSecondaryStructuresBudget--; SetSpawnFlag5(gridCell); if (DungeonRandInt(2) != 0) { @@ -4313,8 +4313,8 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) s32 middleX = (gridCell->start.x + gridCell->end.x) / 2; s32 middleY = (gridCell->start.y + gridCell->end.y) / 2; // Both dimensions are at least 6. Generate an "island" with lava, items, and a Warp Tile at the center - if (gUnknown_202F1C8 != 0) { - gUnknown_202F1C8--; + if (sSecondaryStructuresBudget != 0) { + sSecondaryStructuresBudget--; SetSpawnFlag5(gridCell); @@ -4362,8 +4362,8 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) s32 randX2 = DungeonRandRange(gridCell->start.x + 2, gridCell->end.x - 3); s32 randY2 = DungeonRandRange(gridCell->start.y + 2, gridCell->end.y - 3); - if (gUnknown_202F1C8 != 0) { - gUnknown_202F1C8--; + if (sSecondaryStructuresBudget != 0) { + sSecondaryStructuresBudget--; SetSpawnFlag5(gridCell); @@ -4388,10 +4388,10 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) } break; case SECONDARY_STRUCTURE_CHECKERBOARD: - if ((gridCell->end.x - gridCell->start.x) % 2 != 0 && (gridCell->end.y - gridCell->start.y) % 2 != 0 && gUnknown_202F1C8 != 0) { + if ((gridCell->end.x - gridCell->start.x) % 2 != 0 && (gridCell->end.y - gridCell->start.y) % 2 != 0 && sSecondaryStructuresBudget != 0) { s32 i; // Dimensions are odd, generate diagonal stripes/checkerboard of water/lava - gUnknown_202F1C8--; + sSecondaryStructuresBudget--; SetSpawnFlag5(gridCell); @@ -4407,8 +4407,8 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) } break; case SECONDARY_STRUCTURE_MAZE_PLUS_DOT: - if (gUnknown_202F1C8 != 0) { - gUnknown_202F1C8--; + if (sSecondaryStructuresBudget != 0) { + sSecondaryStructuresBudget--; // If the dimensions are odd, generate a maze room if ((gridCell->end.x - gridCell->start.x) % 2 == 0 || (gridCell->end.y - gridCell->start.y) % 2 == 0) { @@ -4454,7 +4454,7 @@ void ResolveInvalidSpawns(void) for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { Tile *tile = GetTileSafe(x, y); if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) { - if (tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL)) { + if (tile->terrainType & (TERRAIN_TYPE_UNBREAKABLE | TERRAIN_TYPE_IMPASSABLE_WALL)) { // This tile is an impassable obstacle, make sure no items spawn here tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); } @@ -4476,4 +4476,468 @@ void ResolveInvalidSpawns(void) } } +// Converts Secondary terrain to both secondary and normal. Possibly to note that it's a water tile? +void sub_804FC74(void) +{ + s32 x, y; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (GetTerrainType(GetTile(x, y)) == TERRAIN_TYPE_SECONDARY) { + SetTerrainType(GetTileSafe(x,y), TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + } + } + } +} + +/* + * EnsureImpassableTilesAreWalls - Force all tiles with the impassable flag to be set as walls. + */ +void EnsureImpassableTilesAreWalls(void) +{ + s32 x, y; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (GetTile(x, y)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) { + SetTerrainWall(GetTileSafe(x,y)); + } + } + } +} + +void ResetTile(Tile *tile) +{ + tile->terrainType = 0; + tile->spawnOrVisibilityFlags = 0; + tile->room = -1; + tile->unk8 = 0; + tile->walkableNeighborFlags[CROSSABLE_TERRAIN_REGULAR] = 0; + tile->walkableNeighborFlags[CROSSABLE_TERRAIN_LIQUID] = 0; + tile->walkableNeighborFlags[CROSSABLE_TERRAIN_CREVICE] = 0; + tile->walkableNeighborFlags[CROSSABLE_TERRAIN_WALL] = 0; + tile->unkE = 0; + tile->monster = NULL; + tile->object = NULL; +} + +// PosIsOutOfBounds - Checks if a position is out of bounds on the map. +static inline bool8 PosIsOutOfBounds(s32 x, s32 y) +{ + if (x < 0 || (y < 0)) + return TRUE; + if (DUNGEON_MAX_SIZE_X <= x) + return TRUE; + if (DUNGEON_MAX_SIZE_Y <= y) + return TRUE; + return FALSE; +} + +void ResetFloor(void) +{ + s32 x, y; + + // Reset Room Tiles + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + ResetTile(GetTileSafe(x,y)); + + if ((PosIsOutOfBounds(x, y - 1)) || + (PosIsOutOfBounds(x + 1, y - 1)) || + (PosIsOutOfBounds(x + 1, y - 1)) || + (PosIsOutOfBounds(x + 1, y + 1)) || + (PosIsOutOfBounds(x, y + 1)) || + (PosIsOutOfBounds(x - 1, y + 1)) || + (PosIsOutOfBounds(x - 1, y)) || + (PosIsOutOfBounds(x - 1, y - 1))) + { + GetTileSafe(x,y)->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + } + } + + // Reset Stairs Position + gDungeon->stairsSpawn.x = -1; + gDungeon->stairsSpawn.y = -1; + + // Reset Fixed Room Tiles + for (x = 0; x < 8; x++) { + for (y = 0; y < 8; y++) { + ResetTile(&gDungeon->unkE27C[x][y]); + } + } + + gDungeon->numItems = 0; + + // Reset Traps + for (x = 0; x < DUNGEON_MAX_TRAPS; x++) { + gDungeon->traps[x]->type = 0; + } +} + +/* + * ShuffleSpawnPositions - Randomly shuffle an array of spawn positions + */ +void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count) +{ + s32 i; + // Do twice as many swaps as there are items in the array + for (i = 0; i < count * 2; i++) { + struct PositionU8 temp; + s32 a = DungeonRandInt(count); + s32 b = DungeonRandInt(count); + + SWAP(spawns[a], spawns[b], temp); + } +} + +/* + * SpawnNonEnemies - Spawns all non-enemy entities: Stairs, Items, Traps, and the player. + * + * Most entities spawn randomly on a subset of the valid tiles for their type. + * + * These spawns are categorized into: + * - Stairs (and hidden stairs in later gens) + * - Normal Items + * - Buried Items + * - Monster House Items/Traps + * - Normal Traps + * - Player Spawn + * + * See below for specific conditions on each type of spawn. + */ +extern const s16 gUnknown_80F4DA0; +void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse) +{ + struct PositionU8 validSpawns[1792]; + s32 count; + s32 randIndex; + s32 i; + s32 x, y; + Dungeon *dungeon = gDungeon; + // Spawn Stairs + if (dungeon->stairsSpawn.x == -1 || dungeon->stairsSpawn.y == -1) { + count = 0; + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // The stairs can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not an enemy spawn + // - Not a special tile (flagged by kecleon shops, traps, and items) + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover + + Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + continue; + if (tile->room == CORRIDOR_ROOM) + continue; + if (tile->terrainType & TERRAIN_TYPE_SHOP) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_MONSTER) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_SPECIAL_TILE) + continue; + if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) + continue; + if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) + continue; + + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + + if (count != 0) { + // Randomly select one of the valid tiles to spawn the stairs on + s32 stairsIndex = DungeonRandInt(count); + Tile *stairsTile = GetTileSafe(validSpawns[stairsIndex].x, validSpawns[stairsIndex].y); + + stairsTile->spawnOrVisibilityFlags |= SPAWN_FLAG_STAIRS; + stairsTile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + sStairsRoomIndex = stairsTile->room; + dungeon->stairsSpawn.x = validSpawns[stairsIndex].x; + dungeon->stairsSpawn.y = validSpawns[stairsIndex].y; + + // If we're spawning normal stairs and this is a rescue floor, make the stairs room a Monster House + if (GetFloorType() == FLOOR_TYPE_RESCUE) { + u32 stairsRoomIndex = stairsTile->room; + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + Tile *tile = GetTileSafe(x, y); + if (GetTerrainType(tile) == TERRAIN_TYPE_NORMAL && tile->room == stairsRoomIndex) { + tile->terrainType |= TERRAIN_TYPE_IN_MONSTER_HOUSE; + dungeon->monsterHouseRoom = tile->room; + } + } + } + } + } + } + + // Spawn normal items + + count = 0; + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // Normal items can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not in a Monster House + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover + + Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + continue; + if (tile->room == CORRIDOR_ROOM) + continue; + if (tile->terrainType & TERRAIN_TYPE_SHOP) + continue; + if (tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE) + continue; + if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) + continue; + if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) + continue; + + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + + if (count != 0) { + s32 numItems = unkPtr->itemDensity; + if (numItems != 0) { + // Add variation to the item count + numItems = DungeonRandRange(numItems - 2, numItems + 2); + if (numItems <= 0) { + numItems = 1; + } + } + + if (numItems != 0) { + // Randomly select among the valid item spawn spots + ShuffleSpawnPositions(validSpawns, count); + randIndex = DungeonRandInt(count); + for (i = 0; i < numItems; i++) { + Tile *tile = GetTileSafe(validSpawns[randIndex].x, validSpawns[randIndex].y); + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + + randIndex++; + if (randIndex == count) { + // Wrap around to the start + randIndex = 0; + } + } + } + } + + // Spawn Buried Items (in walls) + + count = 0; + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // Any wall tile is all buried items need + if (GetTerrainType(GetTile(x, y)) == TERRAIN_TYPE_WALL) { + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + } + + if (count != 0) { + s32 numItems = unkPtr->buriedItemDensity; + + if (numItems != 0) { + // Add variation to the item count + numItems = DungeonRandRange(numItems - 2, numItems + 2); + } + + if (numItems > 0) { + // Randomly select among the valid item spawn spots + ShuffleSpawnPositions(validSpawns, count); + randIndex = DungeonRandInt(count); + for (i = 0; i < numItems; i++) { + Tile *tile = GetTileSafe(validSpawns[randIndex].x, validSpawns[randIndex].y); + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + + randIndex++; + if (randIndex == count) { + // Wrap around to the start + randIndex = 0; + } + } + } + } + + // Spawn items/traps in a non-empty Monster House + count = 0; + if (!isEmptyMonsterHouse) { + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // Monster House items/traps can spawn on tiles that are: + // - not in a kecleon shop (how would they be?) + // - in a Monster House + // - not a junction (near a hallway) + Tile *tile = GetTile(x, y); + if (tile->terrainType & TERRAIN_TYPE_SHOP) + continue; + if (!(tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE)) + continue; + if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) + continue; + + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + } + + if (count != 0) { + // Choose a subset of the available tiles to spawn stuff on + s32 numItems = DungeonRandRange((count / 2), (count * 8) / 10); + + if (numItems < 6) { + numItems = 6; + } + // Cap item spawns at 7 (normally) + if (numItems >= gUnknown_80F4DA0) { + numItems = gUnknown_80F4DA0; + } + + // Randomly select among the valid item spawn spots + ShuffleSpawnPositions(validSpawns, count); + randIndex = DungeonRandInt(count); + for (i = 0; i < numItems; i++) { + Tile *tile = GetTileSafe(validSpawns[randIndex].x, validSpawns[randIndex].y); + + // 50/50 chance of spawning an item or a trap + if (DungeonRandInt(2) != 0) { + // Spawn an item + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + } + else if (gDungeon->unk65C) { + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_TRAP; + } + + randIndex++; + if (randIndex == count) { + // Wrap around to the start + randIndex = 0; + } + } + } + + // Spawn Normal Traps + count = 0; + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // Normal traps can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Don't already have an item spawn + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover + + Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + continue; + if (tile->room == CORRIDOR_ROOM) + continue; + if (tile->terrainType & TERRAIN_TYPE_SHOP) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_ITEM) + continue; + if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) + continue; + if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) + continue; + + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + + if (count != 0) { + s32 numTraps = DungeonRandRange(unkPtr->trapDensity / 2, unkPtr->trapDensity); + + if (numTraps > 0) { + s32 trapIndex; + if (numTraps >= 56) { + // Cap the number of traps at 56 + numTraps = 56; + } + + // Randomly select among the valid trap spawn spots + ShuffleSpawnPositions(validSpawns, count); + trapIndex = DungeonRandInt(count); + for (i = 0; i < numTraps; i++) { + Tile *tile = GetTileSafe(validSpawns[trapIndex].x, validSpawns[trapIndex].y); + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_TRAP; + + trapIndex++; + if (trapIndex == count) { + // Wrap around to the start + trapIndex = 0; + } + } + } + } + + // Spawn the player + if (dungeon->playerSpawn.x == -1 || dungeon->playerSpawn.y == -1) { + count = 0; + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // The player can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover + // - Not an item, enemy, or trap spawn + + Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + continue; + if (tile->room == CORRIDOR_ROOM) + continue; + if (tile->terrainType & TERRAIN_TYPE_SHOP) + continue; + if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) + continue; + if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_ITEM) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_MONSTER) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_TRAP) + continue; + + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + + if (count != 0) { + // Randomly select one of the valid tiles to spawn the player on + s32 spawnIndex = DungeonRandInt(count); + dungeon->playerSpawn.x = validSpawns[spawnIndex].x; + dungeon->playerSpawn.y = validSpawns[spawnIndex].y; + } + } +} + // diff --git a/src/dungeon_util.c b/src/dungeon_util.c index 56885cb0b..728b9604e 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -167,7 +167,7 @@ void sub_804522C(void) { } } - for(index = 0; index < gDungeon->unk3904; index++) + for(index = 0; index < gDungeon->numItems; index++) { sub_80462AC(gDungeon->items[index], crossEyed, 1, 0xFF, 0); } diff --git a/src/tile_types.c b/src/tile_types.c index f00c7a4ba..d0bd10c8c 100644 --- a/src/tile_types.c +++ b/src/tile_types.c @@ -128,7 +128,7 @@ bool8 sub_804AD34(Position *pos) iVar8 = 0; tile = GetTileSafe(pos->x,pos->y); if (!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) - if(!(tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL))){ + if(!(tile->terrainType & (TERRAIN_TYPE_UNBREAKABLE | TERRAIN_TYPE_IMPASSABLE_WALL))){ iVar8 = 1; tile->terrainType = (tile->terrainType & ~(TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL)) | TERRAIN_TYPE_NORMAL; @@ -167,7 +167,7 @@ bool8 sub_804AE08(Position *pos) tile = GetTileSafe(pos->x,pos->y); if (!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) - if(!(tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL))) { + if(!(tile->terrainType & (TERRAIN_TYPE_UNBREAKABLE | TERRAIN_TYPE_IMPASSABLE_WALL))) { uVar6 = TRUE; tile->terrainType = (tile->terrainType & ~(TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL)) | TERRAIN_TYPE_NORMAL; tile->spawnOrVisibilityFlags = tile->spawnOrVisibilityFlags | 0x10; diff --git a/src/trap_1.c b/src/trap_1.c index ee7262aff..910ca92e6 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -487,7 +487,7 @@ void sub_8081454(unkStruct_8094924 *param_1) sub_80830B4(param_1, gDungeon->unk3A09); sub_80830B4(param_1, gDungeon->unk3A0A); sub_80830B4(param_1, gDungeon->unk3A0B); - sub_8083060(param_1, gDungeon->unk3A0C); + sub_8083060(param_1, gDungeon->monsterHouseRoom); sub_8083060(param_1, gDungeon->unk3A0D); sub_8083048(param_1, gDungeon->tileset); sub_8083048(param_1,gDungeon->unk3A10); @@ -504,8 +504,8 @@ void sub_8081454(unkStruct_8094924 *param_1) } - SavePosition(param_1,&gDungeon->unkE218); - SavePosition(param_1,&gDungeon->unkE21C); + SavePosition(param_1,&gDungeon->playerSpawn); + SavePosition(param_1,&gDungeon->stairsSpawn); @@ -824,7 +824,7 @@ void sub_8081C7C(unkStruct_8094924 *r0) gDungeon->unk3A09 = sub_80831DC(r0); gDungeon->unk3A0A = sub_80831DC(r0); gDungeon->unk3A0B = sub_80831DC(r0); - gDungeon->unk3A0C = sub_8083188(r0); + gDungeon->monsterHouseRoom = sub_8083188(r0); gDungeon->unk3A0D = sub_8083188(r0); gDungeon->tileset = sub_8083170(r0); gDungeon->unk3A10 = sub_8083170(r0); @@ -839,8 +839,8 @@ void sub_8081C7C(unkStruct_8094924 *r0) RestoreTile(r0,&gDungeon->tiles[y][x]); } } - sub_80831F8(r0,&gDungeon->unkE218); - sub_80831F8(r0,&gDungeon->unkE21C); + sub_80831F8(r0,&gDungeon->playerSpawn); + sub_80831F8(r0,&gDungeon->stairsSpawn); for(iVar7 = 0; iVar7 < 8; iVar7++) { diff --git a/sym_ewram.txt b/sym_ewram.txt index f4a5c0262..07d02485a 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -274,35 +274,8 @@ gUnknown_202EE76: /* 202EE76 (sub_804513C - sub_8082A08) */ .space 0x10 .include "src/dungeon_map_access.o" + .include "src/dungeon_generation.o" -gUnknown_202F1A8: /* 202F1A8 (sub_8043CE4 - sub_8051A74) */ - .space 0x1 -gUnknown_202F1A9: /* 202F1A9 (sub_804AFAC) */ - .space 0x1 -gUnknown_202F1AA: /* 202F1AA (sub_804AFAC - sub_804EEE4) */ - .space 0x1 -gUnknown_202F1AB: /* 202F1AB (sub_804AFAC - sub_804EEE4) */ - .space 0x1 -gUnknown_202F1AC: /* 202F1AC (sub_804AFAC - sub_804F278) */ - .space 0x1 -gUnknown_202F1AD: /* 202F1AD (sub_804AFAC - sub_804D154) */ - .space 0x1 -gUnknown_202F1AE: /* 202F1AE (sub_804AFAC - sub_804D084) */ - .space 0x2 -gUnknown_202F1B0: /* 202F1B0 (sub_804AFAC - sub_804C53C) */ - .space 0x2 -gUnknown_202F1B2: /* 202F1B2 (sub_804AFAC - sub_804C53C) */ - .space 0x2 -gUnknown_202F1B4: /* 202F1B4 (sub_804AFAC - sub_804FF08) */ - .space 0x4 -gUnknown_202F1B8: /* 202F1B8 (sub_804AFAC - sub_8051654) */ - .space 0x10 -gUnknown_202F1C8: /* 202F1C8 (sub_804AFAC - sub_804F694) */ - .space 0x4 -gUnknown_202F1CC: /* 202F1CC (sub_804D154) */ - .space 0x4 -gUnknown_202F1D0: /* 202F1D0 (sub_804AFAC) */ - .space 0x4 gUnknown_202F1D4: /* 202F1D4 (sub_8050C30) */ .space 0x4 gUnknown_202F1D8: /* 202F1D8 (sub_804AFAC - sub_804EBC8) */ From 799ea6a5c600f2f07f197e327f2a566d2d1283cd Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 14 Nov 2024 15:05:08 +0100 Subject: [PATCH 18/30] GenerateSecondaryTerrainFormations failed attempt --- asm/code_804FD30.s | 1065 --------------------------------- include/structs/str_dungeon.h | 4 +- src/code_8042B34.c | 2 +- src/code_8066D04.c | 8 +- src/code_8073CF0.c | 2 +- src/code_807CD9C.c | 4 +- src/code_807E1A0.c | 4 +- src/dungeon_ai_attack.c | 2 +- src/dungeon_generation.c | 487 ++++++++++++++- src/move_actions.c | 2 +- src/trap_1.c | 4 +- 11 files changed, 488 insertions(+), 1096 deletions(-) diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index 1801adf9b..6d3e82c56 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -5,1071 +5,6 @@ .text - thumb_func_start sub_8050438 -sub_8050438: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _08050470 - add sp, r4 - lsls r1, 24 - lsrs r1, 24 - movs r2, 0xE0 - lsls r2, 5 - add r2, sp - str r1, [r2] - ldr r1, _08050474 - ldr r1, [r1] - mov r10, r1 - ldrb r1, [r0, 0x6] - cmp r1, 0 - ble _08050478 - lsrs r0, r1, 1 - bl DungeonRandRange - adds r7, r0, 0 - cmp r7, 0 - bgt _0805047A - movs r7, 0x1 - b _0805047A - .align 2, 0 -_08050470: .4byte 0xffffe3f8 -_08050474: .4byte gDungeon -_08050478: - adds r7, r1, 0 -_0805047A: - movs r0, 0 - mov r8, r0 - movs r6, 0 -_08050480: - movs r5, 0 - adds r1, r6, 0x1 - mov r9, r1 - mov r2, r8 - lsls r0, r2, 2 - mov r1, sp - adds r4, r0, r1 -_0805048E: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - adds r1, r0, 0 - ldrh r3, [r1] - movs r2, 0x3 - ands r2, r3 - cmp r2, 0x1 - bne _080504F6 - ldrb r0, [r1, 0x9] - cmp r0, 0xFF - beq _080504F6 - movs r0, 0x20 - ands r0, r3 - cmp r0, 0 - bne _080504F6 - ldrh r1, [r1, 0x4] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _080504F6 - ands r2, r1 - cmp r2, 0 - bne _080504F6 - movs r0, 0x8 - ands r0, r3 - cmp r0, 0 - bne _080504F6 - movs r2, 0x80 - lsls r2, 1 - adds r0, r2, 0 - ands r0, r3 - cmp r0, 0 - bne _080504F6 - ldr r0, _080506A0 - add r0, r10 - movs r1, 0 - ldrsh r0, [r0, r1] - cmp r6, r0 - bne _080504EC - ldr r0, _080506A4 - add r0, r10 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r5, r0 - beq _080504F6 -_080504EC: - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r0, 0x1 - add r8, r0 -_080504F6: - adds r5, 0x1 - cmp r5, 0x1F - ble _0805048E - mov r6, r9 - cmp r6, 0x37 - ble _08050480 - mov r1, r8 - cmp r1, 0 - beq _0805055E - ldr r0, _080506A8 - ldr r0, [r0] - movs r2, 0xD1 - lsls r2, 3 - adds r0, r2 - movs r1, 0 - ldrsh r0, [r0, r1] - cmp r0, 0 - beq _0805051C - adds r7, 0x1 -_0805051C: - cmp r7, 0 - beq _0805055E - mov r0, sp - mov r1, r8 - bl ShuffleSpawnPositions - mov r0, r8 - bl DungeonRandInt - adds r5, r0, 0 - cmp r7, 0 - ble _0805055E - adds r6, r7, 0 - lsls r0, r5, 2 - mov r2, sp - adds r4, r0, r2 -_0805053C: - ldrb r0, [r4] - ldrb r1, [r4, 0x1] - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x8 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x4 - adds r5, 0x1 - cmp r5, r8 - bne _08050558 - mov r4, sp - movs r5, 0 -_08050558: - subs r6, 0x1 - cmp r6, 0 - bne _0805053C -_0805055E: - ldr r0, _080506AC - add r0, r10 - ldrb r0, [r0] - cmp r0, 0 - bne _0805056A - b _0805068C -_0805056A: - ldr r0, _080506B0 - movs r2, 0 - ldrsh r1, [r0, r2] - ldr r2, _080506B4 - add r2, sp - str r1, [r2] - movs r0, 0 - mov r8, r0 - movs r1, 0xE0 - lsls r1, 5 - add r1, sp - ldr r1, [r1] - cmp r1, 0 - beq _0805058A - movs r0, 0x3 - str r0, [r2] -_0805058A: - ldr r1, _080506B4 - add r1, sp - ldr r1, [r1] - lsls r0, r1, 1 - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - ldr r1, _080506B4 - add r1, sp - str r0, [r1] - movs r6, 0 -_080505A2: - movs r5, 0 - adds r2, r6, 0x1 - mov r9, r2 - mov r1, r8 - lsls r0, r1, 2 - mov r2, sp - adds r4, r0, r2 -_080505B0: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - adds r1, r0, 0 - ldrh r2, [r1] - movs r0, 0x3 - ands r0, r2 - cmp r0, 0x1 - bne _08050608 - ldrb r0, [r1, 0x9] - cmp r0, 0xFF - beq _08050608 - movs r0, 0x20 - ands r0, r2 - cmp r0, 0 - bne _08050608 - movs r1, 0x80 - lsls r1, 1 - adds r0, r1, 0 - ands r0, r2 - cmp r0, 0 - bne _08050608 - movs r0, 0x40 - ands r0, r2 - cmp r0, 0 - beq _08050608 - ldr r0, _080506A0 - add r0, r10 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r6, r0 - bne _080505FE - ldr r0, _080506A4 - add r0, r10 - movs r1, 0 - ldrsh r0, [r0, r1] - cmp r5, r0 - beq _08050608 -_080505FE: - strb r6, [r4] - strb r5, [r4, 0x1] - adds r4, 0x4 - movs r2, 0x1 - add r8, r2 -_08050608: - adds r5, 0x1 - cmp r5, 0x1F - ble _080505B0 - mov r6, r9 - cmp r6, 0x37 - ble _080505A2 - mov r0, r8 - cmp r0, 0 - beq _0805068C - lsls r4, r0, 3 - subs r0, r4, r0 - movs r1, 0xA - bl __divsi3 - adds r5, r0, 0 - adds r0, r4, 0 - movs r1, 0xA - bl __divsi3 - adds r1, r0, 0 - adds r0, r5, 0 - bl DungeonRandRange - adds r7, r0, 0 - cmp r7, 0 - bne _0805063E - movs r7, 0x1 -_0805063E: - ldr r1, _080506B4 - add r1, sp - ldr r1, [r1] - cmp r7, r1 - blt _0805064E - ldr r2, _080506B4 - add r2, sp - ldr r7, [r2] -_0805064E: - mov r0, sp - mov r1, r8 - bl ShuffleSpawnPositions - mov r0, r8 - bl DungeonRandInt - adds r5, r0, 0 - cmp r7, 0 - ble _0805068C - adds r6, r7, 0 - lsls r0, r5, 2 - mov r1, sp - adds r4, r0, r1 -_0805066A: - ldrb r0, [r4] - ldrb r1, [r4, 0x1] - bl GetTileSafe - ldrh r2, [r0, 0x4] - movs r1, 0x8 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x4 - adds r5, 0x1 - cmp r5, r8 - bne _08050686 - mov r4, sp - movs r5, 0 -_08050686: - subs r6, 0x1 - cmp r6, 0 - bne _0805066A -_0805068C: - ldr r3, _080506B8 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080506A0: .4byte 0x0000e218 -_080506A4: .4byte 0x0000e21a -_080506A8: .4byte gDungeon -_080506AC: .4byte 0x00003a08 -_080506B0: .4byte gUnknown_80F4DA4 -_080506B4: .4byte 0x00001c04 -_080506B8: .4byte 0x00001c08 - thumb_func_end sub_8050438 - - thumb_func_start sub_80506BC -sub_80506BC: - push {lr} - adds r3, r0, 0 - movs r2, 0x1 - ldrh r1, [r3] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - beq _080506CE - movs r2, 0 -_080506CE: - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _080506D8 - movs r2, 0 -_080506D8: - cmp r2, 0 - beq _080506E6 - ldr r0, _080506EC - ands r0, r1 - movs r1, 0x2 - orrs r0, r1 - strh r0, [r3] -_080506E6: - pop {r0} - bx r0 - .align 2, 0 -_080506EC: .4byte 0x0000fffc - thumb_func_end sub_80506BC - - thumb_func_start sub_80506F0 -sub_80506F0: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xA4 - str r1, [sp, 0x64] - ldrb r1, [r1, 0xD] - ands r1, r0 - cmp r1, 0 - bne _08050708 - b _08050C20 -_08050708: - ldr r4, _08050738 - movs r0, 0x8 - bl DungeonRandInt - lsls r0, 2 - adds r0, r4 - ldr r4, [r0] - cmp r4, 0 - bne _0805071C - b _08050A7C -_0805071C: - movs r0, 0x64 - bl DungeonRandInt - cmp r0, 0x31 - bgt _0805073C - movs r0, 0x1 - str r0, [sp, 0x74] - movs r1, 0x1F - mov r10, r1 - movs r2, 0x1 - negs r2, r2 - str r2, [sp, 0x70] - b _08050746 - .align 2, 0 -_08050738: .4byte gUnknown_80F6DF8 -_0805073C: - movs r0, 0 - str r0, [sp, 0x74] - mov r10, r0 - movs r1, 0x1 - str r1, [sp, 0x70] -_08050746: - movs r0, 0x32 - bl DungeonRandInt - adds r0, 0xA - str r0, [sp, 0x78] - movs r0, 0x2 - movs r1, 0x36 - bl DungeonRandRange - mov r9, r0 - movs r2, 0 - str r2, [sp, 0x6C] - subs r4, 0x1 - str r4, [sp, 0x98] -_08050762: - movs r0, 0x6 - bl DungeonRandInt - adds r0, 0x2 - str r0, [sp, 0x68] - cmp r0, 0 - bne _08050772 - b _08050A38 -_08050772: - mov r0, r9 - cmp r0, 0x37 - bhi _080507B8 - mov r1, r10 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x2 - bne _0805078A - b _08050A74 -_0805078A: - mov r1, r9 - cmp r1, 0 - blt _080507A2 - mov r2, r10 - cmp r2, 0 - blt _080507A2 - mov r0, r9 - cmp r0, 0x37 - bgt _080507A2 - mov r1, r10 - cmp r1, 0x1F - ble _080507A6 -_080507A2: - movs r0, 0x1 - b _080507A8 -_080507A6: - movs r0, 0 -_080507A8: - cmp r0, 0 - bne _080507B8 - mov r0, r9 - mov r1, r10 - bl GetTileSafe - bl sub_80506BC -_080507B8: - ldr r2, [sp, 0x68] - subs r2, 0x1 - str r2, [sp, 0x68] - ldr r0, [sp, 0x6C] - add r9, r0 - ldr r1, [sp, 0x70] - add r10, r1 - mov r2, r10 - cmp r2, 0x1F - bls _080507CE - b _08050A38 -_080507CE: - ldr r0, [sp, 0x78] - subs r0, 0x1 - str r0, [sp, 0x78] - cmp r0, 0 - beq _080507DA - b _08050A30 -_080507DA: - movs r1, 0x3F - str r1, [sp, 0x7C] -_080507DE: - movs r0, 0x7 - bl DungeonRandInt - subs r0, 0x3 - str r0, [sp, 0x84] - movs r0, 0x7 - bl DungeonRandInt - subs r1, r0, 0x3 - ldr r6, [sp, 0x84] - add r6, r9 - subs r0, r6, 0x2 - cmp r0, 0x33 - bhi _080508DA - mov r2, r10 - adds r5, r1, r2 - cmp r5, 0x1 - ble _080508DA - cmp r5, 0x1D - bgt _080508DA - adds r4, r6, 0x1 - adds r0, r5, 0x1 - mov r8, r0 - adds r0, r4, 0 - mov r1, r8 - bl GetTile - ldrh r1, [r0] - movs r2, 0x3 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - beq _080508B2 - adds r0, r4, 0 - adds r1, r5, 0 - str r2, [sp, 0x9C] - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x9C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - beq _080508B2 - subs r7, r5, 0x1 - adds r0, r4, 0 - adds r1, r7, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x9C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - beq _080508B2 - adds r0, r6, 0 - mov r1, r8 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x9C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - beq _080508B2 - adds r0, r6, 0 - adds r1, r7, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x9C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - beq _080508B2 - subs r4, r6, 0x1 - adds r0, r4, 0 - mov r1, r8 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x9C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - beq _080508B2 - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x9C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - beq _080508B2 - adds r0, r4, 0 - adds r1, r7, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x9C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x2 - bne _080508DA -_080508B2: - ldr r0, [sp, 0x84] - add r0, r9 - cmp r0, 0 - blt _080508C6 - cmp r5, 0 - blt _080508C6 - cmp r0, 0x37 - bgt _080508C6 - cmp r5, 0x1F - ble _080508CA -_080508C6: - movs r1, 0x1 - b _080508CC -_080508CA: - movs r1, 0 -_080508CC: - cmp r1, 0 - bne _080508DA - adds r1, r5, 0 - bl GetTileSafe - bl sub_80506BC -_080508DA: - ldr r1, [sp, 0x7C] - subs r1, 0x1 - str r1, [sp, 0x7C] - cmp r1, 0 - blt _080508E6 - b _080507DE -_080508E6: - movs r0, 0x3 - negs r0, r0 -_080508EA: - movs r2, 0x3 - negs r2, r2 - str r2, [sp, 0x80] - mov r1, r9 - adds r1, r0, r1 - str r1, [sp, 0x90] - adds r0, 0x1 - str r0, [sp, 0x8C] - adds r7, r1, 0 - mov r5, r10 - subs r5, 0x3 -_08050900: - movs r6, 0 - subs r0, r7, 0x2 - cmp r0, 0x33 - bls _0805090A - b _08050A1A -_0805090A: - str r5, [sp, 0x88] - str r5, [sp, 0x94] - cmp r5, 0x1 - bgt _08050914 - b _08050A1A -_08050914: - cmp r5, 0x1D - ble _0805091A - b _08050A1A -_0805091A: - adds r4, r7, 0x1 - adds r3, r5, 0x1 - adds r0, r4, 0 - adds r1, r3, 0 - str r3, [sp, 0xA0] - bl GetTile - ldrh r1, [r0] - movs r2, 0x3 - mov r8, r2 - mov r0, r8 - ands r0, r1 - ldr r3, [sp, 0xA0] - cmp r0, 0x2 - bne _0805093A - movs r6, 0x1 -_0805093A: - adds r0, r4, 0 - adds r1, r5, 0 - str r3, [sp, 0xA0] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r3, [sp, 0xA0] - cmp r0, 0x2 - bne _08050952 - adds r6, 0x1 -_08050952: - subs r2, r5, 0x1 - adds r0, r4, 0 - adds r1, r2, 0 - str r2, [sp, 0x9C] - str r3, [sp, 0xA0] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x9C] - ldr r3, [sp, 0xA0] - cmp r0, 0x2 - bne _08050970 - adds r6, 0x1 -_08050970: - adds r0, r7, 0 - adds r1, r3, 0 - str r2, [sp, 0x9C] - str r3, [sp, 0xA0] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x9C] - ldr r3, [sp, 0xA0] - cmp r0, 0x2 - bne _0805098C - adds r6, 0x1 -_0805098C: - adds r0, r7, 0 - adds r1, r2, 0 - str r2, [sp, 0x9C] - str r3, [sp, 0xA0] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x9C] - ldr r3, [sp, 0xA0] - cmp r0, 0x2 - bne _080509A8 - adds r6, 0x1 -_080509A8: - subs r4, r7, 0x1 - adds r0, r4, 0 - adds r1, r3, 0 - str r2, [sp, 0x9C] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x9C] - cmp r0, 0x2 - bne _080509C2 - adds r6, 0x1 -_080509C2: - adds r0, r4, 0 - adds r1, r5, 0 - str r2, [sp, 0x9C] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x9C] - cmp r0, 0x2 - bne _080509DA - adds r6, 0x1 -_080509DA: - adds r0, r4, 0 - adds r1, r2, 0 - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - cmp r0, 0x2 - bne _080509EE - adds r6, 0x1 -_080509EE: - cmp r6, 0x3 - ble _08050A1A - cmp r7, 0 - blt _08050A04 - cmp r5, 0 - blt _08050A04 - cmp r7, 0x37 - bgt _08050A04 - ldr r0, [sp, 0x88] - cmp r0, 0x1F - ble _08050A08 -_08050A04: - movs r0, 0x1 - b _08050A0A -_08050A08: - movs r0, 0 -_08050A0A: - cmp r0, 0 - bne _08050A1A - ldr r0, [sp, 0x90] - ldr r1, [sp, 0x94] - bl GetTileSafe - bl sub_80506BC -_08050A1A: - adds r5, 0x1 - ldr r1, [sp, 0x80] - adds r1, 0x1 - str r1, [sp, 0x80] - cmp r1, 0x3 - bgt _08050A28 - b _08050900 -_08050A28: - ldr r0, [sp, 0x8C] - cmp r0, 0x3 - bgt _08050A30 - b _080508EA -_08050A30: - ldr r2, [sp, 0x68] - cmp r2, 0 - beq _08050A38 - b _08050772 -_08050A38: - ldr r0, [sp, 0x6C] - cmp r0, 0 - beq _08050A54 - movs r1, 0x1 - str r1, [sp, 0x70] - ldr r2, [sp, 0x74] - cmp r2, 0 - beq _08050A4E - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0x70] -_08050A4E: - movs r1, 0 - str r1, [sp, 0x6C] - b _08050A6C -_08050A54: - movs r0, 0x64 - bl DungeonRandInt - movs r2, 0x1 - str r2, [sp, 0x6C] - cmp r0, 0x31 - bgt _08050A68 - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0x6C] -_08050A68: - movs r1, 0 - str r1, [sp, 0x70] -_08050A6C: - mov r2, r10 - cmp r2, 0x1F - bhi _08050A74 - b _08050762 -_08050A74: - ldr r4, [sp, 0x98] - cmp r4, 0 - beq _08050A7C - b _0805071C -_08050A7C: - movs r0, 0 - ldr r1, [sp, 0x64] - ldrb r1, [r1, 0x15] - cmp r0, r1 - blt _08050A88 - b _08050BAE -_08050A88: - movs r2, 0 - mov r8, r2 - mov r9, r2 - movs r5, 0 - adds r0, 0x1 - mov r10, r0 - b _08050A98 -_08050A96: - adds r5, 0x1 -_08050A98: - cmp r5, 0xC7 - bgt _08050AC2 - movs r0, 0 - movs r1, 0x38 - bl DungeonRandRange - mov r9, r0 - movs r0, 0 - movs r1, 0x20 - bl DungeonRandRange - mov r8, r0 - mov r0, r9 - subs r0, 0x1 - cmp r0, 0x35 - bhi _08050A96 - mov r0, r8 - cmp r0, 0 - ble _08050A96 - cmp r0, 0x1E - bgt _08050A96 -_08050AC2: - cmp r5, 0xC8 - beq _08050BA2 - movs r7, 0 - movs r3, 0x1 - movs r1, 0 -_08050ACC: - movs r2, 0 - lsls r0, r7, 2 - adds r4, r7, 0x1 - adds r0, r7 - lsls r0, 1 - add r0, sp -_08050AD8: - cmp r7, 0 - beq _08050AE8 - cmp r7, 0x9 - beq _08050AE8 - cmp r2, 0 - beq _08050AE8 - cmp r2, 0x9 - bne _08050AEC -_08050AE8: - strb r3, [r0] - b _08050AEE -_08050AEC: - strb r1, [r0] -_08050AEE: - adds r0, 0x1 - adds r2, 0x1 - cmp r2, 0x9 - ble _08050AD8 - adds r7, r4, 0 - cmp r7, 0x9 - ble _08050ACC - movs r5, 0x4F -_08050AFE: - movs r0, 0x8 - bl DungeonRandInt - adds r4, r0, 0 - adds r7, r4, 0x1 - movs r0, 0x8 - bl DungeonRandInt - adds r2, r0, 0x1 - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 1 - adds r0, r2, r0 - add r0, sp - ldrb r0, [r0] - cmp r0, 0 - bne _08050B50 - adds r1, r7, 0x1 - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 1 - adds r0, r2, r0 - add r0, sp - ldrb r0, [r0] - cmp r0, 0 - bne _08050B50 - lsls r0, r7, 2 - adds r0, r7 - lsls r1, r0, 1 - subs r0, r1, 0x1 - adds r0, r2, r0 - add r0, sp - ldrb r0, [r0] - cmp r0, 0 - bne _08050B50 - adds r0, r1, 0x1 - adds r0, r2, r0 - add r0, sp - ldrb r0, [r0] - cmp r0, 0 - beq _08050B60 -_08050B50: - lsls r0, r7, 2 - adds r0, r7 - lsls r0, 1 - adds r0, r2, r0 - mov r2, sp - adds r1, r2, r0 - movs r0, 0x1 - strb r0, [r1] -_08050B60: - subs r5, 0x1 - cmp r5, 0 - bge _08050AFE - movs r7, 0 -_08050B68: - lsls r0, r7, 2 - adds r4, r7, 0x1 - adds r0, r7 - lsls r0, 1 - mov r6, r8 - subs r6, 0x5 - mov r1, sp - adds r5, r0, r1 - add r7, r9 - movs r2, 0x9 -_08050B7C: - ldrb r0, [r5] - cmp r0, 0 - bne _08050B92 - subs r0, r7, 0x5 - adds r1, r6, 0 - str r2, [sp, 0x9C] - bl GetTileSafe - bl sub_80506BC - ldr r2, [sp, 0x9C] -_08050B92: - adds r6, 0x1 - adds r5, 0x1 - subs r2, 0x1 - cmp r2, 0 - bge _08050B7C - adds r7, r4, 0 - cmp r7, 0x9 - ble _08050B68 -_08050BA2: - mov r0, r10 - ldr r2, [sp, 0x64] - ldrb r2, [r2, 0x15] - cmp r0, r2 - bge _08050BAE - b _08050A88 -_08050BAE: - movs r0, 0 - mov r9, r0 - movs r6, 0x1 - ldr r1, _08050BF4 - adds r5, r1, 0 -_08050BB8: - movs r2, 0 - mov r10, r2 - mov r4, r9 - adds r4, 0x1 -_08050BC0: - mov r0, r9 - mov r1, r10 - bl GetTileSafe - adds r2, r0, 0 - ldrh r3, [r2] - movs r0, 0x3 - ands r0, r3 - cmp r0, 0x2 - bne _08050C10 - movs r1, 0xB0 - lsls r1, 1 - adds r0, r1, 0 - ands r0, r3 - cmp r0, 0 - bne _08050BEA - ldrh r1, [r2, 0x4] - adds r0, r6, 0 - ands r0, r1 - cmp r0, 0 - beq _08050BF8 -_08050BEA: - adds r0, r3, 0 - ands r0, r5 - orrs r0, r6 - b _08050C0E - .align 2, 0 -_08050BF4: .4byte 0x0000fffc -_08050BF8: - mov r0, r9 - subs r0, 0x2 - cmp r0, 0x34 - bhi _08050C0A - mov r0, r10 - cmp r0, 0x1 - ble _08050C0A - cmp r0, 0x1E - ble _08050C10 -_08050C0A: - ldrh r0, [r2] - ands r0, r5 -_08050C0E: - strh r0, [r2] -_08050C10: - movs r1, 0x1 - add r10, r1 - mov r2, r10 - cmp r2, 0x1F - ble _08050BC0 - mov r9, r4 - cmp r4, 0x37 - ble _08050BB8 -_08050C20: - add sp, 0xA4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80506F0 - thumb_func_start sub_8050C30 sub_8050C30: push {r4-r7,lr} diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index e600e3d27..f6b6d769d 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -125,7 +125,7 @@ typedef struct UnkDungeonGlobal_unk1C574 u8 unk3; u8 unk4; u8 floorConnectivity; - u8 unk6; + u8 enemyDensity; u8 kecleonShopChance; // Percentage chance 0-100% u8 monsterHouseChance; // Percentage chance 0-100% u8 mazeRoomChance; // Percentage chance 0-100% @@ -347,7 +347,7 @@ typedef struct Dungeon u8 fill3802[0x3904 - 0x3802]; /* 0x3904 */ s16 numItems; u8 fill3906[0x3A08 - 0x3906]; - /* 0x3A08 */ u8 unk3A08; + /* 0x3A08 */ bool8 forceMonsterHouse; // Forces the current floor to have monster house /* 0x3A09 */ u8 unk3A09; /* 0x3A0A */ u8 unk3A0A; /* 0x3A0B */ u8 unk3A0B; diff --git a/src/code_8042B34.c b/src/code_8042B34.c index 62d442818..57e7f649e 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -751,7 +751,7 @@ void xxx_dungeon_8042F6C(struct UnkStruct_xxx_dungeon_8042F6C *r8) } else { sub_80427AC(); - sub_8075900(GetLeader(), gDungeon->unk3A08); + sub_8075900(GetLeader(), gDungeon->forceMonsterHouse); sub_807EAA0(1, 0); } diff --git a/src/code_8066D04.c b/src/code_8066D04.c index a618531a9..da88b04e8 100644 --- a/src/code_8066D04.c +++ b/src/code_8066D04.c @@ -182,7 +182,7 @@ void HandleGiveItemAction(Entity *param_1) if (!info2->isTeamLeader) { info2->flags = info2->flags | MOVEMENT_FLAG_UNK_14; } - sub_807AB38(param_1,gDungeon->unk3A08); + sub_807AB38(param_1,gDungeon->forceMonsterHouse); } } @@ -223,7 +223,7 @@ void HandleTakeItemAction(Entity *param_1) if (!info->isTeamLeader) { info->flags |= MOVEMENT_FLAG_UNK_14; } - sub_807AB38(param_1,gDungeon->unk3A08); + sub_807AB38(param_1,gDungeon->forceMonsterHouse); } } } @@ -267,7 +267,7 @@ void sub_8066BD4(Entity *param_1) if (!info->isTeamLeader) { info->flags = info->flags | MOVEMENT_FLAG_UNK_14; } - sub_807AB38(param_1,gDungeon->unk3A08); + sub_807AB38(param_1,gDungeon->forceMonsterHouse); } } @@ -325,7 +325,7 @@ void HandlePlaceItemAction(Entity *param_1) PlaySoundEffect(0x14d); SetMessageArgument(gFormatBuffer_Monsters[0],entity,0); TryDisplayDungeonLoggableMessage(entity,*gUnknown_80F8E28); - sub_807AB38(entity,gDungeon->unk3A08); + sub_807AB38(entity,gDungeon->forceMonsterHouse); } } else diff --git a/src/code_8073CF0.c b/src/code_8073CF0.c index 07f3b9dae..376047ef9 100644 --- a/src/code_8073CF0.c +++ b/src/code_8073CF0.c @@ -1019,7 +1019,7 @@ bool8 UseAttack(Entity *a0) sub_8071DA4(mon); sub_8046D20(); - sub_8075900(mon, gDungeon->unk3A08); + sub_8075900(mon, gDungeon->forceMonsterHouse); } if (!EntityExists(mon)) continue; diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 19cb58310..a2e973226 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -157,7 +157,7 @@ void sub_807CD9C(Entity *pokemon, Entity *target, u32 direction) sub_807EC28(FALSE); } sub_806A5B8(target); - sub_8075900(target,gDungeon->unk3A08); + sub_8075900(target,gDungeon->forceMonsterHouse); } } } @@ -321,7 +321,7 @@ void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, Position *pos) sub_807EC28(0); } sub_806A5B8(target); - sub_8075900(target,gDungeon->unk3A08); + sub_8075900(target,gDungeon->forceMonsterHouse); } void sub_807D3CC(Entity *param_1) diff --git a/src/code_807E1A0.c b/src/code_807E1A0.c index a1d17e4a3..8d1223e27 100644 --- a/src/code_807E1A0.c +++ b/src/code_807E1A0.c @@ -101,7 +101,7 @@ void sub_807E254(Entity *pokemon,Entity *target) sub_807EC28(FALSE); } sub_806A5B8(pokemon); - sub_8075900(pokemon,gDungeon->unk3A08); + sub_8075900(pokemon,gDungeon->forceMonsterHouse); } if (EntityExists(target)) { @@ -110,7 +110,7 @@ void sub_807E254(Entity *pokemon,Entity *target) sub_807EC28(FALSE); } sub_806A5B8(target); - sub_8075900(target,gDungeon->unk3A08); + sub_8075900(target,gDungeon->forceMonsterHouse); } } } diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 3b9d68433..d0ad73066 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -1065,7 +1065,7 @@ void HandleUseOrbAction(Entity *pokemon) } sub_806A5B8(pokemon); - sub_8075900(pokemon, gDungeon->unk3A08); + sub_8075900(pokemon, gDungeon->forceMonsterHouse); } else if (r4) sub_8044D40(&act, 0); diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index c23e3dba6..8327aa8f8 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -107,9 +107,9 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr); void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); -void sub_80506F0(s32 a0, UnkDungeonGlobal_unk1C574 *a1); +void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr); void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); -void sub_8050438(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); +void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); EWRAM_DATA u8 gUnknown_202F1A8 = 0; EWRAM_DATA u8 gUnknown_202F1A9 = 0; @@ -210,7 +210,7 @@ void sub_804AFAC(void) ResetFloor(); gDungeon->playerSpawn.x = -1; gDungeon->playerSpawn.y = -1; - gDungeon->unk3A08 = 0; + gDungeon->forceMonsterHouse = 0; if (gDungeon->bossBattleIndex != 0) { if (sub_804C70C(gDungeon->bossBattleIndex, unkPtr)) { break; @@ -247,7 +247,7 @@ void sub_804AFAC(void) y = 1; } - gDungeon->unk3A08 = 0; + gDungeon->forceMonsterHouse = 0; gDungeon->monsterHouseRoom = 0xFF; gUnknown_202F1D0 = r7; switch (r7 & 0xF) { @@ -270,7 +270,7 @@ void sub_804AFAC(void) break; case 2: GenerateOneRoomMonsterHouseFloor(); - gDungeon->unk3A08 = 1; + gDungeon->forceMonsterHouse = 1; break; case 3: GenerateOuterRingFloor(unkPtr); @@ -282,7 +282,7 @@ void sub_804AFAC(void) break; case 5: GenerateTwoRoomsWithMonsterHouseFloor(); - gDungeon->unk3A08 = 1; + gDungeon->forceMonsterHouse = 1; break; case 6: GenerateLineFloor(unkPtr); @@ -342,15 +342,15 @@ void sub_804AFAC(void) gUnknown_202F1D8.x = -1; gUnknown_202F1D8.y = -1; GenerateOneRoomMonsterHouseFloor(); - gDungeon->unk3A08 = 1; + gDungeon->forceMonsterHouse = 1; } sub_804E9DC(); if (r10) { - sub_80506F0(1, unkPtr); + GenerateSecondaryTerrainFormations(1, unkPtr); } r4 = (DungeonRandInt(100) < unkPtr->connectedToTop); SpawnNonEnemies(unkPtr, r4); - sub_8050438(unkPtr, r4); + SpawnEnemies(unkPtr, r4); ResolveInvalidSpawns(); if (gDungeon->playerSpawn.x != -1 && gDungeon->playerSpawn.y != -1) { @@ -366,10 +366,10 @@ void sub_804AFAC(void) gUnknown_202F1D8.y = -1; ResetFloor(); GenerateOneRoomMonsterHouseFloor(); - gDungeon->unk3A08 = 1; + gDungeon->forceMonsterHouse = TRUE; sub_804E9DC(); SpawnNonEnemies(unkPtr, FALSE); - sub_8050438(unkPtr, FALSE); + SpawnEnemies(unkPtr, FALSE); ResolveInvalidSpawns(); } @@ -863,7 +863,7 @@ void NAKED sub_804AFAC(void) " beq _0804B3AA\n" " movs r0, 0x1\n" " mov r1, r8\n" -" bl sub_80506F0\n" +" bl GenerateSecondaryTerrainFormations\n" "_0804B3AA:\n" " movs r0, 0x64\n" " bl DungeonRandInt\n" @@ -879,7 +879,7 @@ void NAKED sub_804AFAC(void) " bl SpawnNonEnemies\n" " mov r0, r8\n" " adds r1, r4, 0\n" -" bl sub_8050438\n" +" bl SpawnEnemies\n" " bl ResolveInvalidSpawns\n" " ldr r5, _0804B4C0\n" " ldr r1, [r5]\n" @@ -955,7 +955,7 @@ void NAKED sub_804AFAC(void) " bl SpawnNonEnemies\n" " mov r0, r8\n" " movs r1, 0\n" -" bl sub_8050438\n" +" bl SpawnEnemies\n" " bl ResolveInvalidSpawns\n" "_0804B474:\n" " ldr r1, _0804B4B8\n" @@ -4607,9 +4607,10 @@ void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count) * See below for specific conditions on each type of spawn. */ extern const s16 gUnknown_80F4DA0; +extern const s16 gUnknown_80F4DA4; void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse) { - struct PositionU8 validSpawns[1792]; + struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; s32 count; s32 randIndex; s32 i; @@ -4940,4 +4941,460 @@ void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHous } } +/* + * SpawnEnemies - Spawns all enemies, including those in forced monster houses + */ +void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse) +{ + struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; + s32 count; + s32 randIndex; + s32 i; + s32 x, y; + Dungeon *dungeon = gDungeon; + s32 numEnemies, numMonsterHouseEnemies; + s32 enemyDensity = unkPtr->enemyDensity; + + if (enemyDensity > 0) { + // Positive means value with variance + numEnemies = DungeonRandRange(enemyDensity / 2, enemyDensity); + + if (numEnemies < 1) { + numEnemies = 1; + } + } + else { + // Negative means exact value. + // Bug - abs is missing, also it should be s8, not u8 + numEnemies = enemyDensity; + } + + count = 0; + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // Enemies can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Don't have stairs, an item + // - Not a special tile that can't be broken by Absolute Mover + // - Not where the player spawns + Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + continue; + if (tile->room == CORRIDOR_ROOM) + continue; + if (tile->terrainType & TERRAIN_TYPE_SHOP) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_ITEM) + continue; + if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_STAIRS) + continue; + if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) + continue; + if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) + continue; + if (x == dungeon->playerSpawn.x && y == dungeon->playerSpawn.y) + continue; + + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + + if (count != 0) { + // ? + if (gDungeon->unk688) { + numEnemies++; + } + if (numEnemies != 0) { + // Randomly select among the valid enemy spawn spots + ShuffleSpawnPositions(validSpawns, count); + randIndex = DungeonRandInt(count); + + for (i = 0; i < numEnemies; i++) { + Tile *tile = GetTileSafe(validSpawns[randIndex].x, validSpawns[randIndex].y); + // Spawn an enemy here + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_MONSTER; + + randIndex++; + if (randIndex == count) { + // Wrap around to the start + randIndex = 0; + } + } + } + } + + if (!dungeon->forceMonsterHouse) { + return; + } + + // This floor was marked to force a monster house + // Place extra enemy spawns in the Monster House room + + numMonsterHouseEnemies = gUnknown_80F4DA4; + count = 0; + if (isEmptyMonsterHouse) { + // An "empty" monster house only spawns 3 enemies + numMonsterHouseEnemies = 3; + } + + numMonsterHouseEnemies = (numMonsterHouseEnemies * 3) / 2; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + s32 y; + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // Monster House enemies can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not a special tile that can't be broken by Absolute Mover + // - Not where the player spawns + // - In the monster house room + + Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + continue; + if (tile->room == CORRIDOR_ROOM) + continue; + if (tile->terrainType & TERRAIN_TYPE_SHOP) + continue; + if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) + continue; + if (!(tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE)) + continue; + if (x == dungeon->playerSpawn.x && y == dungeon->playerSpawn.y) + continue; + + validSpawns[count].x = x; + validSpawns[count].y = y; + count++; + } + } + + if (count != 0) { + numEnemies = DungeonRandRange((7 * count) / 10, (8 * count) / 10); + + if (numEnemies == 0) { + numEnemies = 1; + } + + if (numEnemies >= numMonsterHouseEnemies) { + // Don't spawn more enemies than the designated limit + numEnemies = numMonsterHouseEnemies; + } + + // Randomly select among the valid enemy spawn spots + ShuffleSpawnPositions(validSpawns, count); + randIndex = DungeonRandInt(count); + + for (i = 0; i < numEnemies; i++) { + Tile *tile = GetTileSafe(validSpawns[randIndex].x, validSpawns[randIndex].y); + // Spawn an enemy here + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_MONSTER; + + randIndex++; + if (randIndex == count) { + // Wrap around to the start + randIndex = 0; + } + } + } +} + +/* + * SetSecondaryTerrainOnWall - Set a specific tile to have secondary terrain if the tile + * is a passable wall. + */ +void SetSecondaryTerrainOnWall(Tile *tile) +{ + bool8 isWall = TRUE; + if (GetTerrainType(tile) != TERRAIN_TYPE_WALL) + isWall = FALSE; + if (tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) + isWall = FALSE; + + if (isWall) { + SetTerrainSecondary(tile); + } +} + +/* + * GenerateSecondaryTerrainFormations - Generates secondary terrain (water/lava) formations + * + * This generation includes rivers, lakes along the river path, and standalone lakes. + * + * The river flows from top-to-bottom or bottom-to-top, using a random walk ending when the walk + * goes out of bounds or finds existing secondary terrain. Because of this, rivers can end prematurely + * when a lake is generated. + * + * Lakes are a large collection of secondary terrain generated around a central point. + * Standalone lakes are generated based on secondary_terrain_density + * + * The formations will never cut into room tiles, but can pass through to the other side. + */ +extern const s32 gUnknown_80F6DF8[8]; +void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + s32 num_tiles_fill; + s32 dir_x, dir_y; + bool8 dir_y_upwards; + s32 steps_until_lake; + s32 j; + s32 offsetX; + s32 offsetY; + s32 numToGen; + s32 densityN; + s32 x, y; + + if (!(unkPtr->roomFlags & flag)) + return; + + + // Generate 1-3 "river+lake" formations + numToGen = gUnknown_80F6DF8[DungeonRandInt(ARRAY_COUNT(gUnknown_80F6DF8))]; + //for (i = 0; i < numToGen; i++) { + for (;numToGen != 0; numToGen--) { + // Randomly pick between starting from the bottom going up, or from the top going down + + + if (DungeonRandInt(100) < 50) { + dir_y_upwards = TRUE; + y = DUNGEON_MAX_SIZE_Y - 1; + dir_y = -1; + } + else { + dir_y_upwards = FALSE; + y = 0; + dir_y = 1; + } + + steps_until_lake = DungeonRandInt(50) + 10; + + // Pick a random column in the interior to start the river on + x = DungeonRandRange(2, DUNGEON_MAX_SIZE_X - 2); + dir_x = 0; + + while (1) { + // Fill in tiles in chunks of size 2-7 before changing the flow direction + num_tiles_fill = DungeonRandInt(6) + 2; + //for (v = 0; v < num_tiles_fill; v++) { + while (num_tiles_fill != 0) { + if (x >= 0 && x < DUNGEON_MAX_SIZE_X) { + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_SECONDARY) { + if (!PosIsOutOfBounds(x, y)) { + // Fill in secondary terrain as we go + SetSecondaryTerrainOnWall(GetTileSafe(x, y)); + } + } + else { + goto LABEL; + } + } + num_tiles_fill--; + + // Move to the next tile + x += dir_x; + y += dir_y; + + // Vertically out of bounds, stop + if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { + break; + } + + steps_until_lake--; + if (steps_until_lake != 0) + continue; + + // After we go a certain number of steps, make a "lake" + + // This loop will attempt to generate new lake tiles up to 64 times + // We select a random tile, check for space and nearby secondary terrain tiles, + // then if verified add a new lake tile. + for (j = 0; j < 64; j++) { + // Each tile is in a random location +-3 tiles from the current cursor in either direction + s32 offsetX = DungeonRandInt(7) - 3; + s32 offsetY = DungeonRandInt(7) - 3; + + // Check that there's enough space for a lake within a 2 tile margin of the map bounds + if (offsetX + x < 2 || offsetX + x >= DUNGEON_MAX_SIZE_X - 2 || offsetY + y < 2 || offsetY + y >= DUNGEON_MAX_SIZE_Y - 2) + continue; + + // Make secondary terrain here if it's within 2 tiles + // of a tile that's currently secondary terrain + // This results in a "cluster" akin to a lake + if (GetTerrainType(GetTile(offsetX + x + 1, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY || + GetTerrainType(GetTile(offsetX + x + 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY || + GetTerrainType(GetTile(offsetX + x + 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY || + GetTerrainType(GetTile(offsetX + x + 0, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY || + GetTerrainType(GetTile(offsetX + x + 0, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY || + GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY || + GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY || + GetTerrainType(GetTile(offsetX + x - 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) + { + if (!PosIsOutOfBounds(x + offsetX, y + offsetY)) { + SetSecondaryTerrainOnWall(GetTileSafe(offsetX + x, offsetY + y)); + } + } + } + + // Finalization/gap-filling step because the random approach + // might leave weird gaps. Go through every tile and do an + // on line nearest-neighbor interpolation of secondary terrain + // tiles to smoothen out the "lake" + for (offsetX = -3; offsetX <= 3; offsetX++) { + for (offsetY = -3; offsetY <= 3; offsetY++) { + s32 numAdjacent = 0; + s32 xPlus1, yPlus1; + + if (offsetX + x < 2 || offsetX + x >= DUNGEON_MAX_SIZE_X - 2 || offsetY + y < 2 || offsetY + y >= DUNGEON_MAX_SIZE_Y - 2) + continue; + + // Count the number of secondary terrain tiles adjacent (all 8 directions) + xPlus1 = offsetX + x + 1; + yPlus1 = offsetY + y + 1; + + if (GetTerrainType(GetTile(xPlus1, yPlus1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 0, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 0, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + + // If at least half are secondary terrain, make this tile secondary terrain as well + if (numAdjacent >= 4 && !PosIsOutOfBounds(x + offsetX , y + offsetY)) { + SetSecondaryTerrainOnWall(GetTileSafe(offsetX + x , offsetY + y)); + } + } + } + } + + // Creating a lake doesn't mean we are done yet + // but it's likely that the next iteration will hit the tile + // stopping condition for secondary terrain, if not the river continues + + // Alternate between horizontal and vertical movement each iteration + if (dir_x != 0) { + // The y direction never reverses, ensuring the river doesn't + // double back on itself and cuts across the map only once + if (dir_y_upwards) { + dir_y = -1; + } + else { + dir_y = 1; + } + + dir_x = 0; + } + else { + //Randomly pick between left and right + if (DungeonRandInt(100) < 50) { + dir_x = -1; + } + else { + dir_x = 1; + } + + dir_y = 0; + } + + if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { + LABEL: + // Vertically out of bounds, stop + break; + } + } + } + + // Generate standalone lakes secondary_terrain_density # of times + for (densityN = 0; densityN < unkPtr->unk15; densityN++) { + s32 x, y; + bool8 table[10][10]; + // Try to pick a random tile in the interior to seed the "lake" + // Incredibly unlikely to fail + s32 rnd_y = 0; + s32 rnd_x = 0; + s32 n = 0; + + // Up to 200 attempts + while (n < 200) { + rnd_x = DungeonRandRange(0, DUNGEON_MAX_SIZE_X); + rnd_y = DungeonRandRange(0, DUNGEON_MAX_SIZE_Y); + + if (rnd_x >= 1 && rnd_x < DUNGEON_MAX_SIZE_X - 1 && rnd_y >= 1 && rnd_y < DUNGEON_MAX_SIZE_Y - 1) + break; + + n++; + } + + if (n == 200) + continue; + + // Make a 10x10 grid with TRUE on the boundary and FALSE on the interior + for (x = 0; x < 10; x++) { + for (y = 0; y < 10; y++) { + if (x == 0 || x == 9 || y == 0 || y == 9) { + table[x][y] = TRUE; + } + else { + table[x][y] = FALSE; + } + } + } + + // Generate an "inverse lake" by spreading the TRUE values inwards + for (n = 0; n < 80; n++) { + // Pick a random interior point on the 10x10 grid + x = DungeonRandInt(8) + 1; + y = DungeonRandInt(8) + 1; + + if (table[x - 1][y] || table[x + 1][y] || table[x][y - 1] || table[x][y + 1]) { + table[x][y] = TRUE; + } + } + + // Iterate through the grid, any spaces which are still FALSE form the inverse-inverse lake + // or as some may prefer to call it, just a regular lake! + for (x = 0; x < 10; x++) { + for (y = 0; y < 10; y++) { + if (!table[x][y]) { + // Shift the 0-10 random offset position into +- 5 to center around the lake seed tile + SetSecondaryTerrainOnWall(GetTileSafe(x + rnd_x - 5, y + rnd_y - 5)); + } + } + } + } + + // Clean up secondary terrain that got in places it shouldn't + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + Tile *tile = GetTileSafe(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_SECONDARY) + continue; + + // Revert tiles back to open terrain if: + // - in a kecleon shop + // - in a monster house + // - is an unbreakable tile + // - on a stairs spawn point + // This really shouldn't happen since we only place terrain on wall tiles to begin with, + // but it provides additional safety + + if (tile->terrainType & (TERRAIN_TYPE_SHOP | TERRAIN_TYPE_IN_MONSTER_HOUSE | TERRAIN_TYPE_UNBREAKABLE) || (tile->spawnOrVisibilityFlags & SPAWN_FLAG_STAIRS)) { + SetTerrainNormal(tile); + } + else { + // Revert to wall tiles if they're on the soft/hard borders + if (x <= 1 || x >= DUNGEON_MAX_SIZE_X - 1 || y <= 1 || y >= DUNGEON_MAX_SIZE_Y - 1) { + SetTerrainWall(tile); + } + } + } + } +} + // diff --git a/src/move_actions.c b/src/move_actions.c index 10e706752..b4d167359 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -2749,7 +2749,7 @@ _0805AA5E: sub_807EC28(FALSE); } sub_806A5B8(target); - sub_8075900(target,gDungeon->unk3A08); + sub_8075900(target,gDungeon->forceMonsterHouse); } } return TRUE; diff --git a/src/trap_1.c b/src/trap_1.c index 910ca92e6..44b6b78bb 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -483,7 +483,7 @@ void sub_8081454(unkStruct_8094924 *param_1) int iVar4; sub_808300C(param_1,gMisakiSan); - sub_80830B4(param_1, gDungeon->unk3A08); + sub_80830B4(param_1, gDungeon->forceMonsterHouse); sub_80830B4(param_1, gDungeon->unk3A09); sub_80830B4(param_1, gDungeon->unk3A0A); sub_80830B4(param_1, gDungeon->unk3A0B); @@ -820,7 +820,7 @@ void sub_8081C7C(unkStruct_8094924 *r0) s32 iVar7; sub_8083018(r0,gMisakiSan); - gDungeon->unk3A08 = sub_80831DC(r0); + gDungeon->forceMonsterHouse = sub_80831DC(r0); gDungeon->unk3A09 = sub_80831DC(r0); gDungeon->unk3A0A = sub_80831DC(r0); gDungeon->unk3A0B = sub_80831DC(r0); From cf71f8835685628b7ee903c431123174279e370d Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 15 Nov 2024 13:17:41 +0100 Subject: [PATCH 19/30] StairsAlwaysReachable --- asm/code_804FD30.s | 454 --------------- asm/code_807CD9C.s | 2 +- include/dungeon_generation.h | 1 + include/structs/map.h | 3 +- src/dungeon_generation.c | 1060 +++++++++++++++++++++++++++++++--- sym_ewram.txt | 5 - 6 files changed, 971 insertions(+), 554 deletions(-) diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index 6d3e82c56..5e7f5965e 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -5,460 +5,6 @@ .text - thumb_func_start sub_8050C30 -sub_8050C30: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _08050F3C - add sp, r4 - mov r8, r0 - mov r9, r1 - lsls r2, 24 - lsrs r2, 24 - movs r0, 0xE0 - lsls r0, 3 - add r0, sp - str r2, [r0] - movs r7, 0 - mov r1, r8 - lsls r1, 5 - movs r2, 0xE2 - lsls r2, 3 - add r2, sp - str r1, [r2] -_08050C5C: - movs r6, 0 - lsls r2, r7, 5 - adds r3, r7, 0x1 - mov r10, r3 - mov r5, sp - adds r4, r2, r5 -_08050C68: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrh r0, [r2] - movs r3, 0x3 - ands r3, r0 - movs r0, 0 - strb r0, [r4] - movs r0, 0xE0 - lsls r0, 3 - add r0, sp - ldr r0, [r0] - cmp r0, 0 - beq _08050C92 - ldrh r0, [r2] - ldr r5, _08050F40 - adds r1, r5, 0 - ands r0, r1 - strh r0, [r2] -_08050C92: - cmp r3, 0x1 - beq _08050CA8 - ldrh r1, [r2] - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - bne _08050CA8 - ldrb r0, [r4] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r4] -_08050CA8: - cmp r3, 0x2 - bne _08050CBE - ldrh r1, [r2] - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - bne _08050CBE - ldrb r0, [r4] - movs r1, 0x2 - orrs r0, r1 - strb r0, [r4] -_08050CBE: - adds r4, 0x1 - adds r6, 0x1 - cmp r6, 0x1F - ble _08050C68 - mov r7, r10 - cmp r7, 0x37 - ble _08050C5C - movs r1, 0xE2 - lsls r1, 3 - add r1, sp - ldr r0, [r1] - add r0, r9 - mov r3, sp - adds r2, r3, r0 - ldrb r1, [r2] - movs r0, 0x50 - orrs r0, r1 - strb r0, [r2] - ldr r0, _08050F44 - ldr r1, [r0] - ldr r5, _08050F48 - adds r0, r1, r5 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, r8 - beq _08050CF4 - b _08050F36 -_08050CF4: - ldr r3, _08050F4C - adds r0, r1, r3 - movs r5, 0 - ldrsh r0, [r0, r5] - cmp r0, r9 - beq _08050D02 - b _08050F36 -_08050D02: - ldr r1, _08050F50 - movs r0, 0 - str r0, [r1] - movs r0, 0x40 - mov r9, r0 -_08050D0C: - movs r1, 0 - ldr r2, _08050F54 - add r2, sp - str r1, [r2] - ldr r3, _08050F50 - ldr r0, [r3] - adds r0, 0x1 - str r0, [r3] - movs r7, 0 -_08050D1E: - movs r6, 0 - lsls r2, r7, 5 - adds r5, r7, 0x1 - mov r10, r5 - subs r0, r7, 0x1 - movs r1, 0xE1 - lsls r1, 3 - add r1, sp - str r0, [r1] - lsls r0, 5 - mov r1, sp - subs r1, 0x1 - adds r5, r2, r1 - add r0, sp - mov r8, r0 - mov r2, r10 - ldr r3, _08050F58 - add r3, sp - str r2, [r3] - lsls r0, r2, 5 - add r0, sp - mov r12, r0 -_08050D4A: - ldrb r1, [r5, 0x1] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _08050D56 - b _08050EDA -_08050D56: - movs r3, 0x40 - mov r0, r9 - ands r0, r1 - cmp r0, 0 - bne _08050D62 - b _08050EDA -_08050D62: - ldr r2, _08050F54 - add r2, sp - ldr r0, [r2] - adds r0, 0x1 - str r0, [r2] - movs r0, 0xBF - ands r0, r1 - movs r2, 0 - movs r1, 0x80 - orrs r0, r1 - strb r0, [r5, 0x1] - cmp r7, 0 - ble _08050D90 - mov r0, r8 - ldrb r1, [r0] - movs r0, 0x83 - ands r0, r1 - cmp r0, 0 - bne _08050D90 - adds r0, r1, 0 - orrs r0, r3 - mov r1, r8 - strb r0, [r1] -_08050D90: - cmp r6, 0 - ble _08050DA4 - ldrb r1, [r5] - movs r0, 0x83 - ands r0, r1 - cmp r0, 0 - bne _08050DA4 - mov r0, r9 - orrs r0, r1 - strb r0, [r5] -_08050DA4: - cmp r7, 0x36 - bgt _08050DBA - mov r2, r12 - ldrb r1, [r2] - movs r0, 0x83 - ands r0, r1 - cmp r0, 0 - bne _08050DBA - mov r0, r9 - orrs r0, r1 - strb r0, [r2] -_08050DBA: - cmp r6, 0x1E - bgt _08050DCE - ldrb r1, [r5, 0x2] - movs r0, 0x83 - ands r0, r1 - cmp r0, 0 - bne _08050DCE - mov r0, r9 - orrs r0, r1 - strb r0, [r5, 0x2] -_08050DCE: - cmp r7, 0 - ble _08050E12 - cmp r6, 0 - ble _08050E12 - movs r3, 0xE1 - lsls r3, 3 - add r3, sp - ldr r3, [r3] - lsls r1, r3, 5 - subs r0, r1, 0x1 - adds r0, r6, r0 - mov r2, sp - adds r4, r2, r0 - ldrb r3, [r4] - movs r0, 0x87 - ands r0, r3 - cmp r0, 0 - bne _08050E12 - adds r0, r6, r1 - add r0, sp - ldrb r1, [r0] - movs r2, 0x1 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050E12 - ldrb r1, [r5] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050E12 - mov r0, r9 - orrs r0, r3 - strb r0, [r4] -_08050E12: - cmp r7, 0x36 - bgt _08050E54 - cmp r6, 0 - ble _08050E54 - ldr r3, _08050F58 - add r3, sp - ldr r3, [r3] - lsls r1, r3, 5 - subs r0, r1, 0x1 - adds r0, r6, r0 - mov r2, sp - adds r4, r2, r0 - ldrb r3, [r4] - movs r0, 0x87 - ands r0, r3 - cmp r0, 0 - bne _08050E54 - adds r0, r6, r1 - add r0, sp - ldrb r1, [r0] - movs r2, 0x1 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050E54 - ldrb r1, [r5] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050E54 - mov r0, r9 - orrs r0, r3 - strb r0, [r4] -_08050E54: - cmp r7, 0 - ble _08050E98 - cmp r6, 0x1E - bgt _08050E98 - movs r3, 0xE1 - lsls r3, 3 - add r3, sp - ldr r3, [r3] - lsls r1, r3, 5 - adds r0, r1, 0x1 - adds r0, r6, r0 - mov r2, sp - adds r4, r2, r0 - ldrb r3, [r4] - movs r0, 0x87 - ands r0, r3 - cmp r0, 0 - bne _08050E98 - adds r0, r6, r1 - add r0, sp - ldrb r1, [r0] - movs r2, 0x1 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050E98 - ldrb r1, [r5, 0x2] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050E98 - mov r0, r9 - orrs r0, r3 - strb r0, [r4] -_08050E98: - cmp r7, 0x36 - bgt _08050EDA - cmp r6, 0x1E - bgt _08050EDA - ldr r3, _08050F58 - add r3, sp - ldr r3, [r3] - lsls r1, r3, 5 - adds r0, r1, 0x1 - adds r0, r6, r0 - mov r2, sp - adds r4, r2, r0 - ldrb r3, [r4] - movs r0, 0x87 - ands r0, r3 - cmp r0, 0 - bne _08050EDA - adds r0, r6, r1 - add r0, sp - ldrb r1, [r0] - movs r2, 0x1 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050EDA - ldrb r1, [r5, 0x2] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050EDA - mov r0, r9 - orrs r0, r3 - strb r0, [r4] -_08050EDA: - adds r5, 0x1 - movs r3, 0x1 - add r8, r3 - add r12, r3 - adds r6, 0x1 - cmp r6, 0x1F - bgt _08050EEA - b _08050D4A -_08050EEA: - mov r7, r10 - cmp r7, 0x37 - bgt _08050EF2 - b _08050D1E -_08050EF2: - ldr r5, _08050F54 - add r5, sp - ldr r5, [r5] - cmp r5, 0 - beq _08050EFE - b _08050D0C -_08050EFE: - movs r7, 0 -_08050F00: - movs r6, 0 - lsls r2, r7, 5 - mov r0, sp - adds r4, r2, r0 -_08050F08: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrb r1, [r4] - movs r0, 0x87 - ands r0, r1 - cmp r0, 0 - bne _08050F68 - movs r1, 0xE0 - lsls r1, 3 - add r1, sp - ldr r1, [r1] - cmp r1, 0 - bne _08050F5C - ldrh r0, [r2] - movs r2, 0x80 - lsls r2, 1 - adds r1, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08050F68 -_08050F36: - movs r0, 0 - b _08050F78 - .align 2, 0 -_08050F3C: .4byte 0xfffff8ec -_08050F40: .4byte 0x00007fff -_08050F44: .4byte gDungeon -_08050F48: .4byte 0x0000e21c -_08050F4C: .4byte 0x0000e21e -_08050F50: .4byte gUnknown_202F1D4 -_08050F54: .4byte 0x00000704 -_08050F58: .4byte 0x0000070c -_08050F5C: - ldrh r1, [r2] - movs r3, 0x80 - lsls r3, 8 - adds r0, r3, 0 - orrs r0, r1 - strh r0, [r2] -_08050F68: - adds r4, 0x1 - adds r6, 0x1 - cmp r6, 0x1F - ble _08050F08 - adds r7, 0x1 - cmp r7, 0x37 - ble _08050F00 - movs r0, 0x1 -_08050F78: - ldr r3, _08050F8C - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_08050F8C: .4byte 0x00000714 - thumb_func_end sub_8050C30 - thumb_func_start sub_8050F90 sub_8050F90: push {r4-r7,lr} diff --git a/asm/code_807CD9C.s b/asm/code_807CD9C.s index 391f34e32..6cd0f2471 100644 --- a/asm/code_807CD9C.s +++ b/asm/code_807CD9C.s @@ -1081,7 +1081,7 @@ _0807DD94: movs r3, 0 ldrsh r1, [r1, r3] movs r2, 0x1 - bl sub_8050C30 + bl StairsAlwaysReachable lsls r0, 24 cmp r0, 0 beq _0807DE02 diff --git a/include/dungeon_generation.h b/include/dungeon_generation.h index 509d410cf..fda8a171d 100644 --- a/include/dungeon_generation.h +++ b/include/dungeon_generation.h @@ -31,5 +31,6 @@ enum SecondaryStructureType { SECONDARY_STRUCTURE_DIVIDER, // A "divider" of secondary terrain will split the room in half randomly either horizontally or vertically. }; +bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); #endif diff --git a/include/structs/map.h b/include/structs/map.h index 9553558bb..5bd916d2e 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -13,7 +13,7 @@ enum TerrainType TERRAIN_TYPE_WALL = 0, // x0 When neither TERRAIN_TYPE_NORMAL nor TERRAIN_TYPE_SECONDARY are set TERRAIN_TYPE_NORMAL = 1 << 0, // x1 TERRAIN_TYPE_SECONDARY = 1 << 1, // Water or lava depending on the dungeon. x2 - TERRAIN_TYPE_UNK_2 = 1 << 2, // x4 + TERRAIN_TYPE_CORNER_CUTTABLE = 1 << 2, // x4 This tile can be corner-cut when walking. Seemingly only used during dungeon generation. TERRAIN_TYPE_NATURAL_JUNCTION = 1 << 3, // x8 TERRAIN_TYPE_IMPASSABLE_WALL = 1 << 4, // x10 TERRAIN_TYPE_SHOP = 1 << 5, // x20 @@ -24,6 +24,7 @@ enum TerrainType TERRAIN_TYPE_UNK_x400 = 1 << 10, TERRAIN_TYPE_UNK_x800 = 1 << 11, TERRAIN_TYPE_UNK_x1000 = 1 << 12, + TERRAIN_TYPE_UNREACHABLE_FROM_STAIRS = 1 << 15, // 0x8000 }; enum CrossableTerrain diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 8327aa8f8..38141c2c9 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -11,9 +11,6 @@ extern const u8 gUnknown_80F6DCC[]; extern struct FileArchive gDungeonFileArchive; -extern Position gUnknown_202F1D8; - - extern void ResetFloor(void); extern void ResetFloor(void); extern void sub_80518F0(void); @@ -21,7 +18,6 @@ extern void GenerateOneRoomMonsterHouseFloor(void); extern void ResolveInvalidSpawns(void); extern void GenerateTwoRoomsWithMonsterHouseFloor(void); extern u8 GetFloorType(); -extern bool8 sub_8050C30(s32 a0, s32 a1, u8 a2); extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); extern const Position gAdjacentTileOffsets[]; @@ -110,6 +106,7 @@ void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr); void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); +bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); EWRAM_DATA u8 gUnknown_202F1A8 = 0; EWRAM_DATA u8 gUnknown_202F1A9 = 0; @@ -125,6 +122,8 @@ EWRAM_DATA struct MinMaxPosition sKecleonShopPosition = {0}; static EWRAM_DATA s32 sSecondaryStructuresBudget = 0; static EWRAM_DATA s32 sNumRooms = 0; EWRAM_DATA s32 gUnknown_202F1D0 = 0; +static EWRAM_DATA s32 sNumTilesReachableFromStairs = 0; +static EWRAM_DATA Position sKecleonShopMiddlePos = {0}; struct PositionU8 { @@ -205,8 +204,8 @@ void sub_804AFAC(void) sSecondaryStructuresBudget = 0; } gUnknown_202F1A9 = 0; - gUnknown_202F1D8.x = -1; - gUnknown_202F1D8.y = -1; + sKecleonShopMiddlePos.x = -1; + sKecleonShopMiddlePos.y = -1; ResetFloor(); gDungeon->playerSpawn.x = -1; gDungeon->playerSpawn.y = -1; @@ -339,8 +338,8 @@ void sub_804AFAC(void) } if (j == 10) { - gUnknown_202F1D8.x = -1; - gUnknown_202F1D8.y = -1; + sKecleonShopMiddlePos.x = -1; + sKecleonShopMiddlePos.y = -1; GenerateOneRoomMonsterHouseFloor(); gDungeon->forceMonsterHouse = 1; } @@ -356,14 +355,14 @@ void sub_804AFAC(void) { if (GetFloorType() == 1) break; - if (gDungeon->stairsSpawn.x != -1 && gDungeon->stairsSpawn.y != -1 && sub_8050C30(gDungeon->stairsSpawn.x, gDungeon->stairsSpawn.y, 0)) + if (gDungeon->stairsSpawn.x != -1 && gDungeon->stairsSpawn.y != -1 && StairsAlwaysReachable(gDungeon->stairsSpawn.x, gDungeon->stairsSpawn.y, 0)) break; } } if (i == 10) { - gUnknown_202F1D8.x = -1; - gUnknown_202F1D8.y = -1; + sKecleonShopMiddlePos.x = -1; + sKecleonShopMiddlePos.y = -1; ResetFloor(); GenerateOneRoomMonsterHouseFloor(); gDungeon->forceMonsterHouse = TRUE; @@ -373,8 +372,8 @@ void sub_804AFAC(void) ResolveInvalidSpawns(); } - if (gUnknown_202F1D8.x >= 0 && gUnknown_202F1D8.y >= 0) { - sub_806C330(gUnknown_202F1D8.x, gUnknown_202F1D8.y, 380, 0); + if (sKecleonShopMiddlePos.x >= 0 && sKecleonShopMiddlePos.y >= 0) { + sub_806C330(sKecleonShopMiddlePos.x, sKecleonShopMiddlePos.y, 380, 0); } if (sKecleonShopPosition.unk0 >= 0) { @@ -582,7 +581,7 @@ void NAKED sub_804AFAC(void) "_0804B14C: .4byte 0x0000e21e\n" "_0804B150: .4byte 0x00003a16\n" "_0804B154: .4byte gUnknown_202F1A9\n" -"_0804B158: .4byte gUnknown_202F1D8\n" +"_0804B158: .4byte sKecleonShopMiddlePos\n" "_0804B15C: .4byte 0x00003a08\n" "_0804B160: .4byte 0x00003a14\n" "_0804B164:\n" @@ -920,7 +919,7 @@ void NAKED sub_804AFAC(void) " movs r2, 0\n" " ldrsh r1, [r1, r2]\n" " movs r2, 0\n" -" bl sub_8050C30\n" +" bl StairsAlwaysReachable\n" " lsls r0, 24\n" " cmp r0, 0\n" " bne _0804B436\n" @@ -990,7 +989,7 @@ void NAKED sub_804AFAC(void) " b _0804B4EA\n" " .align 2, 0\n" "_0804B4B4: .4byte gUnknown_202F1A9\n" -"_0804B4B8: .4byte gUnknown_202F1D8\n" +"_0804B4B8: .4byte sKecleonShopMiddlePos\n" "_0804B4BC: .4byte 0x0000ffff\n" "_0804B4C0: .4byte gDungeon\n" "_0804B4C4: .4byte 0x00003a08\n" @@ -1049,7 +1048,7 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) s32 unkCount = 0; Tile *tile = GetTileSafe(x, y); - tile->terrainType &= ~(TERRAIN_TYPE_UNK_2); + tile->terrainType &= ~(TERRAIN_TYPE_CORNER_CUTTABLE); if (tile->room == CORRIDOR_ROOM && (GetTerrainType(tile) == TERRAIN_TYPE_NORMAL)) { if (x > 0 && (GetTerrainType(GetTile(x - 1, y)) == TERRAIN_TYPE_NORMAL)) unkCount++; @@ -3632,8 +3631,8 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 s32 i, j; Dungeon *dungeon = gDungeon; - gUnknown_202F1D8.x = -1; - gUnknown_202F1D8.y = -1; + sKecleonShopMiddlePos.x = -1; + sKecleonShopMiddlePos.y = -1; if (sHasMonsterHouse || GetFloorType() == FLOOR_TYPE_RESCUE || chance == 0) return; @@ -3765,8 +3764,8 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 curX = (sKecleonShopPosition.minX + sKecleonShopPosition.maxX) / 2; curY = (sKecleonShopPosition.minY + sKecleonShopPosition.maxY) / 2; - gUnknown_202F1D8.x = curX; - gUnknown_202F1D8.y = curY; + sKecleonShopMiddlePos.x = curX; + sKecleonShopMiddlePos.y = curY; return; } @@ -4319,20 +4318,20 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) SetSpawnFlag5(gridCell); // Water "Moat" - SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY - 2), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 1, middleY - 2), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY - 2), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 2), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY - 1), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY + 1), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY + 1), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 1, middleY + 1), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY + 1), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 2), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 1), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY), TERRAIN_TYPE_UNK_2); - SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY + 1), TERRAIN_TYPE_UNK_2); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 1, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY - 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 2, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX - 1, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY - 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileSafe(middleX + 1, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); // Trap GetTileSafe(middleX - 1, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_TRAP; @@ -4524,7 +4523,9 @@ void ResetTile(Tile *tile) // PosIsOutOfBounds - Checks if a position is out of bounds on the map. static inline bool8 PosIsOutOfBounds(s32 x, s32 y) { - if (x < 0 || (y < 0)) + if (x < 0) + return TRUE; + if (y < 0) return TRUE; if (DUNGEON_MAX_SIZE_X <= x) return TRUE; @@ -5136,76 +5137,76 @@ void SetSecondaryTerrainOnWall(Tile *tile) * The formations will never cut into room tiles, but can pass through to the other side. */ extern const s32 gUnknown_80F6DF8[8]; +// This function IS IMPOSSIBLE TO MATCH! Tried with 3 different compiler outputs and got nothing. Functionally it is the same, for the gba it's just a stack difference. +// https://decomp.me/scratch/9E4Uj - Red +// https://decomp.me/scratch/sA4YH - Blue +// https://decomp.me/scratch/SNyV8 - Sky +#ifdef NONMATCHING void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr) { - s32 num_tiles_fill; - s32 dir_x, dir_y; - bool8 dir_y_upwards; - s32 steps_until_lake; - s32 j; - s32 offsetX; - s32 offsetY; - s32 numToGen; s32 densityN; s32 x, y; + // Stack + + s32 numToGen; + s32 numTilesFill; if (!(unkPtr->roomFlags & flag)) return; - // Generate 1-3 "river+lake" formations - numToGen = gUnknown_80F6DF8[DungeonRandInt(ARRAY_COUNT(gUnknown_80F6DF8))]; - //for (i = 0; i < numToGen; i++) { - for (;numToGen != 0; numToGen--) { - // Randomly pick between starting from the bottom going up, or from the top going down - + for (numToGen = gUnknown_80F6DF8[DungeonRandInt(ARRAY_COUNT(gUnknown_80F6DF8))]; numToGen != 0; numToGen--) { + s32 dirX, dirY; + bool8 upwards; + s32 stepsUntilLake; + s32 j; + s32 offsetX; + s32 offsetY; + // Randomly pick between starting from the bottom going up, or from the top going down if (DungeonRandInt(100) < 50) { - dir_y_upwards = TRUE; + upwards = TRUE; y = DUNGEON_MAX_SIZE_Y - 1; - dir_y = -1; + dirY = -1; } else { - dir_y_upwards = FALSE; + upwards = FALSE; y = 0; - dir_y = 1; + dirY = 1; } - steps_until_lake = DungeonRandInt(50) + 10; + stepsUntilLake = DungeonRandInt(50) + 10; // Pick a random column in the interior to start the river on x = DungeonRandRange(2, DUNGEON_MAX_SIZE_X - 2); - dir_x = 0; + dirX = 0; while (1) { // Fill in tiles in chunks of size 2-7 before changing the flow direction - num_tiles_fill = DungeonRandInt(6) + 2; - //for (v = 0; v < num_tiles_fill; v++) { - while (num_tiles_fill != 0) { + numTilesFill = DungeonRandInt(6) + 2; + while (numTilesFill != 0) { if (x >= 0 && x < DUNGEON_MAX_SIZE_X) { - if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_SECONDARY) { - if (!PosIsOutOfBounds(x, y)) { - // Fill in secondary terrain as we go - SetSecondaryTerrainOnWall(GetTileSafe(x, y)); - } + if (GetTerrainType(GetTile(x, y)) == TERRAIN_TYPE_SECONDARY) { + goto LABEL; } - else { - goto LABEL; + if (!PosIsOutOfBounds(x, y)) { + // Fill in secondary terrain as we go + SetSecondaryTerrainOnWall(GetTileSafe(x, y)); } } - num_tiles_fill--; + numTilesFill--; // Move to the next tile - x += dir_x; - y += dir_y; + x += dirX; + y += dirY; // Vertically out of bounds, stop if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { break; } - steps_until_lake--; - if (steps_until_lake != 0) + stepsUntilLake--; + if (stepsUntilLake != 0) continue; // After we go a certain number of steps, make a "lake" @@ -5245,6 +5246,7 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk // on line nearest-neighbor interpolation of secondary terrain // tiles to smoothen out the "lake" for (offsetX = -3; offsetX <= 3; offsetX++) { + for (offsetY = -3; offsetY <= 3; offsetY++) { s32 numAdjacent = 0; s32 xPlus1, yPlus1; @@ -5253,17 +5255,17 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk continue; // Count the number of secondary terrain tiles adjacent (all 8 directions) - xPlus1 = offsetX + x + 1; + xPlus1 = offsetX + x + 1; yPlus1 = offsetY + y + 1; if (GetTerrainType(GetTile(xPlus1, yPlus1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; - if (GetTerrainType(GetTile(offsetX + x + 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; - if (GetTerrainType(GetTile(offsetX + x + 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; - if (GetTerrainType(GetTile(offsetX + x + 0, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; - if (GetTerrainType(GetTile(offsetX + x + 0, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; - if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; - if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; - if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 0, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x + 0, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y + 0)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; + if (GetTerrainType(GetTile(offsetX + x - 1, offsetY + y - 1)) == TERRAIN_TYPE_SECONDARY) numAdjacent++; // If at least half are secondary terrain, make this tile secondary terrain as well if (numAdjacent >= 4 && !PosIsOutOfBounds(x + offsetX , y + offsetY)) { @@ -5278,28 +5280,28 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk // stopping condition for secondary terrain, if not the river continues // Alternate between horizontal and vertical movement each iteration - if (dir_x != 0) { + if (dirX != 0) { // The y direction never reverses, ensuring the river doesn't // double back on itself and cuts across the map only once - if (dir_y_upwards) { - dir_y = -1; + if (upwards) { + dirY = -1; } else { - dir_y = 1; + dirY = 1; } - dir_x = 0; + dirX = 0; } else { //Randomly pick between left and right if (DungeonRandInt(100) < 50) { - dir_x = -1; + dirX = -1; } else { - dir_x = 1; + dirX = 1; } - dir_y = 0; + dirY = 0; } if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { @@ -5316,16 +5318,16 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk bool8 table[10][10]; // Try to pick a random tile in the interior to seed the "lake" // Incredibly unlikely to fail - s32 rnd_y = 0; - s32 rnd_x = 0; + s32 rndY = 0; + s32 rndX = 0; s32 n = 0; // Up to 200 attempts while (n < 200) { - rnd_x = DungeonRandRange(0, DUNGEON_MAX_SIZE_X); - rnd_y = DungeonRandRange(0, DUNGEON_MAX_SIZE_Y); + rndX = DungeonRandRange(0, DUNGEON_MAX_SIZE_X); + rndY = DungeonRandRange(0, DUNGEON_MAX_SIZE_Y); - if (rnd_x >= 1 && rnd_x < DUNGEON_MAX_SIZE_X - 1 && rnd_y >= 1 && rnd_y < DUNGEON_MAX_SIZE_Y - 1) + if (rndX >= 1 && rndX < DUNGEON_MAX_SIZE_X - 1 && rndY >= 1 && rndY < DUNGEON_MAX_SIZE_Y - 1) break; n++; @@ -5363,7 +5365,7 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk for (y = 0; y < 10; y++) { if (!table[x][y]) { // Shift the 0-10 random offset position into +- 5 to center around the lake seed tile - SetSecondaryTerrainOnWall(GetTileSafe(x + rnd_x - 5, y + rnd_y - 5)); + SetSecondaryTerrainOnWall(GetTileSafe(x + rndX - 5, y + rndY - 5)); } } } @@ -5397,4 +5399,876 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk } } +#else +NAKED void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr) +{ + asm_unified("\n" +" push {r4-r7,lr}\n" +" mov r7, r10\n" +" mov r6, r9\n" +" mov r5, r8\n" +" push {r5-r7}\n" +" sub sp, 0xA4\n" +" str r1, [sp, 0x64]\n" +" ldrb r1, [r1, 0xD]\n" +" ands r1, r0\n" +" cmp r1, 0\n" +" bne _08050708\n" +" b _08050C20\n" +"_08050708:\n" +" ldr r4, _08050738\n" +" movs r0, 0x8\n" +" bl DungeonRandInt\n" +" lsls r0, 2\n" +" adds r0, r4\n" +" ldr r4, [r0]\n" +" cmp r4, 0\n" +" bne _0805071C\n" +" b _08050A7C\n" +"_0805071C:\n" +" movs r0, 0x64\n" +" bl DungeonRandInt\n" +" cmp r0, 0x31\n" +" bgt _0805073C\n" +" movs r0, 0x1\n" +" str r0, [sp, 0x74]\n" +" movs r1, 0x1F\n" +" mov r10, r1\n" +" movs r2, 0x1\n" +" negs r2, r2\n" +" str r2, [sp, 0x70]\n" +" b _08050746\n" +" .align 2, 0\n" +"_08050738: .4byte gUnknown_80F6DF8\n" +"_0805073C:\n" +" movs r0, 0\n" +" str r0, [sp, 0x74]\n" +" mov r10, r0\n" +" movs r1, 0x1\n" +" str r1, [sp, 0x70]\n" +"_08050746:\n" +" movs r0, 0x32\n" +" bl DungeonRandInt\n" +" adds r0, 0xA\n" +" str r0, [sp, 0x78]\n" +" movs r0, 0x2\n" +" movs r1, 0x36\n" +" bl DungeonRandRange\n" +" mov r9, r0\n" +" movs r2, 0\n" +" str r2, [sp, 0x6C]\n" +" subs r4, 0x1\n" +" str r4, [sp, 0x98]\n" +"_08050762:\n" +" movs r0, 0x6\n" +" bl DungeonRandInt\n" +" adds r0, 0x2\n" +" str r0, [sp, 0x68]\n" +" cmp r0, 0\n" +" bne _08050772\n" +" b _08050A38\n" +"_08050772:\n" +" mov r0, r9\n" +" cmp r0, 0x37\n" +" bhi _080507B8\n" +" mov r1, r10\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" movs r0, 0x3\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" bne _0805078A\n" +" b _08050A74\n" +"_0805078A:\n" +" mov r1, r9\n" +" cmp r1, 0\n" +" blt _080507A2\n" +" mov r2, r10\n" +" cmp r2, 0\n" +" blt _080507A2\n" +" mov r0, r9\n" +" cmp r0, 0x37\n" +" bgt _080507A2\n" +" mov r1, r10\n" +" cmp r1, 0x1F\n" +" ble _080507A6\n" +"_080507A2:\n" +" movs r0, 0x1\n" +" b _080507A8\n" +"_080507A6:\n" +" movs r0, 0\n" +"_080507A8:\n" +" cmp r0, 0\n" +" bne _080507B8\n" +" mov r0, r9\n" +" mov r1, r10\n" +" bl GetTileSafe\n" +" bl SetSecondaryTerrainOnWall\n" +"_080507B8:\n" +" ldr r2, [sp, 0x68]\n" +" subs r2, 0x1\n" +" str r2, [sp, 0x68]\n" +" ldr r0, [sp, 0x6C]\n" +" add r9, r0\n" +" ldr r1, [sp, 0x70]\n" +" add r10, r1\n" +" mov r2, r10\n" +" cmp r2, 0x1F\n" +" bls _080507CE\n" +" b _08050A38\n" +"_080507CE:\n" +" ldr r0, [sp, 0x78]\n" +" subs r0, 0x1\n" +" str r0, [sp, 0x78]\n" +" cmp r0, 0\n" +" beq _080507DA\n" +" b _08050A30\n" +"_080507DA:\n" +" movs r1, 0x3F\n" +" str r1, [sp, 0x7C]\n" +"_080507DE:\n" +" movs r0, 0x7\n" +" bl DungeonRandInt\n" +" subs r0, 0x3\n" +" str r0, [sp, 0x84]\n" +" movs r0, 0x7\n" +" bl DungeonRandInt\n" +" subs r1, r0, 0x3\n" +" ldr r6, [sp, 0x84]\n" +" add r6, r9\n" +" subs r0, r6, 0x2\n" +" cmp r0, 0x33\n" +" bhi _080508DA\n" +" mov r2, r10\n" +" adds r5, r1, r2\n" +" cmp r5, 0x1\n" +" ble _080508DA\n" +" cmp r5, 0x1D\n" +" bgt _080508DA\n" +" adds r4, r6, 0x1\n" +" adds r0, r5, 0x1\n" +" mov r8, r0\n" +" adds r0, r4, 0\n" +" mov r1, r8\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" movs r2, 0x3\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" beq _080508B2\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" str r2, [sp, 0x9C]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" ldr r2, [sp, 0x9C]\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" beq _080508B2\n" +" subs r7, r5, 0x1\n" +" adds r0, r4, 0\n" +" adds r1, r7, 0\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" ldr r2, [sp, 0x9C]\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" beq _080508B2\n" +" adds r0, r6, 0\n" +" mov r1, r8\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" ldr r2, [sp, 0x9C]\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" beq _080508B2\n" +" adds r0, r6, 0\n" +" adds r1, r7, 0\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" ldr r2, [sp, 0x9C]\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" beq _080508B2\n" +" subs r4, r6, 0x1\n" +" adds r0, r4, 0\n" +" mov r1, r8\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" ldr r2, [sp, 0x9C]\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" beq _080508B2\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" ldr r2, [sp, 0x9C]\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" beq _080508B2\n" +" adds r0, r4, 0\n" +" adds r1, r7, 0\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" ldr r2, [sp, 0x9C]\n" +" adds r0, r2, 0\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" bne _080508DA\n" +"_080508B2:\n" +" ldr r0, [sp, 0x84]\n" +" add r0, r9\n" +" cmp r0, 0\n" +" blt _080508C6\n" +" cmp r5, 0\n" +" blt _080508C6\n" +" cmp r0, 0x37\n" +" bgt _080508C6\n" +" cmp r5, 0x1F\n" +" ble _080508CA\n" +"_080508C6:\n" +" movs r1, 0x1\n" +" b _080508CC\n" +"_080508CA:\n" +" movs r1, 0\n" +"_080508CC:\n" +" cmp r1, 0\n" +" bne _080508DA\n" +" adds r1, r5, 0\n" +" bl GetTileSafe\n" +" bl SetSecondaryTerrainOnWall\n" +"_080508DA:\n" +" ldr r1, [sp, 0x7C]\n" +" subs r1, 0x1\n" +" str r1, [sp, 0x7C]\n" +" cmp r1, 0\n" +" blt _080508E6\n" +" b _080507DE\n" +"_080508E6:\n" +" movs r0, 0x3\n" +" negs r0, r0\n" +"_080508EA:\n" +" movs r2, 0x3\n" +" negs r2, r2\n" +" str r2, [sp, 0x80]\n" +" mov r1, r9\n" +" adds r1, r0, r1\n" +" str r1, [sp, 0x90]\n" +" adds r0, 0x1\n" +" str r0, [sp, 0x8C]\n" +" adds r7, r1, 0\n" +" mov r5, r10\n" +" subs r5, 0x3\n" +"_08050900:\n" +" movs r6, 0\n" +" subs r0, r7, 0x2\n" +" cmp r0, 0x33\n" +" bls _0805090A\n" +" b _08050A1A\n" +"_0805090A:\n" +" str r5, [sp, 0x88]\n" +" str r5, [sp, 0x94]\n" +" cmp r5, 0x1\n" +" bgt _08050914\n" +" b _08050A1A\n" +"_08050914:\n" +" cmp r5, 0x1D\n" +" ble _0805091A\n" +" b _08050A1A\n" +"_0805091A:\n" +" adds r4, r7, 0x1\n" +" adds r3, r5, 0x1\n" +" adds r0, r4, 0\n" +" adds r1, r3, 0\n" +" str r3, [sp, 0xA0]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" movs r2, 0x3\n" +" mov r8, r2\n" +" mov r0, r8\n" +" ands r0, r1\n" +" ldr r3, [sp, 0xA0]\n" +" cmp r0, 0x2\n" +" bne _0805093A\n" +" movs r6, 0x1\n" +"_0805093A:\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" str r3, [sp, 0xA0]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" mov r0, r8\n" +" ands r0, r1\n" +" ldr r3, [sp, 0xA0]\n" +" cmp r0, 0x2\n" +" bne _08050952\n" +" adds r6, 0x1\n" +"_08050952:\n" +" subs r2, r5, 0x1\n" +" adds r0, r4, 0\n" +" adds r1, r2, 0\n" +" str r2, [sp, 0x9C]\n" +" str r3, [sp, 0xA0]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" mov r0, r8\n" +" ands r0, r1\n" +" ldr r2, [sp, 0x9C]\n" +" ldr r3, [sp, 0xA0]\n" +" cmp r0, 0x2\n" +" bne _08050970\n" +" adds r6, 0x1\n" +"_08050970:\n" +" adds r0, r7, 0\n" +" adds r1, r3, 0\n" +" str r2, [sp, 0x9C]\n" +" str r3, [sp, 0xA0]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" mov r0, r8\n" +" ands r0, r1\n" +" ldr r2, [sp, 0x9C]\n" +" ldr r3, [sp, 0xA0]\n" +" cmp r0, 0x2\n" +" bne _0805098C\n" +" adds r6, 0x1\n" +"_0805098C:\n" +" adds r0, r7, 0\n" +" adds r1, r2, 0\n" +" str r2, [sp, 0x9C]\n" +" str r3, [sp, 0xA0]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" mov r0, r8\n" +" ands r0, r1\n" +" ldr r2, [sp, 0x9C]\n" +" ldr r3, [sp, 0xA0]\n" +" cmp r0, 0x2\n" +" bne _080509A8\n" +" adds r6, 0x1\n" +"_080509A8:\n" +" subs r4, r7, 0x1\n" +" adds r0, r4, 0\n" +" adds r1, r3, 0\n" +" str r2, [sp, 0x9C]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" mov r0, r8\n" +" ands r0, r1\n" +" ldr r2, [sp, 0x9C]\n" +" cmp r0, 0x2\n" +" bne _080509C2\n" +" adds r6, 0x1\n" +"_080509C2:\n" +" adds r0, r4, 0\n" +" adds r1, r5, 0\n" +" str r2, [sp, 0x9C]\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" mov r0, r8\n" +" ands r0, r1\n" +" ldr r2, [sp, 0x9C]\n" +" cmp r0, 0x2\n" +" bne _080509DA\n" +" adds r6, 0x1\n" +"_080509DA:\n" +" adds r0, r4, 0\n" +" adds r1, r2, 0\n" +" bl GetTile\n" +" ldrh r1, [r0]\n" +" mov r0, r8\n" +" ands r0, r1\n" +" cmp r0, 0x2\n" +" bne _080509EE\n" +" adds r6, 0x1\n" +"_080509EE:\n" +" cmp r6, 0x3\n" +" ble _08050A1A\n" +" cmp r7, 0\n" +" blt _08050A04\n" +" cmp r5, 0\n" +" blt _08050A04\n" +" cmp r7, 0x37\n" +" bgt _08050A04\n" +" ldr r0, [sp, 0x88]\n" +" cmp r0, 0x1F\n" +" ble _08050A08\n" +"_08050A04:\n" +" movs r0, 0x1\n" +" b _08050A0A\n" +"_08050A08:\n" +" movs r0, 0\n" +"_08050A0A:\n" +" cmp r0, 0\n" +" bne _08050A1A\n" +" ldr r0, [sp, 0x90]\n" +" ldr r1, [sp, 0x94]\n" +" bl GetTileSafe\n" +" bl SetSecondaryTerrainOnWall\n" +"_08050A1A:\n" +" adds r5, 0x1\n" +" ldr r1, [sp, 0x80]\n" +" adds r1, 0x1\n" +" str r1, [sp, 0x80]\n" +" cmp r1, 0x3\n" +" bgt _08050A28\n" +" b _08050900\n" +"_08050A28:\n" +" ldr r0, [sp, 0x8C]\n" +" cmp r0, 0x3\n" +" bgt _08050A30\n" +" b _080508EA\n" +"_08050A30:\n" +" ldr r2, [sp, 0x68]\n" +" cmp r2, 0\n" +" beq _08050A38\n" +" b _08050772\n" +"_08050A38:\n" +" ldr r0, [sp, 0x6C]\n" +" cmp r0, 0\n" +" beq _08050A54\n" +" movs r1, 0x1\n" +" str r1, [sp, 0x70]\n" +" ldr r2, [sp, 0x74]\n" +" cmp r2, 0\n" +" beq _08050A4E\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" str r0, [sp, 0x70]\n" +"_08050A4E:\n" +" movs r1, 0\n" +" str r1, [sp, 0x6C]\n" +" b _08050A6C\n" +"_08050A54:\n" +" movs r0, 0x64\n" +" bl DungeonRandInt\n" +" movs r2, 0x1\n" +" str r2, [sp, 0x6C]\n" +" cmp r0, 0x31\n" +" bgt _08050A68\n" +" movs r0, 0x1\n" +" negs r0, r0\n" +" str r0, [sp, 0x6C]\n" +"_08050A68:\n" +" movs r1, 0\n" +" str r1, [sp, 0x70]\n" +"_08050A6C:\n" +" mov r2, r10\n" +" cmp r2, 0x1F\n" +" bhi _08050A74\n" +" b _08050762\n" +"_08050A74:\n" +" ldr r4, [sp, 0x98]\n" +" cmp r4, 0\n" +" beq _08050A7C\n" +" b _0805071C\n" +"_08050A7C:\n" +" movs r0, 0\n" +" ldr r1, [sp, 0x64]\n" +" ldrb r1, [r1, 0x15]\n" +" cmp r0, r1\n" +" blt _08050A88\n" +" b _08050BAE\n" +"_08050A88:\n" +" movs r2, 0\n" +" mov r8, r2\n" +" mov r9, r2\n" +" movs r5, 0\n" +" adds r0, 0x1\n" +" mov r10, r0\n" +" b _08050A98\n" +"_08050A96:\n" +" adds r5, 0x1\n" +"_08050A98:\n" +" cmp r5, 0xC7\n" +" bgt _08050AC2\n" +" movs r0, 0\n" +" movs r1, 0x38\n" +" bl DungeonRandRange\n" +" mov r9, r0\n" +" movs r0, 0\n" +" movs r1, 0x20\n" +" bl DungeonRandRange\n" +" mov r8, r0\n" +" mov r0, r9\n" +" subs r0, 0x1\n" +" cmp r0, 0x35\n" +" bhi _08050A96\n" +" mov r0, r8\n" +" cmp r0, 0\n" +" ble _08050A96\n" +" cmp r0, 0x1E\n" +" bgt _08050A96\n" +"_08050AC2:\n" +" cmp r5, 0xC8\n" +" beq _08050BA2\n" +" movs r7, 0\n" +" movs r3, 0x1\n" +" movs r1, 0\n" +"_08050ACC:\n" +" movs r2, 0\n" +" lsls r0, r7, 2\n" +" adds r4, r7, 0x1\n" +" adds r0, r7\n" +" lsls r0, 1\n" +" add r0, sp\n" +"_08050AD8:\n" +" cmp r7, 0\n" +" beq _08050AE8\n" +" cmp r7, 0x9\n" +" beq _08050AE8\n" +" cmp r2, 0\n" +" beq _08050AE8\n" +" cmp r2, 0x9\n" +" bne _08050AEC\n" +"_08050AE8:\n" +" strb r3, [r0]\n" +" b _08050AEE\n" +"_08050AEC:\n" +" strb r1, [r0]\n" +"_08050AEE:\n" +" adds r0, 0x1\n" +" adds r2, 0x1\n" +" cmp r2, 0x9\n" +" ble _08050AD8\n" +" adds r7, r4, 0\n" +" cmp r7, 0x9\n" +" ble _08050ACC\n" +" movs r5, 0x4F\n" +"_08050AFE:\n" +" movs r0, 0x8\n" +" bl DungeonRandInt\n" +" adds r4, r0, 0\n" +" adds r7, r4, 0x1\n" +" movs r0, 0x8\n" +" bl DungeonRandInt\n" +" adds r2, r0, 0x1\n" +" lsls r0, r4, 2\n" +" adds r0, r4\n" +" lsls r0, 1\n" +" adds r0, r2, r0\n" +" add r0, sp\n" +" ldrb r0, [r0]\n" +" cmp r0, 0\n" +" bne _08050B50\n" +" adds r1, r7, 0x1\n" +" lsls r0, r1, 2\n" +" adds r0, r1\n" +" lsls r0, 1\n" +" adds r0, r2, r0\n" +" add r0, sp\n" +" ldrb r0, [r0]\n" +" cmp r0, 0\n" +" bne _08050B50\n" +" lsls r0, r7, 2\n" +" adds r0, r7\n" +" lsls r1, r0, 1\n" +" subs r0, r1, 0x1\n" +" adds r0, r2, r0\n" +" add r0, sp\n" +" ldrb r0, [r0]\n" +" cmp r0, 0\n" +" bne _08050B50\n" +" adds r0, r1, 0x1\n" +" adds r0, r2, r0\n" +" add r0, sp\n" +" ldrb r0, [r0]\n" +" cmp r0, 0\n" +" beq _08050B60\n" +"_08050B50:\n" +" lsls r0, r7, 2\n" +" adds r0, r7\n" +" lsls r0, 1\n" +" adds r0, r2, r0\n" +" mov r2, sp\n" +" adds r1, r2, r0\n" +" movs r0, 0x1\n" +" strb r0, [r1]\n" +"_08050B60:\n" +" subs r5, 0x1\n" +" cmp r5, 0\n" +" bge _08050AFE\n" +" movs r7, 0\n" +"_08050B68:\n" +" lsls r0, r7, 2\n" +" adds r4, r7, 0x1\n" +" adds r0, r7\n" +" lsls r0, 1\n" +" mov r6, r8\n" +" subs r6, 0x5\n" +" mov r1, sp\n" +" adds r5, r0, r1\n" +" add r7, r9\n" +" movs r2, 0x9\n" +"_08050B7C:\n" +" ldrb r0, [r5]\n" +" cmp r0, 0\n" +" bne _08050B92\n" +" subs r0, r7, 0x5\n" +" adds r1, r6, 0\n" +" str r2, [sp, 0x9C]\n" +" bl GetTileSafe\n" +" bl SetSecondaryTerrainOnWall\n" +" ldr r2, [sp, 0x9C]\n" +"_08050B92:\n" +" adds r6, 0x1\n" +" adds r5, 0x1\n" +" subs r2, 0x1\n" +" cmp r2, 0\n" +" bge _08050B7C\n" +" adds r7, r4, 0\n" +" cmp r7, 0x9\n" +" ble _08050B68\n" +"_08050BA2:\n" +" mov r0, r10\n" +" ldr r2, [sp, 0x64]\n" +" ldrb r2, [r2, 0x15]\n" +" cmp r0, r2\n" +" bge _08050BAE\n" +" b _08050A88\n" +"_08050BAE:\n" +" movs r0, 0\n" +" mov r9, r0\n" +" movs r6, 0x1\n" +" ldr r1, _08050BF4\n" +" adds r5, r1, 0\n" +"_08050BB8:\n" +" movs r2, 0\n" +" mov r10, r2\n" +" mov r4, r9\n" +" adds r4, 0x1\n" +"_08050BC0:\n" +" mov r0, r9\n" +" mov r1, r10\n" +" bl GetTileSafe\n" +" adds r2, r0, 0\n" +" ldrh r3, [r2]\n" +" movs r0, 0x3\n" +" ands r0, r3\n" +" cmp r0, 0x2\n" +" bne _08050C10\n" +" movs r1, 0xB0\n" +" lsls r1, 1\n" +" adds r0, r1, 0\n" +" ands r0, r3\n" +" cmp r0, 0\n" +" bne _08050BEA\n" +" ldrh r1, [r2, 0x4]\n" +" adds r0, r6, 0\n" +" ands r0, r1\n" +" cmp r0, 0\n" +" beq _08050BF8\n" +"_08050BEA:\n" +" adds r0, r3, 0\n" +" ands r0, r5\n" +" orrs r0, r6\n" +" b _08050C0E\n" +" .align 2, 0\n" +"_08050BF4: .4byte 0x0000fffc\n" +"_08050BF8:\n" +" mov r0, r9\n" +" subs r0, 0x2\n" +" cmp r0, 0x34\n" +" bhi _08050C0A\n" +" mov r0, r10\n" +" cmp r0, 0x1\n" +" ble _08050C0A\n" +" cmp r0, 0x1E\n" +" ble _08050C10\n" +"_08050C0A:\n" +" ldrh r0, [r2]\n" +" ands r0, r5\n" +"_08050C0E:\n" +" strh r0, [r2]\n" +"_08050C10:\n" +" movs r1, 0x1\n" +" add r10, r1\n" +" mov r2, r10\n" +" cmp r2, 0x1F\n" +" ble _08050BC0\n" +" mov r9, r4\n" +" cmp r4, 0x37\n" +" ble _08050BB8\n" +"_08050C20:\n" +" add sp, 0xA4\n" +" pop {r3-r5}\n" +" mov r8, r3\n" +" mov r9, r4\n" +" mov r10, r5\n" +" pop {r4-r7}\n" +" pop {r0}\n" +" bx r0\n"); +} +#endif // NONMATCHING + +#define STAIRS_FLAG_CANNOT_CORNER_CUT 0x1 // Set to `true` for non-open terrain tiles which have `TERRAIN_TYPE_CORNER_CUTTABLE` in their [TerrainFlags] +#define STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT 0x2 // Set to `true` for secondary terrain tiles which have `TERRAIN_TYPE_CORNER_CUTTABLE` in their [TerrainFlags] +#define STAIRS_FLAG_UNKNOWN 0x4 // Not fully understood field. Is tested in relation to corners, but appears to never be set to `true`. +#define STAIRS_FLAG_STARTING_POINT 0x10 // Determines the starting point for graph traversal, set to `true` on the Stairs tile. +#define STAIRS_FLAG_IN_VISIT_QUEUE 0x40 // Set to `true` for tiles which are currently queued to be visited. +#define STAIRS_FLAG_VISITED 0x80 // Set to `true` for tiles which have been visit + +/* + * StairsAlwaysReachable - Checks that the stairs are always reachable from every walkable tile on the floor + * + * Uses a graph-traversal similar to Breadth-First Search (but with slightly different order due to how + * iteration works)) + * + * If any tile is walkable but wasn't reached, this function will return FALSE. + * If every tile was reached, this function will return TRUE. + */ +bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) +{ + s32 x, y; + u8 test[DUNGEON_MAX_SIZE_X][DUNGEON_MAX_SIZE_Y]; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + Tile *tile = GetTileSafe(x, y); + u16 terrain = GetTerrainType(tile); + + test[x][y] = 0; + if (markUnreachable) { + // Reset all unreachable flags on tiles, they'll be recomputed from scratch + tile->terrainType &= ~(TERRAIN_TYPE_UNREACHABLE_FROM_STAIRS); + } + + if (terrain != TERRAIN_TYPE_NORMAL) { + if (!(tile->terrainType & TERRAIN_TYPE_CORNER_CUTTABLE)) { + test[x][y] |= STAIRS_FLAG_CANNOT_CORNER_CUT; + } + } + + if (terrain == TERRAIN_TYPE_SECONDARY) { + if (!(tile->terrainType & TERRAIN_TYPE_CORNER_CUTTABLE)) { + test[x][y] |= STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT; + } + } + } + } + + test[stairsX][stairsY] |= STAIRS_FLAG_STARTING_POINT | STAIRS_FLAG_IN_VISIT_QUEUE; + + if (gDungeon->stairsSpawn.x != stairsX || gDungeon->stairsSpawn.y != stairsY) { + return FALSE; + } + + sNumTilesReachableFromStairs = 0; + + // Uses a semi-BFS starting from the stairs until all reachable tiles + // have been visited + while (1) { + s32 checked = 0; + sNumTilesReachableFromStairs += 1; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (!(test[x][y] & STAIRS_FLAG_VISITED) && test[x][y] & STAIRS_FLAG_IN_VISIT_QUEUE) { + checked++; + test[x][y] &= ~(STAIRS_FLAG_IN_VISIT_QUEUE); + test[x][y] |= STAIRS_FLAG_VISITED; + + // Queue up in cardinal directions of this tile + + // Left + if (x > 0 && !(test[x - 1][y] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x - 1][y] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + + // Up + if (y > 0 && !(test[x][y - 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x][y - 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + + // Right + if (x < DUNGEON_MAX_SIZE_X - 1 && !(test[x + 1][y] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x + 1][y] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + + // Down + if (y < DUNGEON_MAX_SIZE_Y - 1 && !(test[x][y + 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x][y + 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + + // Up-left + if (x > 0 && y > 0 + && !(test[x - 1][y - 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) + && !(test[x - 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) + && !(test[x][y - 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) + { + test[x - 1][y - 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + + // Up-Right + if (x < DUNGEON_MAX_SIZE_X - 1 && y > 0 + && !(test[x + 1][y - 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) + && !(test[x + 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) + && !(test[x][y - 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) + { + test[x + 1][y - 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + + // Down-left + if (x > 0 && y < DUNGEON_MAX_SIZE_Y - 1 + && !(test[x - 1][y + 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) + && !(test[x - 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) + && !(test[x][y + 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) + { + test[x - 1][y + 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + + // Down-right + if (x < DUNGEON_MAX_SIZE_X - 1 && y < DUNGEON_MAX_SIZE_Y - 1 + && !(test[x + 1][y + 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) + && !(test[x + 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) + && !(test[x][y + 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) + { + test[x + 1][y + 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } + } + } + } + + if (checked == 0) + break; + } + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + Tile *tile = GetTileSafe(x, y); + + if (!(test[x][y] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_UNKNOWN | STAIRS_FLAG_VISITED))) { + // This is an open tile that wasn't visited by BFS, which means it's unreachable from the starting stairs + if (markUnreachable) { + tile->terrainType |= TERRAIN_TYPE_UNREACHABLE_FROM_STAIRS; + } + else { + // unbreakable tiles can't really be navigated onto anyways, so if + // we can ignore the tile (otherwise it's a problem!) + if (!(tile->terrainType & TERRAIN_TYPE_UNBREAKABLE)) { + return FALSE; + } + } + } + } + } + + return TRUE; +} + +/* +void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 x2, s32 y2) +{ + +} +*/ + // diff --git a/sym_ewram.txt b/sym_ewram.txt index 07d02485a..8dc3653f5 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -276,11 +276,6 @@ gUnknown_202EE76: /* 202EE76 (sub_804513C - sub_8082A08) */ .include "src/dungeon_map_access.o" .include "src/dungeon_generation.o" -gUnknown_202F1D4: /* 202F1D4 (sub_8050C30) */ - .space 0x4 -gUnknown_202F1D8: /* 202F1D8 (sub_804AFAC - sub_804EBC8) */ - .space 0x4 - gUnknown_202F1DC: /* 202F1DC (sub_80511F0 - sub_8051438) */ .space 0x4 gUnknown_202F1E0: /* 202F1E0 (sub_80511F0) */ From 973838de7a6948391b750160d2c3a06f6e909c04 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 15 Nov 2024 15:35:02 +0100 Subject: [PATCH 20/30] sub_805124C --- asm/code_804FD30.s | 404 ---------------------------------- include/structs/str_dungeon.h | 2 +- src/code_8042B34.c | 2 +- src/code_806FDF4.c | 6 +- src/code_80848F0.c | 10 +- src/dungeon_engine.c | 2 +- src/dungeon_generation.c | 202 +++++++++++++++-- src/trap_1.c | 4 +- 8 files changed, 193 insertions(+), 439 deletions(-) diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index 5e7f5965e..d4e137903 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -5,410 +5,6 @@ .text - thumb_func_start sub_8050F90 -sub_8050F90: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x3C - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - str r3, [sp, 0xC] - movs r0, 0 - str r0, [sp, 0x10] - movs r1, 0 - str r1, [sp, 0x14] - movs r2, 0 - b _080511D0 -_08050FB0: - movs r4, 0 - str r4, [sp, 0x18] - ldr r5, [sp, 0x1C] - adds r5, 0x1 - str r5, [sp, 0x28] - ldr r6, [sp, 0x4] - cmp r4, r6 - blt _08050FC2 - b _080511CE -_08050FC2: - ldr r1, [sp, 0x18] - lsls r0, r1, 2 - ldr r2, [sp, 0xC] - adds r0, r2 - ldr r3, [r0] - adds r4, r3, 0x2 - mov r9, r4 - ldr r5, [sp, 0x1C] - lsls r1, r5, 2 - ldr r6, [sp, 0x5C] - adds r1, r6 - ldr r2, [r1] - adds r4, r2, 0x2 - mov r10, r4 - ldr r0, [r0, 0x4] - subs r0, r3 - subs r4, r0, 0x4 - ldr r0, [r1, 0x4] - subs r0, r2 - subs r7, r0, 0x4 - movs r3, 0x5 - movs r5, 0x5 - ldr r6, [sp, 0x4] - cmp r6, 0x2 - bgt _08050FF8 - movs r3, 0xA - movs r4, 0xE -_08050FF8: - ldr r0, [sp, 0x8] - cmp r0, 0x1 - bne _08051002 - movs r5, 0x10 - movs r7, 0x18 -_08051002: - ldr r2, [sp, 0x1C] - lsls r1, r2, 5 - ldr r6, [sp, 0x18] - lsls r2, r6, 4 - subs r0, r2, r6 - lsls r0, 5 - ldr r6, [sp] - adds r0, r6 - adds r6, r1, r0 - ldrb r0, [r6, 0xA] - str r1, [sp, 0x30] - str r2, [sp, 0x2C] - cmp r0, 0 - bne _08051020 - b _08051130 -_08051020: - ldr r0, [sp, 0x14] - ldr r1, [sp, 0x60] - cmp r0, r1 - beq _0805108C - adds r0, r3, 0 - adds r1, r4, 0 - bl DungeonRandRange - adds r6, r0, 0 - adds r0, r5, 0 - adds r1, r7, 0 - bl DungeonRandRange - adds r5, r0, 0 - movs r1, 0x1 - adds r0, r6, 0 - orrs r0, r1 - cmp r0, r4 - bge _08051048 - adds r6, r0, 0 -_08051048: - adds r0, r5, 0 - orrs r0, r1 - cmp r0, r7 - bge _08051052 - adds r5, r0, 0 -_08051052: - lsls r0, r5, 1 - adds r0, r5 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - cmp r6, r0 - ble _08051062 - adds r6, r0, 0 -_08051062: - lsls r0, r6, 1 - adds r0, r6 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - cmp r5, r0 - ble _08051072 - adds r5, r0, 0 -_08051072: - subs r0, r4, r6 - bl DungeonRandInt - mov r2, r9 - adds r4, r0, r2 - subs r0, r7, r5 - bl DungeonRandInt - mov r3, r10 - adds r7, r0, r3 - adds r3, r4, r6 - adds r6, r7, r5 - b _08051098 -_0805108C: - mov r4, r9 - mov r7, r10 - ldr r5, [sp, 0x64] - adds r3, r4, r5 - ldr r0, [sp, 0x68] - adds r6, r7, r0 -_08051098: - ldr r1, [sp, 0x2C] - ldr r2, [sp, 0x18] - subs r0, r1, r2 - lsls r0, 5 - ldr r5, [sp] - adds r0, r5 - ldr r1, [sp, 0x30] - adds r0, r1, r0 - strh r4, [r0] - strh r3, [r0, 0x4] - strh r7, [r0, 0x2] - strh r6, [r0, 0x6] - adds r5, r4, 0 - ldr r2, [sp, 0x10] - adds r2, 0x1 - str r2, [sp, 0x20] - ldr r4, [sp, 0x14] - adds r4, 0x1 - str r4, [sp, 0x24] - ldr r0, [sp, 0x18] - adds r0, 0x1 - mov r10, r0 - cmp r5, r3 - bge _08051108 -_080510C8: - adds r4, r7, 0 - adds r1, r5, 0x1 - mov r8, r1 - cmp r4, r6 - bge _08051102 - ldr r2, _0805112C - mov r9, r2 -_080510D6: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x38] - bl GetTileSafe - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - mov r1, sp - ldrb r1, [r1, 0x10] - strb r1, [r0, 0x9] - adds r4, 0x1 - ldr r3, [sp, 0x38] - cmp r4, r6 - blt _080510D6 -_08051102: - mov r5, r8 - cmp r5, r3 - blt _080510C8 -_08051108: - ldr r2, [sp, 0x14] - ldr r3, [sp, 0x60] - cmp r2, r3 - beq _08051124 - ldr r4, [sp, 0x2C] - ldr r5, [sp, 0x18] - subs r0, r4, r5 - lsls r0, 5 - ldr r6, [sp] - adds r0, r6 - ldr r1, [sp, 0x30] - adds r0, r1, r0 - movs r1, 0x1 - strb r1, [r0, 0x1D] -_08051124: - ldr r2, [sp, 0x20] - str r2, [sp, 0x10] - b _080511BE - .align 2, 0 -_0805112C: .4byte 0x0000fffc -_08051130: - movs r1, 0x2 - movs r3, 0x4 - movs r2, 0x2 - mov r8, r3 - ldr r5, [sp, 0x18] - cmp r5, 0 - bne _08051140 - movs r1, 0x1 -_08051140: - ldr r0, [sp, 0x1C] - cmp r0, 0 - bne _08051148 - movs r2, 0x1 -_08051148: - ldr r0, [sp, 0x4] - subs r0, 0x1 - ldr r5, [sp, 0x18] - cmp r5, r0 - bne _08051154 - movs r3, 0x2 -_08051154: - ldr r0, [sp, 0x8] - subs r0, 0x1 - ldr r5, [sp, 0x1C] - cmp r5, r0 - bne _08051162 - movs r0, 0x2 - mov r8, r0 -_08051162: - mov r5, r9 - adds r0, r5, r1 - adds r1, r5, r4 - subs r1, r3 - str r2, [sp, 0x34] - bl DungeonRandRange - adds r5, r0, 0 - ldr r2, [sp, 0x34] - mov r1, r10 - adds r0, r1, r2 - adds r1, r7 - mov r2, r8 - subs r1, r2 - bl DungeonRandRange - adds r4, r0, 0 - strh r5, [r6] - adds r0, r5, 0x1 - strh r0, [r6, 0x4] - strh r4, [r6, 0x2] - adds r0, r4, 0x1 - strh r0, [r6, 0x6] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - ldrh r1, [r0] - ldr r3, _080511EC - adds r2, r3, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileSafe - movs r1, 0xFF - strb r1, [r0, 0x9] - ldr r4, [sp, 0x14] - adds r4, 0x1 - str r4, [sp, 0x24] - ldr r5, [sp, 0x18] - adds r5, 0x1 - mov r10, r5 -_080511BE: - ldr r6, [sp, 0x24] - str r6, [sp, 0x14] - mov r0, r10 - str r0, [sp, 0x18] - ldr r1, [sp, 0x4] - cmp r0, r1 - bge _080511CE - b _08050FC2 -_080511CE: - ldr r2, [sp, 0x28] -_080511D0: - str r2, [sp, 0x1C] - ldr r3, [sp, 0x8] - cmp r2, r3 - bge _080511DA - b _08050FB0 -_080511DA: - add sp, 0x3C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080511EC: .4byte 0x0000fffc - thumb_func_end sub_8050F90 - - thumb_func_start sub_80511F0 -sub_80511F0: - push {r4-r6,lr} - ldr r6, _08051204 - ldrb r0, [r6] - cmp r0, 0 - beq _0805120C - subs r0, 0x1 - strb r0, [r6] - ldr r0, _08051208 - ldrb r0, [r0] - b _08051244 - .align 2, 0 -_08051204: .4byte gUnknown_202F1E1 -_08051208: .4byte gUnknown_202F1E0 -_0805120C: - ldr r1, _0805122C - ldr r5, _08051230 - ldr r2, [r5] - ldrb r3, [r2] - strb r3, [r1] - adds r4, r2, 0x1 - str r4, [r5] - lsls r0, r3, 24 - lsrs r0, 24 - cmp r0, 0xE - bne _08051234 - ldrb r0, [r2, 0x1] - strb r0, [r1] - adds r0, r4, 0x1 - str r0, [r5] - b _08051242 - .align 2, 0 -_0805122C: .4byte gUnknown_202F1E0 -_08051230: .4byte gUnknown_202F1DC -_08051234: - movs r0, 0xF - ands r0, r3 - strb r0, [r6] - movs r0, 0xF0 - ands r0, r3 - lsrs r0, 4 - strb r0, [r1] -_08051242: - ldrb r0, [r1] -_08051244: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_80511F0 - - thumb_func_start sub_805124C -sub_805124C: - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - ldr r5, [sp, 0x1C] - lsls r1, 24 - lsrs r1, 24 - lsls r5, 24 - lsrs r5, 24 - ldrh r6, [r0] - movs r7, 0x80 - lsls r7, 1 - adds r4, r7, 0 - movs r7, 0 - mov r8, r7 - orrs r4, r6 - strh r4, [r0] - mov r4, r8 - strb r4, [r0, 0xE] - str r5, [sp] - bl sub_8051A74 - lsls r0, 24 - lsrs r0, 24 - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_805124C thumb_func_start sub_8051288 sub_8051288: diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index f6b6d769d..58968d4af 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -356,7 +356,7 @@ typedef struct Dungeon /* 0x3A0E */ s16 tileset; /* 0x3A10 */ s16 unk3A10; /* 0x3A12 */ s16 unk3A12; - /* 0x3A14 */ s16 bossBattleIndex; + /* 0x3A14 */ s16 fixedRoomId; /* 0x3A16 */ s16 unk3A16; /* 0x3A18 */ Tile tiles[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X]; /* 0xEA18 */ Position playerSpawn; diff --git a/src/code_8042B34.c b/src/code_8042B34.c index 57e7f649e..2b29e04c3 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -610,7 +610,7 @@ void xxx_dungeon_8042F6C(struct UnkStruct_xxx_dungeon_8042F6C *r8) gDungeon->weather.weather = 0; gDungeon->tileset = gDungeon->unk1C574.unk2; gDungeon->unk3A10 = gDungeon->unk1C574.unk3; - gDungeon->bossBattleIndex = gDungeon->unk1C574.unk12; + gDungeon->fixedRoomId = gDungeon->unk1C574.unk12; sub_807E5E4(0); sub_80842F0(); } diff --git a/src/code_806FDF4.c b/src/code_806FDF4.c index 2e45d797e..bdd66dc2d 100644 --- a/src/code_806FDF4.c +++ b/src/code_806FDF4.c @@ -196,13 +196,13 @@ bool8 sub_806F660(Entity *pokemon,Entity *target) targetInfo = target->info; iVar8 = -1; size = GetBodySize(targetInfo->apparentID); - if ((1 < ((u16)(gDungeon->bossBattleIndex - 4))) && (gDungeon->bossBattleIndex != 9) && (gDungeon->bossBattleIndex != 0xf)) { - if ((u16)(gDungeon->bossBattleIndex - 0x2cU) < 5) { + if ((1 < ((u16)(gDungeon->fixedRoomId - 4))) && (gDungeon->fixedRoomId != 9) && (gDungeon->fixedRoomId != 0xf)) { + if ((u16)(gDungeon->fixedRoomId - 0x2cU) < 5) { if (gDungeon->unk65C == 0) { return FALSE; } } - else if (gDungeon->bossBattleIndex == 0x31) { + else if (gDungeon->fixedRoomId == 0x31) { if (gDungeon->fill655[4] == 0) { return FALSE; } diff --git a/src/code_80848F0.c b/src/code_80848F0.c index 7499d8597..209ea9f5e 100644 --- a/src/code_80848F0.c +++ b/src/code_80848F0.c @@ -20,18 +20,18 @@ void sub_8084854(struct unkData_8107234 *); void sub_80847D4(void) { - u32 bossBattleIndex; + u32 fixedRoomId; s32 index; gDungeon->unk3A0D = 0; gDungeon->unk1356C = 0; sub_8040A84(); for(index = 0; index < 0x3e7 && gUnknown_8107234[index].unk0[0] != 0; index++) { - bossBattleIndex = gDungeon->bossBattleIndex; - if (bossBattleIndex - 0x1c < 0x16) { - bossBattleIndex = 0x1b; + fixedRoomId = gDungeon->fixedRoomId; + if (fixedRoomId - 0x1c < 0x16) { + fixedRoomId = 0x1b; } - if (bossBattleIndex == gUnknown_8107234[index].unk0[0]) + if (fixedRoomId == gUnknown_8107234[index].unk0[0]) { sub_8084854(&gUnknown_8107234[index]); break; diff --git a/src/dungeon_engine.c b/src/dungeon_engine.c index 572789b5d..ba647f1f6 100644 --- a/src/dungeon_engine.c +++ b/src/dungeon_engine.c @@ -34,7 +34,7 @@ static bool8 xxx_dungeon_80442D0(bool8); bool8 IsBossFight() { - if (gDungeon->bossBattleIndex != 0 && gDungeon->bossBattleIndex <= 0x31) + if (gDungeon->fixedRoomId != 0 && gDungeon->fixedRoomId <= 0x31) { return TRUE; } diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 38141c2c9..c97dd7555 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -66,10 +66,10 @@ struct GridCell #define GRID_CELL_LEN 15 -void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr); -void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 x2, s32 y2); -void sub_8051438(struct GridCell *gridCell, s32 a1); -extern void sub_8051288(s32 a0); +static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr); +static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 fixedRoomSizeX, s32 fixedRoomSizeY); +void sub_8051438(struct GridCell *gridCell, s32 fixedRoomId); +void sub_8051288(s32 fixedRoomId); void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); @@ -94,7 +94,7 @@ void sub_804FC74(void); void sub_804EB30(void); void sub_804E9DC(void); void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); -bool8 sub_804C70C(s32, UnkDungeonGlobal_unk1C574 *); +bool8 GenerateFixedFloor(s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr); void GenerateStandardFloor(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *a0); @@ -210,8 +210,9 @@ void sub_804AFAC(void) gDungeon->playerSpawn.x = -1; gDungeon->playerSpawn.y = -1; gDungeon->forceMonsterHouse = 0; - if (gDungeon->bossBattleIndex != 0) { - if (sub_804C70C(gDungeon->bossBattleIndex, unkPtr)) { + if (gDungeon->fixedRoomId != 0) { + // Check for a full-floor fixed room, if this is the case, generation is done. + if (GenerateFixedFloor(gDungeon->fixedRoomId, unkPtr)) { break; } } @@ -545,7 +546,7 @@ void NAKED sub_804AFAC(void) " cmp r0, 0\n" " beq _0804B164\n" " mov r1, r8\n" -" bl sub_804C70C\n" +" bl GenerateFixedFloor\n" " lsls r0, 24\n" " cmp r0, 0\n" " beq _0804B0E4\n" @@ -1644,34 +1645,34 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } -bool8 sub_804C70C(s32 a0, UnkDungeonGlobal_unk1C574 *unkPtr) +bool8 GenerateFixedFloor(s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr) { struct PositionU8 **fileData = (void *) gDungeon->unk13568->data; - s32 x1 = fileData[a0]->x; - s32 y1 = fileData[a0]->y; + s32 fixedRoomSizeX = fileData[fixedRoomId]->x; + s32 fixedRoomSizeY = fileData[fixedRoomId]->y; s32 gridSizeX, gridSizeY; - if (x1 == 0 || y1 == 0) { + if (fixedRoomSizeX == 0 || fixedRoomSizeY == 0) { GenerateOneRoomMonsterHouseFloor(); return FALSE; } - else if (a0 < 50) { - sub_8051288(a0); + else if (fixedRoomId < 50) { + sub_8051288(fixedRoomId); return TRUE; } else { - gridSizeX = DUNGEON_MAX_SIZE_X / (x1 + 4); + gridSizeX = DUNGEON_MAX_SIZE_X / (fixedRoomSizeX + 4); if (gridSizeX <= 1) gridSizeX = 1; - gridSizeY = DUNGEON_MAX_SIZE_Y / (y1 + 4); + gridSizeY = DUNGEON_MAX_SIZE_Y / (fixedRoomSizeY + 4); if (gridSizeY <= 1) gridSizeY = 1; - sub_804C790(gridSizeX, gridSizeY, x1, y1, a0, unkPtr); + sub_804C790(gridSizeX, gridSizeY, fixedRoomSizeX, fixedRoomSizeY, fixedRoomId, unkPtr); return FALSE; } } -void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeonGlobal_unk1C574 *unkPtr) +static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr) { s32 tries; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; @@ -1696,13 +1697,13 @@ void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 x2, s32 y2, s32 a4, UnkDungeo if (grid[cursorX][cursorY].isRoom) break; } - sub_8050F90(grid, gridSizeX, gridSizeY, listX, listY, r10, x2, y2); + CreateRoomsAndAnchorsForFixedFloor(grid, gridSizeX, gridSizeY, listX, listY, r10, fixedRoomSizeX, fixedRoomSizeY); if (gridSizeX != 1 || gridSizeY != 1) { AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, unkPtr); CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); } - sub_8051438(&grid[cursorX][cursorY], a4); + sub_8051438(&grid[cursorX][cursorY], fixedRoomId); } /* @@ -6264,10 +6265,167 @@ bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) return TRUE; } -/* -void sub_8050F90(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 x2, s32 y2) +static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 fixedRoomSizeX, s32 fixedRoomSizeY) { + s32 roomNumber = 0; + s32 var_48 = 0; + s32 x, y; + for (y = 0; y < gridSizeY; y++) { + for (x = 0; x < gridSizeX; var_48++, x++) { + s32 minX = listX[x] + 2; + s32 minY = listY[y] + 2; + s32 rangeX = listX[x + 1] - listX[x] - 4; + s32 rangeY = listY[y + 1] - listY[y] - 4; + s32 minRoomSizeX = 5; + s32 minRoomSizeY = 5; + + if (gridSizeX <= 2) { + minRoomSizeX = 10; + rangeX = 14; + } + if (gridSizeY == 1) { + minRoomSizeY = 16; + rangeY = 24; + } + + if (grid[x][y].isRoom) { + // This cell is a room! + s32 roomSizeX, roomSizeY; + s32 startX, endX; + s32 startY, endY; + s32 roomX, roomY; + + if (var_48 != a5) { + roomSizeX = DungeonRandRange(minRoomSizeX, rangeX); + roomSizeY = DungeonRandRange(minRoomSizeY, rangeY); + + // Force small rooms to have odd-numbered dimensions (?) + if ((roomSizeX | 1) < rangeX) { + roomSizeX |= 1; + } + + if ((roomSizeY | 1) < rangeY) { + roomSizeY |= 1; + } + + // Aspect ratio 2/3 < x/y < 3/2 + if (roomSizeX > (roomSizeY * 3) / 2) { + roomSizeX = (roomSizeY * 3) / 2; + } + + if (roomSizeY > (roomSizeX * 3) / 2) { + roomSizeY = (roomSizeX * 3) / 2; + } + + startX = DungeonRandInt(rangeX - roomSizeX) + minX; + startY = DungeonRandInt(rangeY - roomSizeY) + minY; + endX = startX + roomSizeX; + endY = startY + roomSizeY; + } + else { + startX = minX; + startY = minY; + endX = startX + fixedRoomSizeX; + endY = startY + fixedRoomSizeY; + } + + // Create the room! + grid[x][y].start.x = startX; + grid[x][y].end.x = endX; + grid[x][y].start.y = startY; + grid[x][y].end.y = endY; + + for (roomX = startX; roomX < endX; roomX++) { + for (roomY = startY; roomY < endY; roomY++) { + SetTerrainNormal(GetTileSafe(roomX, roomY)); + GetTileSafe(roomX, roomY)->room = roomNumber; + } + } + + if (var_48 != a5) { + grid[x][y].flagSecondaryStructure = TRUE; + } + + roomNumber++; + } + else { + // This cell is not a room, create a 1x1 hallway anchor + s32 pt_x, pt_y; + s32 unk_x1 = 2; + s32 unk_x2 = 4; + s32 unk_y1 = 2; + s32 unk_y2 = 4; + + if (x == 0) { + unk_x1 = 1; + } + if (y == 0) { + unk_y1 = 1; + } + + if (x == gridSizeX - 1) { + unk_x2 = 2; + } + if (y == gridSizeY - 1) { + unk_y2 = 2; + } + + pt_x = DungeonRandRange(minX + unk_x1, minX + rangeX - unk_x2); + pt_y = DungeonRandRange(minY + unk_y1, minY + rangeY - unk_y2); + + grid[x][y].start.x = pt_x; + grid[x][y].end.x = pt_x + 1; + grid[x][y].start.y = pt_y; + grid[x][y].end.y = pt_y + 1; + + // Flag the tile as open to serve as a hallway anchor + SetTerrainNormal(GetTileSafe(pt_x, pt_y)); + + // Set the room index to 0xFE for anchor + GetTileSafe(pt_x, pt_y)->room = CORRIDOR_ROOM; + } + } + } +} + +extern u8 *gUnknown_202F1DC; +extern u8 gUnknown_202F1E0; +extern u8 gUnknown_202F1E1; + +u8 sub_80511F0(void) +{ + if (gUnknown_202F1E1 != 0) { + gUnknown_202F1E1--; + return gUnknown_202F1E0; + } + + gUnknown_202F1E0 = *gUnknown_202F1DC; + gUnknown_202F1DC++; + if (gUnknown_202F1E0 == 14) { + gUnknown_202F1E0 = *gUnknown_202F1DC; + gUnknown_202F1DC++; + } + else { + gUnknown_202F1E1 = gUnknown_202F1E0 & 0xF; + gUnknown_202F1E0 = (gUnknown_202F1E0 & 0xF0) >> 4; + } + return gUnknown_202F1E0; +} + +bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5); + +bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) +{ + tile->terrainType |= TERRAIN_TYPE_UNBREAKABLE; + tile->unkE = 0; + return sub_8051A74(tile, a1, x, y, a5); +} + +/* +void sub_8051288(s32 fixedRoomId) +{ + Dungeon *dungeon = gDungeon; } */ diff --git a/src/trap_1.c b/src/trap_1.c index 44b6b78bb..c24259b93 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -492,7 +492,7 @@ void sub_8081454(unkStruct_8094924 *param_1) sub_8083048(param_1, gDungeon->tileset); sub_8083048(param_1,gDungeon->unk3A10); sub_8083048(param_1, gDungeon->unk3A12); - sub_8083048(param_1, gDungeon->bossBattleIndex); + sub_8083048(param_1, gDungeon->fixedRoomId); sub_8083048(param_1, gDungeon->unk3A16); for(iVar1 = 0; iVar1 < DUNGEON_MAX_SIZE_Y; iVar1++) { @@ -829,7 +829,7 @@ void sub_8081C7C(unkStruct_8094924 *r0) gDungeon->tileset = sub_8083170(r0); gDungeon->unk3A10 = sub_8083170(r0); gDungeon->unk3A12 = sub_8083170(r0); - gDungeon->bossBattleIndex = sub_8083170(r0); + gDungeon->fixedRoomId = sub_8083170(r0); gDungeon->unk3A16 = sub_8083170(r0); for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) From 5fcb028d8198acf40bfafdc6e5f260e826409e20 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 18 Nov 2024 09:27:57 +0100 Subject: [PATCH 21/30] some unknown, maybe fixed floors dung generation --- asm/code_804FD30.s | 219 ---------------------------------- include/structs/str_dungeon.h | 2 +- src/dungeon_generation.c | 54 ++++++++- src/trap_1.c | 2 +- 4 files changed, 54 insertions(+), 223 deletions(-) diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index d4e137903..363ae5d28 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -6,225 +6,6 @@ .text - thumb_func_start sub_8051288 -sub_8051288: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - str r0, [sp, 0x4] - ldr r0, _08051374 - ldr r7, [r0] - ldr r0, _08051378 - adds r3, r7, r0 - ldr r0, [r3] - ldr r0, [r0, 0x4] - ldr r2, [sp, 0x4] - lsls r1, r2, 2 - adds r0, r1, r0 - ldr r0, [r0] - ldrb r2, [r0] - mov r10, r2 - ldrb r0, [r0, 0x1] - mov r9, r0 - ldr r2, _0805137C - adds r0, r7, r2 - movs r4, 0 - mov r2, r10 - strh r2, [r0] - ldr r2, _08051380 - adds r0, r7, r2 - mov r2, r9 - strh r2, [r0] - ldr r2, _08051384 - ldr r0, [r3] - ldr r0, [r0, 0x4] - adds r1, r0 - ldr r0, [r1] - adds r0, 0x3 - str r0, [r2] - ldr r0, _08051388 - strb r4, [r0] - movs r6, 0x5 - mov r0, r9 - adds r0, 0x5 - cmp r6, r0 - bge _0805132E - movs r1, 0x5 - add r1, r10 - mov r8, r1 - str r0, [sp, 0x8] -_080512E8: - movs r5, 0x5 - cmp r5, r8 - bge _08051326 -_080512EE: - bl sub_80511F0 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileSafe - movs r1, 0x1 - str r1, [sp] - adds r1, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl sub_805124C - lsls r0, 24 - cmp r0, 0 - beq _08051320 - ldr r2, _0805138C - adds r0, r7, r2 - strh r5, [r0] - ldr r1, _08051390 - adds r0, r7, r1 - strh r6, [r0] -_08051320: - adds r5, 0x1 - cmp r5, r8 - blt _080512EE -_08051326: - adds r6, 0x1 - ldr r2, [sp, 0x8] - cmp r6, r2 - blt _080512E8 -_0805132E: - movs r6, 0 - ldr r0, _08051394 - adds r7, r0, 0 -_08051334: - movs r5, 0 - adds r4, r6, 0x1 -_08051338: - cmp r5, 0x4 - ble _08051350 - mov r0, r10 - adds r0, 0x5 - cmp r5, r0 - bge _08051350 - cmp r6, 0x4 - ble _08051350 - mov r0, r9 - adds r0, 0x5 - cmp r6, r0 - blt _080513A0 -_08051350: - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrh r1, [r2] - movs r0, 0x10 - movs r3, 0 - orrs r1, r0 - strh r1, [r2] - ldr r0, _08051398 - ldrb r0, [r0] - cmp r0, 0 - beq _0805139C - ands r1, r7 - movs r0, 0x3 - orrs r1, r0 - b _0805139E - .align 2, 0 -_08051374: .4byte gDungeon -_08051378: .4byte 0x00013568 -_0805137C: .4byte 0x0000e260 -_08051380: .4byte 0x0000e262 -_08051384: .4byte gUnknown_202F1DC -_08051388: .4byte gUnknown_202F1E1 -_0805138C: .4byte 0x0000e21c -_08051390: .4byte 0x0000e21e -_08051394: .4byte 0x0000fffc -_08051398: .4byte gUnknown_202F1A8 -_0805139C: - ands r1, r7 -_0805139E: - strh r1, [r2] -_080513A0: - adds r5, 0x1 - cmp r5, 0x37 - ble _08051338 - adds r6, r4, 0 - cmp r6, 0x1F - ble _08051334 - ldr r1, [sp, 0x4] - cmp r1, 0x4 - bne _080513DA - movs r6, 0x5 - ldr r2, _0805142C - adds r7, r2, 0 -_080513B8: - movs r5, 0x2 - adds r4, r6, 0x1 -_080513BC: - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileSafe - ldrh r2, [r0] - movs r1, 0x10 - orrs r1, r2 - ands r1, r7 - strh r1, [r0] - adds r5, 0x1 - cmp r5, 0x4 - ble _080513BC - adds r6, r4, 0 - cmp r6, 0x10 - ble _080513B8 -_080513DA: - ldr r0, _08051430 - ldr r0, [r0] - ldr r1, _08051434 - adds r0, r1 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, 0x3F - ble _08051416 - movs r6, 0 -_080513EC: - movs r5, 0 - adds r4, r6, 0x1 -_080513F0: - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileSafe - adds r2, r0, 0 - ldrh r1, [r2] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - bne _0805140A - movs r0, 0x10 - orrs r0, r1 - strh r0, [r2] -_0805140A: - adds r5, 0x1 - cmp r5, 0x37 - ble _080513F0 - adds r6, r4, 0 - cmp r6, 0x1F - ble _080513EC -_08051416: - bl sub_804E9DC - 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 -_0805142C: .4byte 0x0000fffc -_08051430: .4byte gDungeon -_08051434: .4byte 0x00003a0e - thumb_func_end sub_8051288 - thumb_func_start sub_8051438 sub_8051438: push {r4-r7,lr} diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 58968d4af..aa6a04abd 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -365,7 +365,7 @@ typedef struct Dungeon struct MinMaxPosition kecleonShopPos; u32 unkE250; u8 fillE254[0xE260 - 0xE254]; - u32 unkE260; + Position unkE260; /* 0xE264 */ Weather weather; // Uses the weather constants in weather.h. /* 0xE27C */ Tile unkE27C[8][8]; /* 0xE87C */ u8 unkE87C[8][8]; diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index c97dd7555..79eb6cde0 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -6422,11 +6422,61 @@ bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) return sub_8051A74(tile, a1, x, y, a5); } -/* void sub_8051288(s32 fixedRoomId) { + s32 x, y; Dungeon *dungeon = gDungeon; + struct PositionU8 **fileData = (void *) dungeon->unk13568->data; + s32 fixedRoomSizeX = fileData[fixedRoomId]->x; + s32 fixedRoomSizeY = fileData[fixedRoomId]->y; + + dungeon->unkE260.x = fixedRoomSizeX; + dungeon->unkE260.y = fixedRoomSizeY; + // FIX ME + gUnknown_202F1DC = ((u8 **)(dungeon->unk13568->data))[fixedRoomId] + 3; + gUnknown_202F1E1 = 0; + for (x = 5; x < fixedRoomSizeX + 5; x++) { + for (y = 5; y < fixedRoomSizeY + 5; y++) { + u8 unk = sub_80511F0(); + if (sub_805124C(GetTileSafe(x, y), unk, x, y, 1)) { + dungeon->unkE260.x = x; + dungeon->unkE260.y = y; + } + } + } + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (y > 4) + + Tile *tile = GetTileSafe(x, y); + if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + } + } + + if (fixedRoomId != 4) { + for (x = 0; x < 17; x++) { + for (y = 0; y < 5; y++) { + Tile *tile = GetTileSafe(x, y); + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + } + } + + if (gDungeon->tileset < 64) { + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + Tile *tile = GetTileSafe(x, y); + if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + } + } + } + + sub_804E9DC(); } -*/ // diff --git a/src/trap_1.c b/src/trap_1.c index c24259b93..aed00072f 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -18,7 +18,7 @@ extern void sub_8082FA8(unkStruct_8094924 *, void *, s32); void SaveTile(unkStruct_8094924 *r0, Tile *tile); void sub_80830F8(void * , void*); -void sub_808312C(void *, u32 *); +void sub_808312C(void *, void *); void SaveDungeonWeather(unkStruct_8094924 *r0, Weather *weather); void sub_8083078(void *, u32); void sub_80830B4(void *, u8); From ad8c36c679a60bf65d274d2cc7c3497ff6a89399 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 18 Nov 2024 11:22:12 +0100 Subject: [PATCH 22/30] sub_8051438 --- asm/code_804FD30.s | 270 ---------------------------------- include/structs/str_dungeon.h | 5 +- src/dungeon_generation.c | 144 +++++++++++++----- 3 files changed, 110 insertions(+), 309 deletions(-) diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index 363ae5d28..7b873c43e 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -5,276 +5,6 @@ .text - - thumb_func_start sub_8051438 -sub_8051438: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x1C - mov r9, r0 - ldr r0, _080515AC - ldr r0, [r0] - str r0, [sp, 0x4] - ldr r2, _080515B0 - ldr r4, _080515B4 - adds r3, r0, r4 - ldr r0, [r3] - ldr r0, [r0, 0x4] - lsls r1, 2 - adds r0, r1, r0 - ldr r0, [r0] - adds r0, 0x3 - str r0, [r2] - ldr r2, _080515B8 - movs r0, 0 - strb r0, [r2] - ldr r0, [r3] - ldr r0, [r0, 0x4] - adds r1, r0 - ldr r0, [r1] - ldrb r1, [r0, 0x2] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0805147A - b _080515D8 -_0805147A: - ldr r5, [sp, 0x4] - ldr r0, _080515BC - adds r1, r5, r0 - mov r2, r9 - movs r3, 0 - ldrsh r0, [r2, r3] - str r0, [r1] - ldr r4, _080515C0 - adds r1, r5, r4 - movs r5, 0x2 - ldrsh r0, [r2, r5] - str r0, [r1] - ldr r0, [sp, 0x4] - ldr r2, _080515C4 - adds r1, r0, r2 - mov r3, r9 - movs r4, 0x4 - ldrsh r0, [r3, r4] - str r0, [r1] - ldr r5, [sp, 0x4] - ldr r0, _080515C8 - adds r1, r5, r0 - movs r2, 0x6 - ldrsh r0, [r3, r2] - str r0, [r1] - movs r3, 0 - str r3, [sp, 0x8] - mov r4, r9 - movs r5, 0x2 - ldrsh r4, [r4, r5] - mov r8, r4 - mov r1, r9 - movs r2, 0x6 - ldrsh r0, [r1, r2] - cmp r8, r0 - blt _080514C4 - b _08051640 -_080514C4: - mov r3, r9 - movs r4, 0 - ldrsh r7, [r3, r4] - movs r5, 0x4 - ldrsh r0, [r3, r5] - ldr r1, [sp, 0x8] - adds r1, 0x1 - str r1, [sp, 0x10] - mov r2, r8 - adds r2, 0x1 - str r2, [sp, 0xC] - cmp r7, r0 - bge _08051598 - ldr r4, _080515CC - ldr r3, [sp, 0x4] - adds r4, r3, r4 - str r4, [sp, 0x14] - movs r5, 0 - str r5, [sp, 0x18] - ldr r0, [sp, 0x8] - mov r10, r0 -_080514EE: - bl sub_80511F0 - adds r5, r0, 0 - lsls r5, 24 - lsrs r5, 24 - adds r0, r7, 0 - mov r1, r8 - bl GetTileSafe - adds r6, r0, 0 - ldr r1, [sp, 0x4] - ldr r2, _080515D0 - adds r0, r1, r2 - add r0, r10 - strb r5, [r0] - ldr r3, [sp, 0x8] - lsls r4, r3, 1 - adds r4, r3 - lsls r4, 3 - ldr r1, [sp, 0x14] - adds r0, r1, r4 - movs r2, 0 - str r2, [sp] - adds r1, r5, 0 - adds r2, r7, 0 - mov r3, r8 - bl sub_805124C - ldrb r1, [r6, 0x9] - ldr r3, [sp, 0x18] - adds r4, r3 - ldr r5, [sp, 0x4] - adds r4, r5, r4 - adds r0, r6, 0 - ldr r2, _080515CC - adds r4, r2 - ldm r4!, {r2,r3,r5} - stm r0!, {r2,r3,r5} - ldm r4!, {r2,r3,r5} - stm r0!, {r2,r3,r5} - mov r3, r9 - movs r4, 0 - ldrsh r0, [r3, r4] - adds r0, 0x2 - cmp r7, r0 - blt _08051572 - movs r5, 0x4 - ldrsh r0, [r3, r5] - subs r0, 0x2 - cmp r7, r0 - bge _08051572 - movs r2, 0x2 - ldrsh r0, [r3, r2] - adds r0, 0x2 - cmp r8, r0 - blt _08051572 - movs r4, 0x6 - ldrsh r0, [r3, r4] - subs r0, 0x2 - cmp r8, r0 - bge _08051572 - movs r0, 0x88 - lsls r0, 1 - strh r0, [r6] - movs r0, 0xE - strb r0, [r6, 0xE] -_08051572: - strb r1, [r6, 0x9] - ldr r5, [sp, 0x4] - ldr r2, _080515D4 - adds r0, r5, r2 - strb r1, [r0] - ldr r3, [sp, 0x14] - adds r3, 0xC0 - str r3, [sp, 0x14] - ldr r4, [sp, 0x18] - adds r4, 0xC0 - str r4, [sp, 0x18] - movs r5, 0x8 - add r10, r5 - adds r7, 0x1 - mov r1, r9 - movs r2, 0x4 - ldrsh r0, [r1, r2] - cmp r7, r0 - blt _080514EE -_08051598: - ldr r3, [sp, 0x10] - str r3, [sp, 0x8] - ldr r4, [sp, 0xC] - mov r8, r4 - mov r5, r9 - movs r1, 0x6 - ldrsh r0, [r5, r1] - cmp r8, r0 - blt _080514C4 - b _08051640 - .align 2, 0 -_080515AC: .4byte gDungeon -_080515B0: .4byte gUnknown_202F1DC -_080515B4: .4byte 0x00013568 -_080515B8: .4byte gUnknown_202F1E1 -_080515BC: .4byte 0x0000e250 -_080515C0: .4byte 0x0000e254 -_080515C4: .4byte 0x0000e258 -_080515C8: .4byte 0x0000e25c -_080515CC: .4byte 0x0000e27c -_080515D0: .4byte 0x0000e87c -_080515D4: .4byte 0x0000e8bc -_080515D8: - mov r2, r9 - movs r3, 0x2 - ldrsh r2, [r2, r3] - mov r8, r2 - b _08051636 -_080515E2: - mov r0, r9 - movs r1, 0 - ldrsh r7, [r0, r1] - movs r2, 0x4 - ldrsh r0, [r0, r2] - mov r3, r8 - adds r3, 0x1 - str r3, [sp, 0xC] - cmp r7, r0 - bge _08051632 -_080515F6: - bl sub_80511F0 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r7, 0 - mov r1, r8 - bl GetTileSafe - adds r5, r0, 0 - ldrb r6, [r5, 0x9] - movs r0, 0x1 - str r0, [sp] - adds r0, r5, 0 - adds r1, r4, 0 - adds r2, r7, 0 - mov r3, r8 - bl sub_805124C - strb r6, [r5, 0x9] - ldr r4, [sp, 0x4] - ldr r5, _08051650 - adds r0, r4, r5 - strb r6, [r0] - adds r7, 0x1 - mov r1, r9 - movs r2, 0x4 - ldrsh r0, [r1, r2] - cmp r7, r0 - blt _080515F6 -_08051632: - ldr r3, [sp, 0xC] - mov r8, r3 -_08051636: - mov r4, r9 - movs r5, 0x6 - ldrsh r0, [r4, r5] - cmp r8, r0 - blt _080515E2 -_08051640: - add sp, 0x1C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08051650: .4byte 0x0000e8bc - thumb_func_end sub_8051438 - thumb_func_start sub_8051654 sub_8051654: push {r4-r7,lr} diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index aa6a04abd..fa152029a 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -363,13 +363,12 @@ typedef struct Dungeon Position stairsSpawn; // stairs location Position unkE220[8]; struct MinMaxPosition kecleonShopPos; - u32 unkE250; - u8 fillE254[0xE260 - 0xE254]; + struct MinMaxPosition unkE250; Position unkE260; /* 0xE264 */ Weather weather; // Uses the weather constants in weather.h. /* 0xE27C */ Tile unkE27C[8][8]; /* 0xE87C */ u8 unkE87C[8][8]; - u32 fillE8BC; + /* 0xE8BC */ u8 unkE8BC; // Seems to be some tile's room index; /* 0xE8C0 */ Tile *tilePointers[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X]; u8 unk104C0; /* 0x104C4 */ RoomData roomData[MAX_ROOM_COUNT]; diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 79eb6cde0..0f7c1ed2e 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -102,7 +102,7 @@ void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0); void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr); -void sub_8051654(UnkDungeonGlobal_unk1C574 *a0); +void sub_8051654(UnkDungeonGlobal_unk1C574 *unkPtr); void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr); void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); @@ -125,12 +125,6 @@ EWRAM_DATA s32 gUnknown_202F1D0 = 0; static EWRAM_DATA s32 sNumTilesReachableFromStairs = 0; static EWRAM_DATA Position sKecleonShopMiddlePos = {0}; -struct PositionU8 -{ - u8 x; - u8 y; -}; - // Helper functions for terrain flags static inline void SetTerrainType(Tile *tile, u32 terrainType) { @@ -158,6 +152,14 @@ static inline u32 GetTerrainType(Tile *tile) return tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); } +struct FixedRoomsData +{ + u8 x; + u8 y; + u8 unk2; + u8 unk3[0]; // Not sure about the size; +}; + // Some weird-ass regswap prevents the function from being matched - https://decomp.me/scratch/9SUV3 #ifdef NONMATCHING void sub_804AFAC(void) @@ -1647,9 +1649,8 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un bool8 GenerateFixedFloor(s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr) { - struct PositionU8 **fileData = (void *) gDungeon->unk13568->data; - s32 fixedRoomSizeX = fileData[fixedRoomId]->x; - s32 fixedRoomSizeY = fileData[fixedRoomId]->y; + s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->x; + s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->y; s32 gridSizeX, gridSizeY; if (fixedRoomSizeX == 0 || fixedRoomSizeY == 0) { @@ -4577,6 +4578,12 @@ void ResetFloor(void) } } +struct PositionU8 +{ + u8 x; + u8 y; +}; + /* * ShuffleSpawnPositions - Randomly shuffle an array of spawn positions */ @@ -6426,48 +6433,52 @@ void sub_8051288(s32 fixedRoomId) { s32 x, y; Dungeon *dungeon = gDungeon; - struct PositionU8 **fileData = (void *) dungeon->unk13568->data; - s32 fixedRoomSizeX = fileData[fixedRoomId]->x; - s32 fixedRoomSizeY = fileData[fixedRoomId]->y; + s32 fixedRoomSizeX = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->x; + s32 fixedRoomSizeY = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->y; dungeon->unkE260.x = fixedRoomSizeX; dungeon->unkE260.y = fixedRoomSizeY; - // FIX ME - gUnknown_202F1DC = ((u8 **)(dungeon->unk13568->data))[fixedRoomId] + 3; + gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk3; gUnknown_202F1E1 = 0; - for (x = 5; x < fixedRoomSizeX + 5; x++) { - for (y = 5; y < fixedRoomSizeY + 5; y++) { + + for (y = 5; y < fixedRoomSizeY + 5; y++) { + for (x = 5; x < fixedRoomSizeX + 5; x++) { u8 unk = sub_80511F0(); if (sub_805124C(GetTileSafe(x, y), unk, x, y, 1)) { - dungeon->unkE260.x = x; - dungeon->unkE260.y = y; + dungeon->stairsSpawn.x = x; + dungeon->stairsSpawn.y = y; } } } - for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { - for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - if (y > 4) - - Tile *tile = GetTileSafe(x, y); - if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { - tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; - } - } - } - - if (fixedRoomId != 4) { - for (x = 0; x < 17; x++) { - for (y = 0; y < 5; y++) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + if (x <= 4 || x >= fixedRoomSizeX + 5 || y <= 4 || y >= fixedRoomSizeY + 5) { Tile *tile = GetTileSafe(x, y); tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + if (gUnknown_202F1A8 != 0) { + SetTerrainType(tile, TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + } + else { + SetTerrainWall(tile); + } } } } - if (gDungeon->tileset < 64) { - for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { - for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (fixedRoomId == 4) { + for (y = 5; y < 17; y++) { + for (x = 2; x < 5; x++) { + Tile *tile = GetTileSafe(x, y); + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + SetTerrainWall(tile); + } + } + } + + if (gDungeon->tileset >= 64) { + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { Tile *tile = GetTileSafe(x, y); if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; @@ -6479,4 +6490,65 @@ void sub_8051288(s32 fixedRoomId) sub_804E9DC(); } +void sub_8051438(struct GridCell *gridCell, s32 fixedRoomId) +{ + s32 x, y; + Dungeon *dungeon = gDungeon; + + gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk3; + gUnknown_202F1E1 = 0; + + if (((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk2 & 1) { + s32 yIndex; + + dungeon->unkE250.minX = gridCell->start.x; + dungeon->unkE250.minY = gridCell->start.y; + dungeon->unkE250.maxX = gridCell->end.x; + dungeon->unkE250.maxY = gridCell->end.y; + + yIndex = 0; + for (y = gridCell->start.y; y < gridCell->end.y; y++) { + s32 xIndex = 0; + for (x = gridCell->start.x; x < gridCell->end.x; x++) { + u8 roomId; + u8 unk = sub_80511F0(); + Tile *tile = GetTileSafe(x, y); + + dungeon->unkE87C[xIndex][yIndex] = unk; + sub_805124C(&dungeon->unkE27C[xIndex][yIndex], unk, x, y, 0); + roomId = tile->room; + *tile = dungeon->unkE27C[xIndex][yIndex]; + if (x >= gridCell->start.x + 2 && x < gridCell->end.x - 2 && y >= gridCell->start.y + 2 && y < gridCell->end.y - 2) { + tile->terrainType = TERRAIN_TYPE_IMPASSABLE_WALL | TERRAIN_TYPE_UNBREAKABLE; + tile->unkE = 0xE; + } + tile->room = roomId; + dungeon->unkE8BC = roomId; + xIndex++; + } + yIndex++; + } + } + else { + for (y = gridCell->start.y; y < gridCell->end.y; y++) { + for (x = gridCell->start.x; x < gridCell->end.x; x++) { + u8 unk = sub_80511F0(); + Tile *tile = GetTileSafe(x, y); + u8 roomId = tile->room; + + sub_805124C(tile, unk, x, y, 1); + tile->room = roomId; + dungeon->unkE8BC = roomId; + } + } + } +} + +/* +void sub_8051654(UnkDungeonGlobal_unk1C574 *unkPtr) +{ + +} +*/ + // From 378a00c510c41e1233c1766c9d9d50c61f41e037 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 18 Nov 2024 15:36:03 +0100 Subject: [PATCH 23/30] ResetInnerBoundaryTileRows --- asm/code_804AFAC.s | 9967 --------------------------------- asm/code_804FD30.s | 389 -- include/structs/str_dungeon.h | 7 +- src/code_803D110.c | 2 +- src/dungeon_generation.c | 308 +- sym_ewram.txt | 8 - 6 files changed, 219 insertions(+), 10462 deletions(-) delete mode 100644 asm/code_804AFAC.s diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s deleted file mode 100644 index 48d8e5dd8..000000000 --- a/asm/code_804AFAC.s +++ /dev/null @@ -1,9967 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start sub_804AFAC -sub_804AFAC: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x44 - movs r0, 0 - mov r10, r0 - ldr r4, _0804B0E8 - ldr r0, [r4] - ldr r1, _0804B0EC - adds r1, r0 - mov r8, r1 - ldr r0, _0804B0F0 - ldr r1, _0804B0F4 - bl OpenFileAndGetFileDataPtr - ldr r2, [r4] - ldr r3, _0804B0F8 - adds r1, r2, r3 - str r0, [r1] - ldr r0, _0804B0FC - mov r6, r10 - strb r6, [r0] - ldr r0, _0804B100 - strb r6, [r0] - ldr r0, _0804B104 - strb r6, [r0] - ldr r5, _0804B108 - movs r3, 0 - ldr r1, _0804B10C - ldr r0, _0804B110 - adds r2, r0 - movs r6, 0 - ldrsh r0, [r2, r6] - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0x2 - bne _0804AFFC - movs r3, 0x1 -_0804AFFC: - strb r3, [r5] - ldr r1, _0804B114 - movs r0, 0xFF - strb r0, [r1] - ldr r0, _0804B118 - mov r1, r10 - strb r1, [r0] - ldr r1, _0804B11C - mov r2, r8 - ldrb r0, [r2, 0x7] - strh r0, [r1] - ldr r1, _0804B120 - ldrb r0, [r2, 0x8] - strh r0, [r1] - ldr r1, _0804B124 - movs r0, 0x1 - strb r0, [r1] - ldr r1, _0804B128 - movs r0, 0x1 - negs r0, r0 - str r0, [r1] - str r0, [r1, 0x8] - str r0, [r1, 0x4] - str r0, [r1, 0xC] - bl sub_804FD30 - ldr r3, [r4] - mov r6, r8 - ldrb r2, [r6, 0x6] - ldr r1, _0804B12C - adds r0, r3, r1 - movs r1, 0 - strh r2, [r0] - ldr r2, _0804B130 - adds r0, r3, r2 - strb r1, [r0] - ldr r0, [r4] - ldr r3, _0804B134 - adds r0, r3 - strb r1, [r0] - ldr r1, _0804B138 - mov r6, r8 - ldrb r0, [r6, 0xC] - str r0, [r1] - movs r0, 0 - str r0, [sp, 0x40] -_0804B058: - ldr r0, _0804B0E8 - ldr r2, [r0] - ldr r3, _0804B13C - adds r1, r2, r3 - ldr r0, _0804B140 - strh r0, [r1] - ldr r6, _0804B144 - adds r1, r2, r6 - movs r0, 0x1 - negs r0, r0 - strh r0, [r1] - ldr r0, _0804B148 - adds r1, r2, r0 - movs r0, 0x1 - negs r0, r0 - strh r0, [r1] - ldr r1, _0804B14C - adds r2, r1 - strh r0, [r2] - movs r2, 0 - mov r9, r2 -_0804B082: - ldr r4, _0804B0E8 - ldr r0, [r4] - ldr r3, _0804B150 - adds r0, r3 - movs r5, 0 - movs r1, 0 - mov r6, r9 - strh r6, [r0] - mov r0, r9 - cmp r0, 0 - ble _0804B09C - ldr r0, _0804B138 - str r1, [r0] -_0804B09C: - ldr r0, _0804B154 - strb r5, [r0] - ldr r1, _0804B158 - ldr r0, _0804B140 - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - bl sub_804FD30 - ldr r1, [r4] - ldr r3, _0804B13C - adds r2, r1, r3 - movs r0, 0x1 - negs r0, r0 - strh r0, [r2] - ldr r6, _0804B144 - adds r2, r1, r6 - strh r0, [r2] - ldr r0, _0804B15C - adds r1, r0 - strb r5, [r1] - ldr r0, [r4] - ldr r2, _0804B160 - adds r1, r0, r2 - movs r3, 0 - ldrsh r0, [r1, r3] - cmp r0, 0 - beq _0804B164 - mov r1, r8 - bl sub_804C70C - lsls r0, 24 - cmp r0, 0 - beq _0804B0E4 - b _0804B376 -_0804B0E4: - b _0804B2F6 - .align 2, 0 -_0804B0E8: .4byte gDungeon -_0804B0EC: .4byte 0x0001c574 -_0804B0F0: .4byte gUnknown_80F6DCC -_0804B0F4: .4byte gDungeonFileArchive -_0804B0F8: .4byte 0x00013568 -_0804B0FC: .4byte gUnknown_202F1AA -_0804B100: .4byte gUnknown_202F1AB -_0804B104: .4byte gUnknown_202F1AC -_0804B108: .4byte gUnknown_202F1A8 -_0804B10C: .4byte gDungeonWaterType -_0804B110: .4byte 0x00003a0e -_0804B114: .4byte gUnknown_202F1B4 -_0804B118: .4byte gUnknown_202F1AE -_0804B11C: .4byte gUnknown_202F1B0 -_0804B120: .4byte gUnknown_202F1B2 -_0804B124: .4byte gUnknown_202F1AD -_0804B128: .4byte gUnknown_202F1B8 -_0804B12C: .4byte 0x00000664 -_0804B130: .4byte 0x00003a09 -_0804B134: .4byte 0x00003a0a -_0804B138: .4byte gUnknown_202F1C8 -_0804B13C: .4byte 0x0000e218 -_0804B140: .4byte 0x0000ffff -_0804B144: .4byte 0x0000e21a -_0804B148: .4byte 0x0000e21c -_0804B14C: .4byte 0x0000e21e -_0804B150: .4byte 0x00003a16 -_0804B154: .4byte gUnknown_202F1A9 -_0804B158: .4byte gUnknown_202F1D8 -_0804B15C: .4byte 0x00003a08 -_0804B160: .4byte 0x00003a14 -_0804B164: - mov r0, r8 - ldrb r7, [r0] - movs r6, 0x20 -_0804B16A: - cmp r7, 0x8 - beq _0804B17E - movs r0, 0x2 - movs r1, 0x9 - bl DungeonRandRange - adds r5, r0, 0 - movs r0, 0x2 - movs r1, 0x8 - b _0804B18C -_0804B17E: - movs r0, 0x2 - movs r1, 0x5 - bl DungeonRandRange - adds r5, r0, 0 - movs r0, 0x2 - movs r1, 0x4 -_0804B18C: - bl DungeonRandRange - adds r4, r0, 0 - cmp r5, 0x6 - bgt _0804B19A - cmp r4, 0x4 - ble _0804B1A4 -_0804B19A: - subs r6, 0x1 - cmp r6, 0 - bne _0804B16A - movs r5, 0x4 - movs r4, 0x4 -_0804B1A4: - movs r0, 0x38 - adds r1, r5, 0 - bl __divsi3 - cmp r0, 0x7 - bgt _0804B1B2 - movs r5, 0x1 -_0804B1B2: - movs r0, 0x20 - adds r1, r4, 0 - bl __divsi3 - cmp r0, 0x7 - bgt _0804B1C0 - movs r4, 0x1 -_0804B1C0: - ldr r2, _0804B1EC - ldr r0, [r2] - ldr r1, _0804B1F0 - adds r0, r1 - movs r1, 0 - strb r1, [r0] - ldr r0, [r2] - ldr r2, _0804B1F4 - adds r0, r2 - movs r1, 0xFF - strb r1, [r0] - ldr r0, _0804B1F8 - str r7, [r0] - movs r0, 0xF - ands r0, r7 - cmp r0, 0xB - bhi _0804B274 - lsls r0, 2 - ldr r1, _0804B1FC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_0804B1EC: .4byte gDungeon -_0804B1F0: .4byte 0x00003a08 -_0804B1F4: .4byte 0x00003a0c -_0804B1F8: .4byte gUnknown_202F1D0 -_0804B1FC: .4byte _0804B200 - .align 2, 0 -_0804B200: - .4byte _0804B274 - .4byte _0804B230 - .4byte _0804B280 - .4byte _0804B298 - .4byte _0804B2A4 - .4byte _0804B2B0 - .4byte _0804B2CC - .4byte _0804B2D8 - .4byte _0804B274 - .4byte _0804B2E0 - .4byte _0804B2E8 - .4byte _0804B250 -_0804B230: - movs r0, 0x2 - bl DungeonRandInt - adds r4, r0, 0x2 - ldr r1, _0804B24C - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x4 - adds r1, r4, 0 - mov r2, r8 - bl sub_804B634 - b _0804B2AA - .align 2, 0 -_0804B24C: .4byte gUnknown_202F1AE -_0804B250: - movs r0, 0x2 - bl DungeonRandInt - adds r4, r0, 0x2 - ldr r1, _0804B270 - movs r0, 0x2 - strb r0, [r1] - movs r0, 0x4 - adds r1, r4, 0 - mov r2, r8 - bl sub_804B634 - movs r6, 0x1 - mov r10, r6 - b _0804B2F6 - .align 2, 0 -_0804B270: .4byte gUnknown_202F1AE -_0804B274: - adds r0, r5, 0 - adds r1, r4, 0 - mov r2, r8 - bl sub_804B634 - b _0804B2D2 -_0804B280: - bl sub_804C918 - ldr r0, _0804B290 - ldr r0, [r0] - ldr r1, _0804B294 - adds r0, r1 - b _0804B2BC - .align 2, 0 -_0804B290: .4byte gDungeon -_0804B294: .4byte 0x00003a08 -_0804B298: - mov r0, r8 - bl sub_804B72C - movs r2, 0x1 - mov r10, r2 - b _0804B2F6 -_0804B2A4: - mov r0, r8 - bl sub_804BC80 -_0804B2AA: - movs r3, 0x1 - mov r10, r3 - b _0804B2F6 -_0804B2B0: - bl sub_804C9D0 - ldr r0, _0804B2C4 - ldr r0, [r0] - ldr r6, _0804B2C8 - adds r0, r6 -_0804B2BC: - movs r1, 0x1 - strb r1, [r0] - b _0804B2F6 - .align 2, 0 -_0804B2C4: .4byte gDungeon -_0804B2C8: .4byte 0x00003a08 -_0804B2CC: - mov r0, r8 - bl sub_804C0A8 -_0804B2D2: - movs r0, 0x1 - mov r10, r0 - b _0804B2F6 -_0804B2D8: - mov r0, r8 - bl sub_804C190 - b _0804B2F6 -_0804B2E0: - mov r0, r8 - bl sub_804C2F4 - b _0804B2F6 -_0804B2E8: - adds r0, r5, 0 - adds r1, r4, 0 - mov r2, r8 - bl sub_804C53C - movs r1, 0x1 - mov r10, r1 -_0804B2F6: - bl sub_80518F0 - bl sub_804FCCC - ldr r0, _0804B4B4 - ldrb r0, [r0] - cmp r0, 0 - bne _0804B36A - movs r7, 0 - movs r1, 0 - mov r0, sp - adds r0, 0x3F -_0804B30E: - strb r1, [r0] - subs r0, 0x1 - cmp r0, sp - bge _0804B30E - movs r5, 0 -_0804B318: - movs r4, 0 - adds r6, r5, 0x1 -_0804B31C: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - adds r1, r0, 0 - ldrh r0, [r1] - movs r2, 0x3 - ands r2, r0 - cmp r2, 0x1 - bne _0804B340 - ldrb r0, [r1, 0x9] - cmp r0, 0xF0 - bhi _0804B340 - adds r7, 0x1 - cmp r0, 0x3F - bhi _0804B340 - add r0, sp - strb r2, [r0] -_0804B340: - adds r4, 0x1 - cmp r4, 0x1F - ble _0804B31C - adds r5, r6, 0 - cmp r5, 0x37 - ble _0804B318 - movs r1, 0 - movs r4, 0 -_0804B350: - mov r2, sp - adds r0, r2, r4 - ldrb r0, [r0] - cmp r0, 0 - beq _0804B35C - adds r1, 0x1 -_0804B35C: - adds r4, 0x1 - cmp r4, 0x3F - ble _0804B350 - cmp r7, 0x1D - ble _0804B36A - cmp r1, 0x1 - bgt _0804B376 -_0804B36A: - movs r3, 0x1 - add r9, r3 - mov r6, r9 - cmp r6, 0x9 - bgt _0804B376 - b _0804B082 -_0804B376: - mov r0, r9 - cmp r0, 0xA - bne _0804B398 - ldr r1, _0804B4B8 - ldr r0, _0804B4BC - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - bl sub_804C918 - ldr r0, _0804B4C0 - ldr r0, [r0] - ldr r1, _0804B4C4 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0] -_0804B398: - bl sub_804E9DC - mov r2, r10 - cmp r2, 0 - beq _0804B3AA - movs r0, 0x1 - mov r1, r8 - bl sub_80506F0 -_0804B3AA: - movs r0, 0x64 - bl DungeonRandInt - movs r4, 0 - mov r3, r8 - ldrb r3, [r3, 0x19] - cmp r0, r3 - bge _0804B3BC - movs r4, 0x1 -_0804B3BC: - mov r0, r8 - adds r1, r4, 0 - bl sub_804FF08 - mov r0, r8 - adds r1, r4, 0 - bl sub_8050438 - bl sub_804FBE8 - ldr r5, _0804B4C0 - ldr r1, [r5] - ldr r6, _0804B4C8 - adds r0, r1, r6 - movs r2, 0 - ldrsh r0, [r0, r2] - movs r4, 0x1 - negs r4, r4 - cmp r0, r4 - beq _0804B42A - ldr r3, _0804B4CC - adds r0, r1, r3 - movs r6, 0 - ldrsh r0, [r0, r6] - cmp r0, r4 - beq _0804B42A - bl sub_8043D10 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _0804B436 - ldr r1, [r5] - ldr r0, _0804B4D0 - adds r2, r1, r0 - movs r3, 0 - ldrsh r0, [r2, r3] - cmp r0, r4 - beq _0804B42A - ldr r6, _0804B4D4 - adds r1, r6 - movs r3, 0 - ldrsh r0, [r1, r3] - cmp r0, r4 - beq _0804B42A - movs r6, 0 - ldrsh r0, [r2, r6] - movs r2, 0 - ldrsh r1, [r1, r2] - movs r2, 0 - bl sub_8050C30 - lsls r0, 24 - cmp r0, 0 - bne _0804B436 -_0804B42A: - ldr r3, [sp, 0x40] - adds r3, 0x1 - str r3, [sp, 0x40] - cmp r3, 0x9 - bgt _0804B436 - b _0804B058 -_0804B436: - ldr r6, [sp, 0x40] - cmp r6, 0xA - bne _0804B474 - ldr r1, _0804B4B8 - ldr r0, _0804B4BC - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - bl sub_804FD30 - bl sub_804C918 - ldr r0, _0804B4C0 - ldr r0, [r0] - ldr r1, _0804B4C4 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0] - bl sub_804E9DC - mov r0, r8 - movs r1, 0 - bl sub_804FF08 - mov r0, r8 - movs r1, 0 - bl sub_8050438 - bl sub_804FBE8 -_0804B474: - ldr r1, _0804B4B8 - movs r2, 0 - ldrsh r0, [r1, r2] - cmp r0, 0 - blt _0804B498 - movs r3, 0x2 - ldrsh r0, [r1, r3] - cmp r0, 0 - blt _0804B498 - movs r6, 0 - ldrsh r0, [r1, r6] - movs r2, 0x2 - ldrsh r1, [r1, r2] - movs r2, 0xBE - lsls r2, 1 - movs r3, 0 - bl sub_806C330 -_0804B498: - ldr r0, _0804B4D8 - ldr r0, [r0] - cmp r0, 0 - blt _0804B4E0 - mov r0, r8 - bl sub_8051654 - ldr r0, _0804B4C0 - ldr r0, [r0] - ldr r3, _0804B4DC - adds r0, r3 - movs r1, 0x1 - b _0804B4EA - .align 2, 0 -_0804B4B4: .4byte gUnknown_202F1A9 -_0804B4B8: .4byte gUnknown_202F1D8 -_0804B4BC: .4byte 0x0000ffff -_0804B4C0: .4byte gDungeon -_0804B4C4: .4byte 0x00003a08 -_0804B4C8: .4byte 0x0000e218 -_0804B4CC: .4byte 0x0000e21a -_0804B4D0: .4byte 0x0000e21c -_0804B4D4: .4byte 0x0000e21e -_0804B4D8: .4byte gUnknown_202F1B8 -_0804B4DC: .4byte 0x00003a0a -_0804B4E0: - ldr r0, _0804B524 - ldr r0, [r0] - ldr r6, _0804B528 - adds r0, r6 - movs r1, 0 -_0804B4EA: - strb r1, [r0] - movs r0, 0 - movs r1, 0 - movs r2, 0x38 - movs r3, 0x20 - bl sub_804B534 - ldr r0, _0804B52C - ldrb r0, [r0] - cmp r0, 0 - beq _0804B504 - bl sub_804FC74 -_0804B504: - ldr r0, _0804B524 - ldr r0, [r0] - ldr r1, _0804B530 - adds r0, r1 - ldr r0, [r0] - bl CloseFile - add sp, 0x44 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804B524: .4byte gDungeon -_0804B528: .4byte 0x00003a0a -_0804B52C: .4byte gUnknown_202F1A8 -_0804B530: .4byte 0x00013568 - thumb_func_end sub_804AFAC - - thumb_func_start sub_804B534 -sub_804B534: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - str r1, [sp] - str r2, [sp, 0x4] - mov r10, r3 - adds r5, r0, 0 - cmp r5, r2 - bge _0804B620 -_0804B54C: - ldr r4, [sp] - adds r0, r5, 0x1 - mov r9, r0 - cmp r4, r10 - bge _0804B618 - movs r6, 0x3 - mov r8, r6 -_0804B55A: - movs r3, 0 - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0xC] - bl GetTileMut - adds r2, r0, 0 - ldrh r0, [r2] - ldr r6, _0804B630 - adds r1, r6, 0 - ands r1, r0 - strh r1, [r2] - ldrb r0, [r2, 0x9] - adds r6, r4, 0x1 - ldr r3, [sp, 0xC] - cmp r0, 0xFF - bne _0804B612 - movs r7, 0x3 - adds r0, r1, 0 - ands r0, r7 - cmp r0, 0x1 - bne _0804B612 - cmp r5, 0 - ble _0804B5A4 - subs r0, r5, 0x1 - adds r1, r4, 0 - str r2, [sp, 0x8] - bl GetTile - ldrh r1, [r0] - adds r0, r7, 0 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B5A4 - movs r3, 0x1 -_0804B5A4: - cmp r4, 0 - ble _0804B5C4 - subs r1, r4, 0x1 - adds r0, r5, 0 - str r2, [sp, 0x8] - str r3, [sp, 0xC] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B5C4 - adds r3, 0x1 -_0804B5C4: - cmp r5, 0x35 - bgt _0804B5E4 - mov r0, r9 - adds r1, r4, 0 - str r2, [sp, 0x8] - str r3, [sp, 0xC] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B5E4 - adds r3, 0x1 -_0804B5E4: - adds r6, r4, 0x1 - cmp r5, 0x1D - bgt _0804B606 - adds r0, r5, 0 - adds r1, r6, 0 - str r2, [sp, 0x8] - str r3, [sp, 0xC] - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - ldr r2, [sp, 0x8] - ldr r3, [sp, 0xC] - cmp r0, 0x1 - bne _0804B606 - adds r3, 0x1 -_0804B606: - cmp r3, 0x2 - ble _0804B612 - ldrh r1, [r2] - movs r0, 0x8 - orrs r0, r1 - strh r0, [r2] -_0804B612: - adds r4, r6, 0 - cmp r4, r10 - blt _0804B55A -_0804B618: - mov r5, r9 - ldr r0, [sp, 0x4] - cmp r5, r0 - blt _0804B54C -_0804B620: - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804B630: .4byte 0x0000fffb - thumb_func_end sub_804B534 - - thumb_func_start sub_804B634 -sub_804B634: - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - ldr r4, _0804B718 - add sp, r4 - adds r4, r0, 0 - adds r5, r1, 0 - mov r9, r2 - ldr r0, _0804B71C - add r0, sp - mov r8, r0 - ldr r6, _0804B720 - add r6, sp - adds r1, r6, 0 - adds r2, r4, 0 - adds r3, r5, 0 - bl sub_804D024 - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804D084 - mov r1, r9 - movs r3, 0x1 - ldrsb r3, [r1, r3] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804D154 - str r6, [sp] - mov r1, r9 - ldrb r0, [r1, 0xD] - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804D2D0 - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r9 - bl sub_804D5B0 - str r6, [sp] - movs r0, 0 - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804D8C8 - str r6, [sp] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804E590 - mov r0, r9 - ldrb r3, [r0, 0x9] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804F0D0 - ldr r0, _0804B724 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804EBC8 - ldr r0, _0804B728 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804EEE4 - mov r0, r9 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804CBEC - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804E03C - add r0, sp, 0x8 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_804D534 - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0804B718: .4byte 0xffffe360 -_0804B71C: .4byte 0x00001c28 -_0804B720: .4byte 0x00001c64 -_0804B724: .4byte gUnknown_202F1B0 -_0804B728: .4byte gUnknown_202F1B2 - thumb_func_end sub_804B634 - - thumb_func_start sub_804B72C -sub_804B72C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804B9AC - add sp, r4 - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - str r0, [r1] - movs r5, 0 - movs r6, 0x1 - ldr r1, _0804B9B0 - add r1, sp - str r5, [r1] - movs r0, 0x5 - str r0, [r1, 0x4] - movs r0, 0x1C - str r0, [r1, 0xC] - movs r0, 0x33 - str r0, [r1, 0x14] - movs r0, 0x38 - str r0, [r1, 0x18] - movs r2, 0x10 - str r2, [r1, 0x8] - movs r0, 0x27 - str r0, [r1, 0x10] - ldr r1, _0804B9B4 - add r1, sp - movs r0, 0x2 - str r0, [r1] - movs r0, 0x7 - str r0, [r1, 0x4] - str r2, [r1, 0x8] - movs r0, 0x19 - str r0, [r1, 0xC] - movs r0, 0x1E - str r0, [r1, 0x10] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804D084 - mov r2, sp - adds r2, 0x3B - ldr r3, _0804B9B8 - add r3, sp - str r2, [r3] - mov r4, sp - adds r4, 0x3C - ldr r0, _0804B9BC - add r0, sp - str r4, [r0] - mov r1, sp - adds r1, 0x5B - ldr r2, _0804B9C0 - add r2, sp - str r1, [r2] - mov r3, sp - adds r3, 0x5C - movs r4, 0xE6 - lsls r4, 5 - add r4, sp - str r3, [r4] - mov r0, sp - adds r0, 0x7B - ldr r1, _0804B9C4 - add r1, sp - str r0, [r1] - mov r2, sp - adds r2, 0x7E - ldr r3, _0804B9C8 - add r3, sp - str r2, [r3] - add r1, sp, 0x68 - add r0, sp, 0x8 - movs r2, 0xF0 - lsls r2, 1 - movs r4, 0x6 -_0804B7CC: - strb r5, [r0, 0xA] - strb r5, [r1, 0xA] - adds r1, r2 - adds r0, r2 - subs r4, 0x1 - cmp r4, 0 - bne _0804B7CC - movs r2, 0x6 - subs r2, 0x1 - movs r4, 0x4 - cmp r4, 0 - beq _0804B80C - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - add r1, sp, 0x8 - ldr r3, _0804B9CC - add r3, sp - str r4, [r3] -_0804B7F6: - strb r5, [r1, 0xA] - strb r5, [r0, 0xA] - adds r0, 0x20 - adds r1, 0x20 - ldr r3, _0804B9CC - add r3, sp - ldr r4, [r3] - subs r4, 0x1 - str r4, [r3] - cmp r4, 0 - bne _0804B7F6 -_0804B80C: - movs r4, 0x1 - cmp r4, r2 - bge _0804B848 - movs r1, 0x3 -_0804B814: - adds r5, r4, 0x1 - mov r8, r5 - cmp r1, 0x1 - ble _0804B842 - lsls r0, r4, 4 - subs r0, r4 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r0, 0x20 - subs r3, r1, 0x1 - ldr r4, _0804B9CC - add r4, sp - str r3, [r4] -_0804B830: - strb r6, [r0, 0xA] - adds r0, 0x20 - ldr r3, _0804B9CC - add r3, sp - ldr r5, [r3] - subs r5, 0x1 - str r5, [r3] - cmp r5, 0 - bne _0804B830 -_0804B842: - mov r4, r8 - cmp r4, r2 - blt _0804B814 -_0804B848: - movs r4, 0 - ldr r5, _0804B9D0 - add r5, sp - str r4, [r5] - ldr r0, _0804B9CC - add r0, sp - str r4, [r0] - cmp r4, 0x4 - blt _0804B85C - b _0804BA8C -_0804B85C: - movs r4, 0 - ldr r2, _0804B9CC - add r2, sp - ldr r1, [r2] - adds r1, 0x1 - ldr r2, _0804B9D4 - add r2, sp - str r1, [r2] - cmp r4, 0x6 - blt _0804B872 - b _0804BA7A -_0804B872: - ldr r3, _0804B9B0 - add r3, sp - ldr r5, _0804B9D8 - add r5, sp - str r3, [r5] - ldr r0, _0804B9B4 - add r0, sp - ldr r1, _0804B9DC - add r1, sp - str r0, [r1] - ldr r2, _0804B9CC - add r2, sp - ldr r2, [r2] - lsls r0, r2, 2 - ldr r3, [r1] - adds r0, r3, r0 - ldr r3, _0804B9E0 - add r3, sp - str r0, [r3] -_0804B898: - lsls r0, r4, 4 - subs r0, r4 - ldr r5, _0804B9CC - add r5, sp - ldr r5, [r5] - adds r0, r5 - lsls r0, 5 - mov r7, sp - adds r7, r0 - adds r7, 0x8 - ldrb r0, [r7, 0xA] - cmp r0, 0 - bne _0804B8B4 - b _0804B9F4 -_0804B8B4: - lsls r0, r4, 2 - ldr r1, _0804B9D8 - add r1, sp - ldr r1, [r1] - adds r0, r1, r0 - ldr r1, [r0] - adds r2, r1, 0x2 - mov r10, r2 - ldr r3, _0804B9E0 - add r3, sp - ldr r3, [r3] - ldr r2, [r3] - adds r5, r2, 0x2 - ldr r0, _0804B9E4 - add r0, sp - str r5, [r0] - adds r4, 0x1 - mov r9, r4 - lsls r0, r4, 2 - ldr r3, _0804B9D8 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r4, [r0] - subs r4, r1 - subs r4, 0x3 - ldr r5, _0804B9D4 - add r5, sp - ldr r5, [r5] - lsls r0, r5, 2 - ldr r1, _0804B9DC - add r1, sp - ldr r1, [r1] - adds r0, r1, r0 - ldr r5, [r0] - subs r5, r2 - subs r5, 0x3 - movs r0, 0x5 - adds r1, r4, 0 - bl DungeonRandRange - mov r8, r0 - movs r0, 0x4 - adds r1, r5, 0 - bl DungeonRandRange - adds r6, r0, 0 - mov r2, r8 - subs r4, r2 - adds r0, r4, 0 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r10 - subs r5, r6 - adds r0, r5, 0 - bl DungeonRandInt - ldr r5, _0804B9E4 - add r5, sp - ldr r3, [r5] - adds r3, r0 - mov r10, r3 - mov r0, r8 - adds r3, r4, r0 - add r6, r10 - strh r4, [r7] - strh r3, [r7, 0x4] - mov r1, r10 - strh r1, [r7, 0x2] - strh r6, [r7, 0x6] - mov r8, r9 - ldr r5, _0804B9D0 - add r5, sp - ldr r2, [r5] - adds r2, 0x1 - ldr r5, _0804B9E8 - add r5, sp - str r2, [r5] - cmp r4, r3 - bge _0804B99E -_0804B956: - mov r5, r10 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804B998 - ldr r0, _0804B9EC - mov r9, r0 -_0804B962: - adds r0, r4, 0 - adds r1, r5, 0 - ldr r2, _0804B9F0 - add r2, sp - str r3, [r2] - bl GetTileMut - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileMut - ldr r1, _0804B9D0 - add r1, sp - ldrb r1, [r1] - strb r1, [r0, 0x9] - adds r5, 0x1 - ldr r2, _0804B9F0 - add r2, sp - ldr r3, [r2] - cmp r5, r6 - blt _0804B962 -_0804B998: - adds r4, r7, 0 - cmp r4, r3 - blt _0804B956 -_0804B99E: - ldr r3, _0804B9E8 - add r3, sp - ldr r3, [r3] - ldr r4, _0804B9D0 - add r4, sp - str r3, [r4] - b _0804BA72 - .align 2, 0 -_0804B9AC: .4byte 0xffffe320 -_0804B9B0: .4byte 0x00001c28 -_0804B9B4: .4byte 0x00001c64 -_0804B9B8: .4byte 0x00001cd4 -_0804B9BC: .4byte 0x00001cd8 -_0804B9C0: .4byte 0x00001cbc -_0804B9C4: .4byte 0x00001cc4 -_0804B9C8: .4byte 0x00001cc8 -_0804B9CC: .4byte 0x00001ca4 -_0804B9D0: .4byte 0x00001ca8 -_0804B9D4: .4byte 0x00001ccc -_0804B9D8: .4byte 0x00001cac -_0804B9DC: .4byte 0x00001cb4 -_0804B9E0: .4byte 0x00001cb8 -_0804B9E4: .4byte 0x00001cb0 -_0804B9E8: .4byte 0x00001cd0 -_0804B9EC: .4byte 0x0000fffc -_0804B9F0: .4byte 0x00001cdc -_0804B9F4: - lsls r0, r4, 2 - ldr r5, _0804BBE8 - add r5, sp - ldr r5, [r5] - adds r0, r5, r0 - ldr r2, [r0] - adds r0, r2, 0x1 - ldr r1, _0804BBEC - add r1, sp - ldr r1, [r1] - ldr r3, [r1] - adds r6, r3, 0x1 - adds r4, 0x1 - mov r8, r4 - lsls r1, r4, 2 - adds r1, r5, r1 - ldr r1, [r1] - subs r1, r2 - subs r1, 0x3 - ldr r5, _0804BBF0 - add r5, sp - ldr r5, [r5] - lsls r2, r5, 2 - ldr r4, _0804BBF4 - add r4, sp - ldr r4, [r4] - adds r2, r4, r2 - ldr r4, [r2] - subs r4, r3 - subs r4, 0x3 - adds r1, r0, r1 - bl DungeonRandRange - adds r5, r0, 0 - adds r4, r6, r4 - adds r0, r6, 0 - adds r1, r4, 0 - bl DungeonRandRange - adds r4, r0, 0 - strh r5, [r7] - adds r0, r5, 0x1 - strh r0, [r7, 0x4] - strh r4, [r7, 0x2] - adds r0, r4, 0x1 - strh r0, [r7, 0x6] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r1, [r0] - ldr r3, _0804BBF8 - adds r2, r3, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0xFF - strb r1, [r0, 0x9] -_0804BA72: - mov r4, r8 - cmp r4, 0x6 - bge _0804BA7A - b _0804B898 -_0804BA7A: - ldr r4, _0804BBF0 - add r4, sp - ldr r4, [r4] - ldr r5, _0804BBFC - add r5, sp - str r4, [r5] - cmp r4, 0x4 - bge _0804BA8C - b _0804B85C -_0804BA8C: - add r1, sp, 0x8 - movs r6, 0 - movs r0, 0x1 - strb r0, [r1, 0x16] - ldr r1, _0804BC00 - add r1, sp - strb r0, [r1] - movs r1, 0xFF - lsls r1, 1 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC04 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC08 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC0C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC10 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC14 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC18 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC1C - add r1, sp - strb r0, [r1] - add r1, sp, 0x8 - strb r0, [r1, 0x14] - ldr r5, _0804BC20 - add r5, sp - ldr r5, [r5] - strb r0, [r5] - ldr r1, _0804BC24 - add r1, sp - ldr r1, [r1] - strb r0, [r1] - ldr r2, _0804BC28 - add r2, sp - ldr r2, [r2] - strb r0, [r2] - movs r3, 0xE6 - lsls r3, 5 - add r3, sp - ldr r3, [r3] - strb r0, [r3] - ldr r4, _0804BC2C - add r4, sp - ldr r4, [r4] - strb r0, [r4] - ldr r5, _0804BC30 - add r5, sp - ldr r5, [r5] - strb r0, [r5] - ldr r1, _0804BC34 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC38 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC3C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC40 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC44 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC48 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC4C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC50 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC54 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC58 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC5C - add r1, sp - strb r0, [r1] - ldr r1, _0804BC60 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC64 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC68 - add r1, sp - strb r0, [r1] - ldr r1, _0804BC6C - add r1, sp - strb r0, [r1] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - movs r4, 0xE5 - lsls r4, 5 - add r4, sp - ldr r3, [r4] - bl sub_804D5B0 - ldr r5, _0804BC70 - add r5, sp - ldr r4, _0804BC74 - add r4, sp - str r4, [sp] - str r6, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804D8C8 - str r4, [sp] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804E590 - ldr r0, _0804BC78 - movs r5, 0 - ldrsh r3, [r0, r5] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804EBC8 - ldr r0, _0804BC7C - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804EEE4 - movs r2, 0xE5 - lsls r2, 5 - add r2, sp - ldr r2, [r2] - ldrb r3, [r2, 0x13] - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804CBEC - add r0, sp, 0x8 - movs r1, 0x6 - movs r2, 0x4 - bl sub_804E03C - movs r3, 0xE7 - lsls r3, 5 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804BBE8: .4byte 0x00001cac -_0804BBEC: .4byte 0x00001cb8 -_0804BBF0: .4byte 0x00001ccc -_0804BBF4: .4byte 0x00001cb4 -_0804BBF8: .4byte 0x0000fffc -_0804BBFC: .4byte 0x00001ca4 -_0804BC00: .4byte 0x000001fd -_0804BC04: .4byte 0x000003dd -_0804BC08: .4byte 0x000003de -_0804BC0C: .4byte 0x000005bd -_0804BC10: .4byte 0x000005be -_0804BC14: .4byte 0x0000079d -_0804BC18: .4byte 0x0000079e -_0804BC1C: .4byte 0x0000097d -_0804BC20: .4byte 0x00001cd4 -_0804BC24: .4byte 0x00001cd8 -_0804BC28: .4byte 0x00001cbc -_0804BC2C: .4byte 0x00001cc4 -_0804BC30: .4byte 0x00001cc8 -_0804BC34: .4byte 0x0000025d -_0804BC38: .4byte 0x0000025e -_0804BC3C: .4byte 0x0000043d -_0804BC40: .4byte 0x0000043e -_0804BC44: .4byte 0x0000061d -_0804BC48: .4byte 0x0000061e -_0804BC4C: .4byte 0x000007fd -_0804BC50: .4byte 0x000007fe -_0804BC54: .4byte 0x000009dd -_0804BC58: .4byte 0x0000097c -_0804BC5C: .4byte 0x0000099b -_0804BC60: .4byte 0x0000099c -_0804BC64: .4byte 0x000009bb -_0804BC68: .4byte 0x000009bc -_0804BC6C: .4byte 0x000009db -_0804BC70: .4byte 0x00001c28 -_0804BC74: .4byte 0x00001c64 -_0804BC78: .4byte gUnknown_202F1B0 -_0804BC7C: .4byte gUnknown_202F1B2 - thumb_func_end sub_804B72C - - thumb_func_start sub_804BC80 -sub_804BC80: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804BED0 - add sp, r4 - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - str r0, [r1] - movs r4, 0x1 - movs r5, 0 - ldr r1, _0804BED4 - add r1, sp - str r5, [r1] - movs r0, 0xB - str r0, [r1, 0x4] - movs r0, 0x16 - str r0, [r1, 0x8] - movs r0, 0x21 - str r0, [r1, 0xC] - movs r0, 0x2C - str r0, [r1, 0x10] - movs r0, 0x38 - str r0, [r1, 0x14] - ldr r1, _0804BED8 - add r1, sp - str r4, [r1] - movs r0, 0x9 - str r0, [r1, 0x4] - movs r0, 0x10 - str r0, [r1, 0x8] - movs r0, 0x17 - str r0, [r1, 0xC] - movs r0, 0x1F - str r0, [r1, 0x10] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804D084 - add r6, sp, 0x70 - add r1, sp, 0x68 - add r0, sp, 0x8 - movs r3, 0xF0 - lsls r3, 1 - movs r2, 0x5 -_0804BCE0: - strb r4, [r0, 0xA] - strb r4, [r1, 0xA] - adds r1, r3 - adds r0, r3 - subs r2, 0x1 - cmp r2, 0 - bne _0804BCE0 - movs r3, 0x5 - subs r3, 0x1 - movs r2, 0x4 - cmp r2, 0 - beq _0804BD1A - lsls r0, r3, 4 - subs r0, r3 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - add r1, sp, 0x8 - mov r10, r2 -_0804BD06: - strb r4, [r1, 0xA] - strb r4, [r0, 0xA] - adds r0, 0x20 - adds r1, 0x20 - movs r2, 0x1 - negs r2, r2 - add r10, r2 - mov r2, r10 - cmp r2, 0 - bne _0804BD06 -_0804BD1A: - movs r2, 0x1 - cmp r2, r3 - bge _0804BD58 - movs r1, 0x3 -_0804BD22: - adds r4, r2, 0x1 - ldr r0, _0804BEDC - add r0, sp - str r4, [r0] - cmp r1, 0x1 - ble _0804BD4E - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r0, 0x20 - subs r2, r1, 0x1 - mov r10, r2 -_0804BD3E: - strb r5, [r0, 0xA] - adds r0, 0x20 - movs r4, 0x1 - negs r4, r4 - add r10, r4 - mov r2, r10 - cmp r2, 0 - bne _0804BD3E -_0804BD4E: - ldr r4, _0804BEDC - add r4, sp - ldr r2, [r4] - cmp r2, r3 - blt _0804BD22 -_0804BD58: - add r0, sp, 0x8 - movs r1, 0x1 - strb r1, [r0, 0x8] - movs r0, 0xF2 - lsls r0, 3 - add r0, sp - strb r1, [r0] - strb r1, [r6] - movs r0, 0xFE - lsls r0, 3 - add r0, sp - strb r1, [r0] - movs r5, 0 - ldr r6, _0804BEE0 - add r6, sp - str r5, [r6] - mov r10, r5 - cmp r5, 0x4 - blt _0804BD80 - b _0804BFAC -_0804BD80: - movs r0, 0x4 - movs r1, 0xE6 - lsls r1, 5 - add r1, sp - str r0, [r1] -_0804BD8A: - movs r2, 0 - cmp r2, 0x5 - blt _0804BD92 - b _0804BF94 -_0804BD92: - ldr r3, _0804BED4 - add r3, sp - ldr r4, _0804BEE4 - add r4, sp - str r3, [r4] - ldr r5, _0804BED8 - add r5, sp - ldr r6, _0804BEE8 - add r6, sp - str r5, [r6] - mov r1, r10 - lsls r0, r1, 2 - adds r0, r5, r0 - ldr r3, _0804BEEC - add r3, sp - str r0, [r3] -_0804BDB2: - lsls r0, r2, 4 - subs r0, r2 - add r0, r10 - lsls r0, 5 - mov r7, sp - adds r7, r0 - adds r7, 0x8 - ldrb r0, [r7, 0x8] - adds r4, r2, 0x1 - ldr r5, _0804BEDC - add r5, sp - str r4, [r5] - cmp r0, 0 - beq _0804BDD0 - b _0804BF88 -_0804BDD0: - ldrb r0, [r7, 0xA] - cmp r0, 0 - bne _0804BDD8 - b _0804BF00 -_0804BDD8: - lsls r0, r2, 2 - ldr r6, _0804BEE4 - add r6, sp - ldr r6, [r6] - adds r0, r6, r0 - ldr r1, [r0] - adds r0, r1, 0x2 - mov r9, r0 - ldr r3, _0804BEEC - add r3, sp - ldr r3, [r3] - ldr r2, [r3] - adds r4, r2, 0x2 - ldr r5, _0804BEF0 - add r5, sp - str r4, [r5] - ldr r6, _0804BEDC - add r6, sp - ldr r6, [r6] - lsls r0, r6, 2 - ldr r3, _0804BEE4 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r4, [r0] - subs r4, r1 - subs r4, 0x3 - ldr r5, _0804BEE8 - add r5, sp - ldr r5, [r5] - movs r6, 0xE6 - lsls r6, 5 - add r6, sp - ldr r6, [r6] - adds r0, r5, r6 - ldr r5, [r0] - subs r5, r2 - subs r5, 0x3 - movs r0, 0x5 - adds r1, r4, 0 - bl DungeonRandRange - mov r8, r0 - movs r0, 0x4 - adds r1, r5, 0 - bl DungeonRandRange - adds r6, r0, 0 - mov r0, r8 - subs r4, r0 - adds r0, r4, 0 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r9 - subs r5, r6 - adds r0, r5, 0 - bl DungeonRandInt - ldr r2, _0804BEF0 - add r2, sp - ldr r1, [r2] - adds r1, r0 - mov r9, r1 - mov r5, r8 - adds r3, r4, r5 - add r6, r9 - strh r4, [r7] - strh r3, [r7, 0x4] - strh r1, [r7, 0x2] - strh r6, [r7, 0x6] - ldr r1, _0804BEE0 - add r1, sp - ldr r0, [r1] - adds r0, 0x1 - ldr r1, _0804BEF4 - add r1, sp - str r0, [r1] - cmp r4, r3 - bge _0804BEC0 -_0804BE78: - mov r5, r9 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804BEBA - ldr r2, _0804BEF8 - mov r8, r2 -_0804BE84: - adds r0, r4, 0 - adds r1, r5, 0 - ldr r2, _0804BEFC - add r2, sp - str r3, [r2] - bl GetTileMut - ldrh r1, [r0] - mov r2, r8 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileMut - ldr r1, _0804BEE0 - add r1, sp - ldrb r1, [r1] - strb r1, [r0, 0x9] - adds r5, 0x1 - ldr r2, _0804BEFC - add r2, sp - ldr r3, [r2] - cmp r5, r6 - blt _0804BE84 -_0804BEBA: - adds r4, r7, 0 - cmp r4, r3 - blt _0804BE78 -_0804BEC0: - ldr r3, _0804BEF4 - add r3, sp - ldr r3, [r3] - ldr r4, _0804BEE0 - add r4, sp - str r3, [r4] - b _0804BF88 - .align 2, 0 -_0804BED0: .4byte 0xffffe338 -_0804BED4: .4byte 0x00001c28 -_0804BED8: .4byte 0x00001c64 -_0804BEDC: .4byte 0x00001cb8 -_0804BEE0: .4byte 0x00001ca4 -_0804BEE4: .4byte 0x00001ca8 -_0804BEE8: .4byte 0x00001cb0 -_0804BEEC: .4byte 0x00001cb4 -_0804BEF0: .4byte 0x00001cac -_0804BEF4: .4byte 0x00001cbc -_0804BEF8: .4byte 0x0000fffc -_0804BEFC: .4byte 0x00001cc4 -_0804BF00: - lsls r0, r2, 2 - ldr r4, _0804C080 - add r4, sp - ldr r4, [r4] - adds r0, r4, r0 - ldr r2, [r0] - adds r0, r2, 0x1 - ldr r5, _0804C084 - add r5, sp - ldr r5, [r5] - ldr r3, [r5] - adds r6, r3, 0x1 - mov r8, r6 - ldr r4, _0804C088 - add r4, sp - ldr r4, [r4] - lsls r1, r4, 2 - ldr r5, _0804C080 - add r5, sp - ldr r5, [r5] - adds r1, r5, r1 - ldr r1, [r1] - subs r1, r2 - subs r1, 0x3 - ldr r6, _0804C08C - add r6, sp - ldr r6, [r6] - movs r4, 0xE6 - lsls r4, 5 - add r4, sp - ldr r4, [r4] - adds r2, r6, r4 - ldr r4, [r2] - subs r4, r3 - subs r4, 0x3 - adds r1, r0, r1 - bl DungeonRandRange - adds r5, r0, 0 - add r4, r8 - mov r0, r8 - adds r1, r4, 0 - bl DungeonRandRange - adds r4, r0, 0 - strh r5, [r7] - adds r0, r5, 0x1 - strh r0, [r7, 0x4] - strh r4, [r7, 0x2] - adds r0, r4, 0x1 - strh r0, [r7, 0x6] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r1, [r0] - ldr r6, _0804C090 - adds r2, r6, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0xFF - strb r1, [r0, 0x9] -_0804BF88: - ldr r0, _0804C088 - add r0, sp - ldr r2, [r0] - cmp r2, 0x5 - bge _0804BF94 - b _0804BDB2 -_0804BF94: - movs r2, 0xE6 - lsls r2, 5 - add r2, sp - ldr r1, [r2] - adds r1, 0x4 - str r1, [r2] - movs r3, 0x1 - add r10, r3 - mov r4, r10 - cmp r4, 0x4 - bge _0804BFAC - b _0804BD8A -_0804BFAC: - movs r2, 0x1 - movs r1, 0x1 - movs r3, 0xF - add r4, sp, 0x1C -_0804BFB4: - movs r5, 0 - mov r10, r5 - lsls r0, r3, 5 - adds r0, r4 -_0804BFBC: - strb r1, [r0] - strb r1, [r0, 0x1F] - adds r0, 0x20 - movs r6, 0x1 - add r10, r6 - mov r5, r10 - cmp r5, 0x2 - ble _0804BFBC - movs r0, 0xF0 - lsls r0, 1 - adds r3, 0xF - adds r2, 0x1 - cmp r2, 0x3 - ble _0804BFB4 - mov r10, r6 - movs r5, 0x1 - adds r4, r0, 0 - mov r6, sp - adds r6, r4 - adds r6, 0x8 -_0804BFE4: - movs r2, 0 - mov r1, r10 - lsls r0, r1, 5 - mov r3, r10 - adds r3, 0x1 - adds r1, r0, r6 - add r0, sp - adds r0, 0x8 -_0804BFF4: - strb r5, [r0, 0x16] - strb r5, [r1, 0x15] - adds r1, r4 - adds r0, r4 - adds r2, 0x1 - cmp r2, 0x3 - ble _0804BFF4 - mov r10, r3 - cmp r3, 0x2 - ble _0804BFE4 - ldr r5, _0804C094 - add r5, sp - ldr r4, _0804C098 - add r4, sp - str r4, [sp] - movs r0, 0x1 - str r0, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804D8C8 - str r4, [sp] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - adds r3, r5, 0 - bl sub_804E590 - ldr r0, _0804C09C - movs r2, 0 - ldrsh r3, [r0, r2] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804EBC8 - ldr r0, _0804C0A0 - movs r4, 0 - ldrsh r3, [r0, r4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804EEE4 - movs r5, 0xE5 - lsls r5, 5 - add r5, sp - ldr r5, [r5] - ldrb r3, [r5, 0x13] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804CBEC - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x4 - bl sub_804E03C - ldr r3, _0804C0A4 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C080: .4byte 0x00001ca8 -_0804C084: .4byte 0x00001cb4 -_0804C088: .4byte 0x00001cb8 -_0804C08C: .4byte 0x00001cb0 -_0804C090: .4byte 0x0000fffc -_0804C094: .4byte 0x00001c28 -_0804C098: .4byte 0x00001c64 -_0804C09C: .4byte gUnknown_202F1B0 -_0804C0A0: .4byte gUnknown_202F1B2 -_0804C0A4: .4byte 0x00001cc8 - thumb_func_end sub_804BC80 - - thumb_func_start sub_804C0A8 -sub_804C0A8: - push {r4-r6,lr} - mov r6, r8 - push {r6} - ldr r4, _0804C17C - add sp, r4 - adds r6, r0, 0 - ldr r4, _0804C180 - add r4, sp - movs r0, 0 - str r0, [r4] - movs r0, 0xB - str r0, [r4, 0x4] - movs r0, 0x16 - str r0, [r4, 0x8] - movs r0, 0x21 - str r0, [r4, 0xC] - movs r0, 0x2C - str r0, [r4, 0x10] - movs r0, 0x38 - str r0, [r4, 0x14] - ldr r5, _0804C184 - add r5, sp - movs r0, 0x4 - str r0, [r5] - movs r0, 0xF - str r0, [r5, 0x4] - movs r0, 0x1 - mov r8, r0 - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804D084 - movs r3, 0x1 - ldrsb r3, [r6, r3] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804D154 - str r5, [sp] - ldrb r0, [r6, 0xD] - str r0, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r4, 0 - bl sub_804D2D0 - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r6, 0 - bl sub_804D5B0 - str r5, [sp] - mov r1, r8 - str r1, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r4, 0 - bl sub_804D8C8 - str r5, [sp] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - adds r3, r4, 0 - bl sub_804E590 - ldr r0, _0804C188 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804EBC8 - ldr r0, _0804C18C - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804EEE4 - ldrb r3, [r6, 0x13] - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804CBEC - add r0, sp, 0x8 - movs r1, 0x5 - movs r2, 0x1 - bl sub_804E03C - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0804C17C: .4byte 0xffffe360 -_0804C180: .4byte 0x00001c28 -_0804C184: .4byte 0x00001c64 -_0804C188: .4byte gUnknown_202F1B0 -_0804C18C: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C0A8 - - thumb_func_start sub_804C190 -sub_804C190: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804C2CC - add sp, r4 - mov r10, r0 - ldr r1, _0804C2D0 - add r1, sp - movs r2, 0xB - str r2, [r1] - movs r0, 0x16 - str r0, [r1, 0x4] - movs r0, 0x21 - str r0, [r1, 0x8] - movs r0, 0x2C - str r0, [r1, 0xC] - ldr r1, _0804C2D4 - add r1, sp - movs r0, 0x2 - str r0, [r1] - str r2, [r1, 0x4] - movs r0, 0x14 - str r0, [r1, 0x8] - movs r0, 0x1E - str r0, [r1, 0xC] - movs r0, 0x3 - mov r8, r0 - movs r7, 0x3 - add r0, sp, 0x8 - movs r1, 0x3 - movs r2, 0x3 - bl sub_804D084 - movs r1, 0 - add r5, sp, 0x50 - movs r0, 0x3E - add r0, sp - mov r9, r0 - mov r0, r10 - ldrb r0, [r0, 0xD] - mov r12, r0 -_0804C1E6: - adds r3, r1, 0x1 - cmp r7, 0 - beq _0804C204 - lsls r0, r1, 4 - subs r0, r1 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r1, r7, 0 -_0804C1FA: - strb r2, [r0, 0xA] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C1FA -_0804C204: - adds r1, r3, 0 - cmp r1, r8 - blt _0804C1E6 - add r0, sp, 0x8 - movs r4, 0x1 - strb r4, [r0, 0x8] - add r0, sp, 0x3D0 - strb r4, [r0] - strb r4, [r5] - movs r0, 0x82 - lsls r0, 3 - add r0, sp - strb r4, [r0] - ldr r6, _0804C2D0 - add r6, sp - ldr r5, _0804C2D4 - add r5, sp - str r5, [sp] - mov r1, r12 - str r1, [sp, 0x4] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804D2D0 - mov r0, r9 - strb r4, [r0] - ldr r0, _0804C2D8 - add r0, sp - strb r4, [r0] - ldr r0, _0804C2DC - add r0, sp - strb r4, [r0] - ldr r0, _0804C2E0 - add r0, sp - strb r4, [r0] - add r0, sp, 0x1FC - strb r4, [r0] - ldr r0, _0804C2E4 - add r0, sp - strb r4, [r0] - add r0, sp, 0x21C - strb r4, [r0] - ldr r0, _0804C2E8 - add r0, sp - strb r4, [r0] - str r5, [sp] - str r4, [sp, 0x4] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804D8C8 - str r5, [sp] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804E590 - ldr r0, _0804C2EC - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804EBC8 - ldr r0, _0804C2F0 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804EEE4 - mov r0, r10 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804CBEC - add r0, sp, 0x8 - mov r1, r8 - adds r2, r7, 0 - bl sub_804E03C - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C2CC: .4byte 0xffffe360 -_0804C2D0: .4byte 0x00001c28 -_0804C2D4: .4byte 0x00001c64 -_0804C2D8: .4byte 0x0000021d -_0804C2DC: .4byte 0x0000021e -_0804C2E0: .4byte 0x000003fd -_0804C2E4: .4byte 0x0000021b -_0804C2E8: .4byte 0x0000023b -_0804C2EC: .4byte gUnknown_202F1B0 -_0804C2F0: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C190 - - thumb_func_start sub_804C2F4 -sub_804C2F4: - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r4, _0804C420 - add sp, r4 - mov r8, r0 - ldr r1, _0804C424 - add r1, sp - movs r0, 0x5 - str r0, [r1] - movs r0, 0xF - str r0, [r1, 0x4] - movs r0, 0x23 - str r0, [r1, 0x8] - movs r0, 0x32 - str r0, [r1, 0xC] - ldr r1, _0804C428 - add r1, sp - movs r0, 0x2 - str r0, [r1] - movs r0, 0xB - str r0, [r1, 0x4] - movs r0, 0x14 - str r0, [r1, 0x8] - movs r0, 0x1E - str r0, [r1, 0xC] - movs r7, 0x3 - movs r6, 0x3 - add r0, sp, 0x8 - movs r1, 0x3 - movs r2, 0x3 - bl sub_804D084 - movs r1, 0 - mov r0, r8 - ldrb r4, [r0, 0xD] -_0804C33C: - adds r3, r1, 0x1 - cmp r6, 0 - beq _0804C35A - lsls r0, r1, 4 - subs r0, r1 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r1, r6, 0 -_0804C350: - strb r2, [r0, 0xA] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C350 -_0804C35A: - adds r1, r3, 0 - cmp r1, r7 - blt _0804C33C - ldr r3, _0804C424 - add r3, sp - ldr r0, _0804C428 - add r0, sp - str r0, [sp] - str r4, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D2D0 - movs r4, 0x1 - ldr r3, _0804C42C - add r3, sp - ldr r0, _0804C430 - add r0, sp - add r2, sp, 0x8 - movs r1, 0x2 -_0804C384: - strb r4, [r2, 0x16] - strb r4, [r0] - strb r4, [r0, 0x1] - strb r4, [r3] - adds r3, 0x20 - adds r0, 0x20 - adds r2, 0x20 - subs r1, 0x1 - cmp r1, 0 - bge _0804C384 - ldr r5, _0804C424 - add r5, sp - ldr r4, _0804C428 - add r4, sp - str r4, [sp] - movs r0, 0x1 - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804D8C8 - movs r0, 0x1 - movs r1, 0 - movs r2, 0x1 - add r3, sp, 0x8 - bl sub_804C43C - movs r0, 0x1 - movs r1, 0 - movs r2, 0x2 - add r3, sp, 0x8 - bl sub_804C43C - str r4, [sp] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804E590 - ldr r0, _0804C434 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EBC8 - ldr r0, _0804C438 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EEE4 - mov r0, r8 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804CBEC - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804E03C - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C420: .4byte 0xffffe360 -_0804C424: .4byte 0x00001c28 -_0804C428: .4byte 0x00001c64 -_0804C42C: .4byte 0x000003dd -_0804C430: .4byte 0x000001fd -_0804C434: .4byte gUnknown_202F1B0 -_0804C438: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C2F4 - - thumb_func_start sub_804C43C -sub_804C43C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - str r0, [sp] - str r3, [sp, 0x4] - lsls r7, r1, 5 - lsls r0, 4 - str r0, [sp, 0xC] - ldr r3, [sp] - subs r0, r3 - lsls r0, 5 - ldr r4, [sp, 0x4] - adds r0, r4 - adds r3, r7, r0 - adds r6, r1, r2 - lsls r1, r6, 5 - adds r2, r1, r0 - movs r5, 0 - ldrsh r1, [r2, r5] - adds r4, r1, 0 - ldrh r0, [r3] - mov r8, r0 - movs r5, 0 - ldrsh r0, [r3, r5] - cmp r1, r0 - ble _0804C478 - mov r4, r8 -_0804C478: - lsls r0, r4, 16 - asrs r0, 16 - str r0, [sp, 0x8] - movs r1, 0x2 - ldrsh r0, [r3, r1] - mov r10, r0 - movs r4, 0x4 - ldrsh r1, [r2, r4] - adds r4, r1, 0 - ldrh r5, [r3, 0x4] - mov r8, r5 - movs r5, 0x4 - ldrsh r0, [r3, r5] - cmp r1, r0 - bge _0804C498 - mov r4, r8 -_0804C498: - lsls r0, r4, 16 - asrs r0, 16 - str r0, [sp, 0x10] - movs r1, 0x6 - ldrsh r0, [r2, r1] - mov r8, r0 - movs r2, 0 - ldrsh r0, [r3, r2] - mov r1, r10 - bl GetTile - ldrb r0, [r0, 0x9] - mov r9, r0 - ldr r5, [sp, 0x8] - str r7, [sp, 0x1C] - ldr r3, [sp, 0xC] - str r3, [sp, 0x18] - str r6, [sp, 0x14] - ldr r4, [sp, 0x10] - cmp r5, r4 - bge _0804C4F2 -_0804C4C2: - mov r4, r10 - adds r6, r5, 0x1 - cmp r10, r8 - bge _0804C4EA - ldr r0, _0804C538 - adds r7, r0, 0 -_0804C4CE: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r1, [r0] - ands r1, r7 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r9 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r8 - blt _0804C4CE -_0804C4EA: - adds r5, r6, 0 - ldr r2, [sp, 0x10] - cmp r5, r2 - blt _0804C4C2 -_0804C4F2: - ldr r3, [sp, 0x18] - ldr r4, [sp] - subs r1, r3, r4 - lsls r1, 5 - ldr r5, [sp, 0x4] - adds r1, r5 - ldr r0, [sp, 0x1C] - adds r2, r0, r1 - movs r3, 0 - mov r4, sp - ldrh r4, [r4, 0x8] - strh r4, [r2] - mov r5, sp - ldrh r5, [r5, 0x10] - strh r5, [r2, 0x4] - mov r0, r10 - strh r0, [r2, 0x2] - mov r4, r8 - strh r4, [r2, 0x6] - ldr r5, [sp, 0x14] - lsls r0, r5, 5 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0, 0x12] - strb r1, [r2, 0x12] - strb r3, [r0, 0xB] - strb r1, [r0, 0x11] - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C538: .4byte 0x0000fffc - thumb_func_end sub_804C43C - - thumb_func_start sub_804C53C -sub_804C53C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804C6F8 - add sp, r4 - mov r10, r2 - adds r7, r0, 0 - adds r6, r1, 0 - ldr r0, _0804C6FC - add r0, sp - ldr r1, _0804C700 - add r1, sp - adds r2, r7, 0 - adds r3, r6, 0 - bl sub_804D024 - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D084 - movs r2, 0 - cmp r2, r7 - bge _0804C594 -_0804C570: - adds r3, r2, 0x1 - cmp r6, 0 - ble _0804C58E - lsls r0, r2, 4 - subs r0, r2 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r1, r6, 0 -_0804C584: - strb r2, [r0, 0xA] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C584 -_0804C58E: - adds r2, r3, 0 - cmp r2, r7 - blt _0804C570 -_0804C594: - movs r2, 0x1 - subs r0, r7, 0x1 - mov r8, r0 - subs r1, r6, 0x1 - mov r9, r1 - mov r0, r10 - ldrb r0, [r0, 0xD] - mov r12, r0 - cmp r2, r8 - bge _0804C5D2 - mov r4, r9 - mov r5, r8 -_0804C5AC: - adds r3, r2, 0x1 - cmp r4, 0x1 - ble _0804C5CC - lsls r0, r2, 4 - subs r0, r2 - movs r2, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - adds r0, 0x20 - subs r1, r4, 0x1 -_0804C5C2: - strb r2, [r0, 0x8] - adds r0, 0x20 - subs r1, 0x1 - cmp r1, 0 - bne _0804C5C2 -_0804C5CC: - adds r2, r3, 0 - cmp r2, r5 - blt _0804C5AC -_0804C5D2: - ldr r3, _0804C6FC - add r3, sp - ldr r0, _0804C700 - add r0, sp - str r0, [sp] - mov r1, r12 - str r1, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D2D0 - movs r2, 0 - cmp r2, r8 - bge _0804C636 - movs r4, 0x1 - mov r0, r9 - lsls r5, r0, 5 - subs r1, r7, 0x2 - mov r12, r1 -_0804C5FA: - cmp r2, 0 - beq _0804C614 - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - mov r1, sp - adds r1, r0 - adds r1, 0x8 - strb r4, [r1, 0x16] - adds r0, r5, r0 - add r0, sp - adds r0, 0x8 - strb r4, [r0, 0x16] -_0804C614: - adds r3, r2, 0x1 - cmp r2, r12 - bge _0804C630 - lsls r0, r3, 4 - subs r0, r3 - lsls r0, 5 - mov r1, sp - adds r1, r0 - adds r1, 0x8 - strb r4, [r1, 0x15] - adds r0, r5, r0 - add r0, sp - adds r0, 0x8 - strb r4, [r0, 0x15] -_0804C630: - adds r2, r3, 0 - cmp r2, r8 - blt _0804C5FA -_0804C636: - movs r1, 0 - cmp r1, r9 - bge _0804C66A - movs r3, 0x1 - mov r2, r8 - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, sp - adds r0, 0x8 - add r2, sp, 0x8 - subs r5, r6, 0x2 - mov r4, r9 -_0804C650: - cmp r1, 0 - beq _0804C658 - strb r3, [r2, 0x13] - strb r3, [r0, 0x13] -_0804C658: - cmp r1, r5 - bge _0804C660 - strb r3, [r2, 0x14] - strb r3, [r0, 0x14] -_0804C660: - adds r0, 0x20 - adds r2, 0x20 - adds r1, 0x1 - cmp r1, r4 - blt _0804C650 -_0804C66A: - ldr r5, _0804C6FC - add r5, sp - ldr r4, _0804C700 - add r4, sp - str r4, [sp] - movs r0, 0 - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804D8C8 - str r4, [sp] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_804E590 - mov r0, r10 - ldrb r3, [r0, 0x9] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804F0D0 - ldr r0, _0804C704 - movs r1, 0 - ldrsh r3, [r0, r1] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EBC8 - ldr r0, _0804C708 - movs r2, 0 - ldrsh r3, [r0, r2] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804EEE4 - mov r0, r10 - ldrb r3, [r0, 0x13] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804CBEC - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804E03C - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - bl sub_804D534 - movs r3, 0xE5 - lsls r3, 5 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C6F8: .4byte 0xffffe360 -_0804C6FC: .4byte 0x00001c28 -_0804C700: .4byte 0x00001c64 -_0804C704: .4byte gUnknown_202F1B0 -_0804C708: .4byte gUnknown_202F1B2 - thumb_func_end sub_804C53C - - thumb_func_start sub_804C70C -sub_804C70C: - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - adds r7, r0, 0 - mov r8, r1 - ldr r0, _0804C73C - ldr r0, [r0] - ldr r1, _0804C740 - adds r0, r1 - ldr r0, [r0] - ldr r1, [r0, 0x4] - lsls r0, r7, 2 - adds r0, r1 - ldr r0, [r0] - ldrb r5, [r0] - ldrb r6, [r0, 0x1] - cmp r5, 0 - beq _0804C736 - cmp r6, 0 - bne _0804C744 -_0804C736: - bl sub_804C918 - b _0804C782 - .align 2, 0 -_0804C73C: .4byte gDungeon -_0804C740: .4byte 0x00013568 -_0804C744: - cmp r7, 0x31 - bgt _0804C752 - adds r0, r7, 0 - bl sub_8051288 - movs r0, 0x1 - b _0804C784 -_0804C752: - adds r1, r5, 0x4 - movs r0, 0x38 - bl __divsi3 - adds r4, r0, 0 - cmp r4, 0x1 - bgt _0804C762 - movs r4, 0x1 -_0804C762: - adds r1, r6, 0x4 - movs r0, 0x20 - bl __divsi3 - adds r1, r0, 0 - cmp r1, 0x1 - bgt _0804C772 - movs r1, 0x1 -_0804C772: - str r7, [sp] - mov r0, r8 - str r0, [sp, 0x4] - adds r0, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl sub_804C790 -_0804C782: - movs r0, 0 -_0804C784: - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_804C70C - - thumb_func_start sub_804C790 -sub_804C790: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804C81C - add sp, r4 - adds r5, r0, 0 - adds r4, r1, 0 - ldr r0, _0804C820 - add r0, sp - str r2, [r0] - ldr r1, _0804C824 - add r1, sp - str r3, [r1] - movs r2, 0 - mov r10, r2 - mov r8, r2 - ldr r0, _0804C828 - add r0, sp - ldr r1, _0804C82C - add r1, sp - adds r2, r5, 0 - adds r3, r4, 0 - bl sub_804D024 - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - bl sub_804D084 - ldr r0, _0804C830 - add r0, sp - ldr r0, [r0] - movs r3, 0x1 - ldrsb r3, [r0, r3] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - bl sub_804D154 - mov r6, r8 - cmp r8, r5 - bge _0804C818 -_0804C7E8: - movs r1, 0 - mov r8, r1 - adds r2, r6, 0x1 - cmp r8, r4 - bge _0804C812 - lsls r0, r6, 4 - subs r0, r6 - movs r1, 0x1 - lsls r0, 5 - add r0, sp - adds r0, 0x10 - mov r8, r4 -_0804C800: - strb r1, [r0, 0x1B] - adds r0, 0x20 - movs r3, 0x1 - negs r3, r3 - add r8, r3 - mov r3, r8 - cmp r3, 0 - bne _0804C800 - mov r8, r4 -_0804C812: - adds r6, r2, 0 - cmp r6, r5 - blt _0804C7E8 -_0804C818: - movs r7, 0 - b _0804C836 - .align 2, 0 -_0804C81C: .4byte 0xffffe350 -_0804C820: .4byte 0x00001ca8 -_0804C824: .4byte 0x00001cac -_0804C828: .4byte 0x00001c30 -_0804C82C: .4byte 0x00001c6c -_0804C830: .4byte 0x00001cd4 -_0804C834: - adds r7, 0x1 -_0804C836: - cmp r7, 0x3F - bgt _0804C864 - adds r0, r5, 0 - bl DungeonRandInt - adds r6, r0, 0 - adds r0, r4, 0 - bl DungeonRandInt - mov r8, r0 - mov r0, r8 - muls r0, r5 - adds r0, r6 - mov r10, r0 - lsls r0, r6, 4 - subs r0, r6 - add r0, r8 - lsls r0, 5 - add r0, sp - adds r0, 0x10 - ldrb r0, [r0, 0xA] - cmp r0, 0 - beq _0804C834 -_0804C864: - ldr r0, _0804C8FC - add r0, sp - mov r9, r0 - ldr r7, _0804C900 - add r7, sp - str r7, [sp] - mov r1, r10 - str r1, [sp, 0x4] - ldr r2, _0804C904 - add r2, sp - ldr r2, [r2] - str r2, [sp, 0x8] - ldr r3, _0804C908 - add r3, sp - ldr r3, [r3] - str r3, [sp, 0xC] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - mov r3, r9 - bl sub_8050F90 - cmp r5, 0x1 - bne _0804C898 - cmp r4, 0x1 - beq _0804C8D0 -_0804C898: - mov r0, r8 - str r0, [sp] - ldr r1, _0804C90C - add r1, sp - ldr r1, [r1] - str r1, [sp, 0x4] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - adds r3, r6, 0 - bl sub_804D5F0 - str r7, [sp] - movs r0, 0x1 - str r0, [sp, 0x4] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - mov r3, r9 - bl sub_804D8C8 - str r7, [sp] - add r0, sp, 0x10 - adds r1, r5, 0 - adds r2, r4, 0 - mov r3, r9 - bl sub_804E590 -_0804C8D0: - lsls r0, r6, 4 - subs r0, r6 - lsls r0, 5 - add r0, sp - adds r0, 0x10 - mov r2, r8 - lsls r1, r2, 5 - adds r0, r1 - ldr r3, _0804C910 - add r3, sp - ldr r1, [r3] - bl sub_8051438 - ldr r3, _0804C914 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C8FC: .4byte 0x00001c30 -_0804C900: .4byte 0x00001c6c -_0804C904: .4byte 0x00001ca8 -_0804C908: .4byte 0x00001cac -_0804C90C: .4byte 0x00001cd4 -_0804C910: .4byte 0x00001cd0 -_0804C914: .4byte 0x00001cb0 - thumb_func_end sub_804C790 - - thumb_func_start sub_804C918 -sub_804C918: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - ldr r4, _0804C9C4 - add sp, r4 - mov r0, sp - movs r1, 0x1 - movs r2, 0x1 - bl sub_804D084 - mov r0, sp - movs r3, 0 - movs r2, 0x2 - strh r2, [r0] - mov r1, sp - movs r0, 0x36 - strh r0, [r1, 0x4] - mov r0, sp - strh r2, [r0, 0x2] - movs r0, 0x1E - strh r0, [r1, 0x6] - mov r0, sp - movs r1, 0x1 - strb r1, [r0, 0xA] - strb r1, [r0, 0xB] - strb r3, [r0, 0x8] - movs r1, 0 - ldrsh r5, [r0, r1] - movs r2, 0x4 - ldrsh r0, [r0, r2] - cmp r5, r0 - bge _0804C9A6 - mov r6, sp -_0804C95C: - movs r0, 0x2 - ldrsh r4, [r6, r0] - movs r1, 0x6 - ldrsh r0, [r6, r1] - adds r7, r5, 0x1 - cmp r4, r0 - bge _0804C99C - movs r2, 0 - mov r9, r2 - ldr r0, _0804C9C8 - mov r8, r0 -_0804C972: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r1, [r0] - mov r2, r8 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - mov r1, r9 - strb r1, [r0, 0x9] - adds r4, 0x1 - movs r2, 0x6 - ldrsh r0, [r6, r2] - cmp r4, r0 - blt _0804C972 -_0804C99C: - adds r5, r7, 0 - movs r1, 0x4 - ldrsh r0, [r6, r1] - cmp r5, r0 - blt _0804C95C -_0804C9A6: - ldr r3, _0804C9CC - mov r0, sp - movs r1, 0x1 - movs r2, 0x1 - bl sub_804EEE4 - movs r3, 0xE1 - lsls r3, 5 - add sp, r3 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804C9C4: .4byte 0xffffe3e0 -_0804C9C8: .4byte 0x0000fffc -_0804C9CC: .4byte 0x000003e7 - thumb_func_end sub_804C918 - - thumb_func_start sub_804C9D0 -sub_804C9D0: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0804CBB4 - add sp, r4 - movs r0, 0 - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - str r0, [r1] - ldr r1, _0804CBB8 - add r1, sp - movs r2, 0x2 - str r2, [r1] - movs r0, 0x1C - str r0, [r1, 0x4] - movs r0, 0x36 - str r0, [r1, 0x8] - ldr r1, _0804CBBC - add r1, sp - str r2, [r1] - movs r0, 0x1E - str r0, [r1, 0x4] - add r0, sp, 0x8 - movs r1, 0x2 - movs r2, 0x1 - bl sub_804D084 - movs r0, 0 - ldr r2, _0804CBB8 - add r2, sp - ldr r3, _0804CBC0 - add r3, sp - str r2, [r3] - ldr r4, _0804CBBC - add r4, sp - ldr r1, _0804CBC4 - add r1, sp - str r4, [r1] -_0804CA22: - movs r7, 0 - lsls r2, r0, 2 - ldr r3, _0804CBC8 - add r3, sp - str r2, [r3] - adds r4, r0, 0x1 - ldr r1, _0804CBCC - add r1, sp - str r4, [r1] - lsls r0, 5 - ldr r2, _0804CBD0 - add r2, sp - str r0, [r2] -_0804CA3C: - lsls r0, r7, 2 - ldr r3, _0804CBC0 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r1, [r0] - adds r4, r1, 0x1 - mov r10, r4 - ldr r2, _0804CBC4 - add r2, sp - ldr r2, [r2] - ldr r3, _0804CBC8 - add r3, sp - ldr r3, [r3] - adds r0, r2, r3 - ldr r2, [r0] - adds r4, r2, 0x1 - ldr r0, _0804CBD4 - add r0, sp - str r4, [r0] - adds r3, r7, 0x1 - mov r9, r3 - lsls r0, r3, 2 - ldr r4, _0804CBC0 - add r4, sp - ldr r4, [r4] - adds r0, r4, r0 - ldr r4, [r0] - subs r4, r1 - subs r4, 0x3 - ldr r1, _0804CBCC - add r1, sp - ldr r1, [r1] - lsls r0, r1, 2 - ldr r3, _0804CBC4 - add r3, sp - ldr r3, [r3] - adds r0, r3, r0 - ldr r5, [r0] - subs r5, r2 - subs r5, 0x3 - movs r0, 0xA - adds r1, r4, 0 - bl DungeonRandRange - mov r8, r0 - movs r0, 0x10 - adds r1, r5, 0 - bl DungeonRandRange - adds r6, r0, 0 - mov r0, r8 - subs r4, r0 - adds r0, r4, 0 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r10 - subs r5, r6 - adds r0, r5, 0 - bl DungeonRandInt - ldr r2, _0804CBD4 - add r2, sp - ldr r1, [r2] - adds r1, r0 - mov r10, r1 - mov r0, r8 - adds r3, r4, r0 - add r6, r10 - lsls r0, r7, 4 - subs r0, r7 - lsls r0, 5 - ldr r1, _0804CBD0 - add r1, sp - ldr r1, [r1] - adds r0, r1, r0 - add r0, sp - adds r0, 0x8 - movs r1, 0x1 - strb r1, [r0, 0xA] - strh r4, [r0] - strh r3, [r0, 0x4] - mov r2, r10 - strh r2, [r0, 0x2] - strh r6, [r0, 0x6] - mov r0, r9 - ldr r1, _0804CBD8 - add r1, sp - str r0, [r1] - movs r0, 0xE5 - lsls r0, 5 - add r0, sp - ldr r2, [r0] - adds r2, 0x1 - mov r9, r2 - cmp r4, r3 - bge _0804CB4E -_0804CB00: - mov r5, r10 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804CB48 - ldr r1, _0804CBDC - mov r8, r1 -_0804CB0C: - adds r0, r4, 0 - adds r1, r5, 0 - movs r2, 0xE6 - lsls r2, 5 - add r2, sp - str r3, [r2] - bl GetTileMut - ldrh r1, [r0] - mov r2, r8 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileMut - movs r1, 0xE5 - lsls r1, 5 - add r1, sp - ldrb r1, [r1] - strb r1, [r0, 0x9] - adds r5, 0x1 - movs r2, 0xE6 - lsls r2, 5 - add r2, sp - ldr r3, [r2] - cmp r5, r6 - blt _0804CB0C -_0804CB48: - adds r4, r7, 0 - cmp r4, r3 - blt _0804CB00 -_0804CB4E: - mov r3, r9 - movs r4, 0xE5 - lsls r4, 5 - add r4, sp - str r3, [r4] - ldr r0, _0804CBD8 - add r0, sp - ldr r7, [r0] - cmp r7, 0x1 - bgt _0804CB64 - b _0804CA3C -_0804CB64: - ldr r1, _0804CBCC - add r1, sp - ldr r0, [r1] - cmp r0, 0 - bgt _0804CB70 - b _0804CA22 -_0804CB70: - add r0, sp, 0x8 - movs r2, 0 - movs r1, 0x1 - strb r1, [r0, 0x16] - ldr r0, _0804CBE0 - add r0, sp - strb r1, [r0] - ldr r3, _0804CBB8 - add r3, sp - ldr r0, _0804CBBC - add r0, sp - str r0, [sp] - str r2, [sp, 0x4] - add r0, sp, 0x8 - movs r1, 0x2 - movs r2, 0x1 - bl sub_804D8C8 - ldr r3, _0804CBE4 - add r0, sp, 0x8 - movs r1, 0x2 - movs r2, 0x1 - bl sub_804EEE4 - ldr r3, _0804CBE8 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804CBB4: .4byte 0xffffe33c -_0804CBB8: .4byte 0x00001c28 -_0804CBBC: .4byte 0x00001c64 -_0804CBC0: .4byte 0x00001ca4 -_0804CBC4: .4byte 0x00001cac -_0804CBC8: .4byte 0x00001cb0 -_0804CBCC: .4byte 0x00001cbc -_0804CBD0: .4byte 0x00001cb4 -_0804CBD4: .4byte 0x00001ca8 -_0804CBD8: .4byte 0x00001cb8 -_0804CBDC: .4byte 0x0000fffc -_0804CBE0: .4byte 0x000001fd -_0804CBE4: .4byte 0x000003e7 -_0804CBE8: .4byte 0x00001cc4 - thumb_func_end sub_804C9D0 - - thumb_func_start sub_804CBEC -sub_804CBEC: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - str r3, [sp, 0xC] - cmp r3, 0 - bne _0804CC06 - b _0804D006 -_0804CC06: - movs r5, 0 - cmp r5, r3 - blt _0804CC0E - b _0804D006 -_0804CC0E: - ldr r0, [sp, 0x4] - bl DungeonRandInt - mov r9, r0 - ldr r0, [sp, 0x8] - bl DungeonRandInt - mov r10, r0 - lsls r0, 5 - mov r2, r9 - lsls r1, r2, 4 - subs r1, r2 - lsls r1, 5 - ldr r3, [sp] - adds r1, r3 - adds r4, r0, r1 - ldrb r0, [r4, 0xA] - adds r5, 0x1 - str r5, [sp, 0x18] - cmp r0, 0 - bne _0804CC3A - b _0804CFFC -_0804CC3A: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _0804CC42 - b _0804CFFC -_0804CC42: - ldrb r0, [r4, 0x8] - cmp r0, 0 - beq _0804CC4A - b _0804CFFC -_0804CC4A: - ldrb r0, [r4, 0x10] - cmp r0, 0 - beq _0804CC52 - b _0804CFFC -_0804CC52: - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x4 - ldrsh r1, [r4, r2] - bl DungeonRandRange - adds r7, r0, 0 - movs r3, 0x2 - ldrsh r0, [r4, r3] - movs r2, 0x6 - ldrsh r1, [r4, r2] - bl DungeonRandRange - adds r6, r0, 0 - movs r0, 0x4 - bl DungeonRandInt - lsls r0, 1 - mov r8, r0 - ldr r1, [sp, 0x8] - subs r1, 0x1 - movs r3, 0x2 - str r3, [sp, 0x10] - ldr r0, [sp, 0x4] - subs r0, 0x1 -_0804CC84: - mov r2, r8 - cmp r2, 0 - bne _0804CC92 - cmp r10, r1 - blt _0804CC92 - movs r3, 0x2 - mov r8, r3 -_0804CC92: - mov r2, r8 - cmp r2, 0x2 - bne _0804CCA0 - cmp r9, r0 - blt _0804CCA0 - movs r3, 0x4 - mov r8, r3 -_0804CCA0: - mov r2, r8 - cmp r2, 0x4 - bne _0804CCB0 - mov r3, r10 - cmp r3, 0 - bgt _0804CCB0 - movs r2, 0x6 - mov r8, r2 -_0804CCB0: - mov r3, r8 - cmp r3, 0x6 - bne _0804CCC0 - mov r2, r9 - cmp r2, 0 - bgt _0804CCC0 - movs r3, 0 - mov r8, r3 -_0804CCC0: - ldr r2, [sp, 0x10] - subs r2, 0x1 - str r2, [sp, 0x10] - cmp r2, 0 - bge _0804CC84 - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrb r5, [r0, 0x9] - ldr r1, _0804CCE0 - mov r3, r8 - lsls r0, r3, 2 - adds r4, r0, r1 - b _0804CCF0 - .align 2, 0 -_0804CCE0: .4byte gAdjacentTileOffsets -_0804CCE4: - movs r1, 0 - ldrsh r0, [r4, r1] - adds r7, r0 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r6, r0 -_0804CCF0: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r5, r0 - beq _0804CCE4 - ldr r1, _0804CD08 - mov r3, r8 - lsls r0, r3, 2 - adds r4, r0, r1 - b _0804CD18 - .align 2, 0 -_0804CD08: .4byte gAdjacentTileOffsets -_0804CD0C: - movs r1, 0 - ldrsh r0, [r4, r1] - adds r7, r0 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r6, r0 -_0804CD18: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - beq _0804CD0C - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x2 - bne _0804CD40 - b _0804CFFC -_0804CD40: - movs r3, 0 - subs r2, r7, 0x2 - adds r4, r7, 0x2 - b _0804CD4A -_0804CD48: - adds r2, 0x1 -_0804CD4A: - cmp r2, r4 - bgt _0804CD6C - subs r0, r6, 0x2 - adds r1, r6, 0x2 - b _0804CD56 -_0804CD54: - adds r0, 0x1 -_0804CD56: - cmp r0, r1 - bgt _0804CD68 - cmp r2, 0x37 - bhi _0804CD66 - cmp r0, 0 - blt _0804CD66 - cmp r0, 0x1F - ble _0804CD54 -_0804CD66: - movs r3, 0x1 -_0804CD68: - cmp r3, 0 - beq _0804CD48 -_0804CD6C: - cmp r3, 0 - beq _0804CD72 - b _0804CFFC -_0804CD72: - ldr r2, _0804CDD4 - mov r1, r8 - adds r1, 0x2 - movs r4, 0x6 - ands r1, r4 - lsls r1, 2 - adds r1, r2 - movs r3, 0 - ldrsh r0, [r1, r3] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - ldr r2, [sp, 0x1C] - cmp r0, 0x1 - bne _0804CDA2 - b _0804CFFC -_0804CDA2: - mov r1, r8 - subs r1, 0x2 - ands r1, r4 - lsls r1, 2 - adds r1, r2 - movs r2, 0 - ldrsh r0, [r1, r2] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CDC8 - b _0804CFFC -_0804CDC8: - movs r0, 0x3 - bl DungeonRandInt - adds r0, 0x3 - str r0, [sp, 0x10] - b _0804CFD4 - .align 2, 0 -_0804CDD4: .4byte gAdjacentTileOffsets -_0804CDD8: - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _0804CDEC - b _0804CFFC -_0804CDEC: - movs r0, 0x1 - str r0, [sp, 0x14] - adds r4, r7, 0x1 - adds r0, r4, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - mov r0, r10 - ands r0, r1 - mov r9, r4 - cmp r0, 0x1 - bne _0804CE32 - adds r5, r6, 0x1 - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTile - ldrh r0, [r0] - mov r4, r10 - ands r4, r0 - cmp r4, 0x1 - bne _0804CE32 - adds r0, r7, 0 - adds r1, r5, 0 - bl GetTile - ldrh r0, [r0] - mov r1, r10 - ands r0, r1 - eors r0, r4 - negs r1, r0 - orrs r1, r0 - lsrs r1, 31 - str r1, [sp, 0x14] -_0804CE32: - mov r0, r9 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CE70 - subs r4, r6, 0x1 - mov r0, r9 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CE70 - adds r0, r7, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CE70 - movs r2, 0 - str r2, [sp, 0x14] -_0804CE70: - subs r4, r7, 0x1 - adds r0, r4, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r2, 0x3 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEB6 - adds r5, r6, 0x1 - adds r0, r4, 0 - adds r1, r5, 0 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEB6 - adds r0, r7, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEB6 - movs r3, 0 - str r3, [sp, 0x14] -_0804CEB6: - adds r0, r4, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r2, 0x3 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEFA - subs r5, r6, 0x1 - adds r0, r4, 0 - adds r1, r5, 0 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEFA - adds r0, r7, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - ldr r2, [sp, 0x1C] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x1 - bne _0804CEFA - movs r0, 0 - str r0, [sp, 0x14] -_0804CEFA: - ldr r1, [sp, 0x14] - cmp r1, 0 - beq _0804CF16 - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTileMut - ldrh r1, [r0] - ldr r3, _0804D018 - adds r2, r3, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] -_0804CF16: - ldr r2, _0804D01C - movs r0, 0x2 - add r0, r8 - mov r9, r0 - movs r1, 0x6 - mov r10, r1 - mov r1, r9 - mov r3, r10 - ands r1, r3 - lsls r1, 2 - adds r1, r2 - movs r3, 0 - ldrsh r0, [r1, r3] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - str r2, [sp, 0x1C] - bl GetTile - ldrh r1, [r0] - movs r5, 0x3 - adds r0, r5, 0 - ands r0, r1 - ldr r2, [sp, 0x1C] - cmp r0, 0x1 - beq _0804CFFC - mov r4, r8 - subs r4, 0x2 - adds r1, r4, 0 - mov r0, r10 - ands r1, r0 - lsls r1, 2 - adds r1, r2 - movs r2, 0 - ldrsh r0, [r1, r2] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - adds r1, r6, r1 - bl GetTile - ldrh r1, [r0] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x1 - beq _0804CFFC - ldr r0, [sp, 0x10] - subs r0, 0x1 - str r0, [sp, 0x10] - cmp r0, 0 - bne _0804CFC0 - movs r0, 0x3 - bl DungeonRandInt - adds r0, 0x3 - str r0, [sp, 0x10] - movs r0, 0x64 - bl DungeonRandInt - mov r8, r4 - cmp r0, 0x31 - bgt _0804CF96 - mov r8, r9 -_0804CF96: - mov r1, r8 - mov r2, r10 - ands r1, r2 - mov r8, r1 - cmp r7, 0x1F - ble _0804CFAE - ldr r0, _0804D020 - ldrb r0, [r0] - cmp r0, 0x1 - bne _0804CFAE - cmp r1, 0x2 - beq _0804CFFC -_0804CFAE: - cmp r7, 0x2F - ble _0804CFC0 - ldr r0, _0804D020 - ldrb r0, [r0] - cmp r0, 0x2 - bne _0804CFC0 - mov r3, r8 - cmp r3, 0x2 - beq _0804CFFC -_0804CFC0: - ldr r0, _0804D01C - mov r2, r8 - lsls r1, r2, 2 - adds r1, r0 - movs r3, 0 - ldrsh r0, [r1, r3] - adds r7, r0 - movs r2, 0x2 - ldrsh r0, [r1, r2] - adds r6, r0 -_0804CFD4: - cmp r7, 0x1 - ble _0804CFFC - cmp r6, 0x1 - ble _0804CFFC - cmp r7, 0x36 - bgt _0804CFFC - cmp r6, 0x1E - bgt _0804CFFC - adds r0, r7, 0 - adds r1, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r3, 0x3 - mov r10, r3 - mov r0, r10 - ands r0, r1 - cmp r0, 0x1 - beq _0804CFFC - b _0804CDD8 -_0804CFFC: - ldr r5, [sp, 0x18] - ldr r0, [sp, 0xC] - cmp r5, r0 - bge _0804D006 - b _0804CC0E -_0804D006: - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804D018: .4byte 0x0000fffc -_0804D01C: .4byte gAdjacentTileOffsets -_0804D020: .4byte gUnknown_202F1AE - thumb_func_end sub_804CBEC - - thumb_func_start sub_804D024 -sub_804D024: - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r7, r0, 0 - mov r8, r1 - adds r5, r2, 0 - adds r6, r3, 0 - movs r4, 0 - cmp r4, r5 - bge _0804D04E - movs r0, 0x38 - adds r1, r5, 0 - bl __divsi3 - adds r2, r7, 0 - adds r1, r5, 0 -_0804D044: - stm r2!, {r4} - adds r4, r0 - subs r1, 0x1 - cmp r1, 0 - bne _0804D044 -_0804D04E: - lsls r0, r5, 2 - adds r0, r7 - str r4, [r0] - movs r4, 0 - lsls r5, r6, 2 - cmp r4, r6 - bge _0804D072 - movs r0, 0x20 - adds r1, r6, 0 - bl __divsi3 - mov r2, r8 - adds r1, r6, 0 -_0804D068: - stm r2!, {r4} - adds r4, r0 - subs r1, 0x1 - cmp r1, 0 - bne _0804D068 -_0804D072: - mov r1, r8 - adds r0, r5, r1 - str r4, [r0] - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804D024 - - thumb_func_start sub_804D084 -sub_804D084: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - mov r8, r0 - adds r5, r1, 0 - mov r9, r2 - movs r2, 0 - cmp r2, r5 - bge _0804D144 - lsrs r0, r5, 31 - adds r0, r5, r0 - asrs r0, 1 - str r0, [sp] - movs r3, 0 -_0804D0A6: - adds r0, r2, 0x1 - mov r10, r0 - mov r4, r9 - cmp r4, 0 - ble _0804D13E - ldr r6, _0804D0D8 - ldrb r6, [r6] - str r6, [sp, 0x4] - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - mov r4, r8 - adds r1, r0, r4 - movs r7, 0 - movs r6, 0x1 - mov r12, r6 - mov r4, r9 -_0804D0C8: - ldr r0, [sp, 0x4] - cmp r0, 0x1 - bne _0804D0DC - ldr r6, [sp] - cmp r2, r6 - blt _0804D0DC - strb r0, [r1, 0x8] - b _0804D102 - .align 2, 0 -_0804D0D8: .4byte gUnknown_202F1AE -_0804D0DC: - ldr r6, _0804D0FC - ldrb r0, [r6] - cmp r0, 0x2 - bne _0804D100 - lsls r0, r5, 1 - adds r0, r5 - cmp r0, 0 - bge _0804D0EE - adds r0, 0x3 -_0804D0EE: - asrs r0, 2 - cmp r2, r0 - blt _0804D100 - mov r0, r12 - strb r0, [r1, 0x8] - b _0804D102 - .align 2, 0 -_0804D0FC: .4byte gUnknown_202F1AE -_0804D100: - strb r3, [r1, 0x8] -_0804D102: - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - add r0, r8 - adds r0, r7, r0 - mov r6, r12 - strb r6, [r0, 0xA] - strb r3, [r0, 0xB] - strb r3, [r0, 0xF] - strb r3, [r0, 0xE] - strb r3, [r0, 0xC] - strb r3, [r0, 0x16] - strb r3, [r0, 0x15] - strb r3, [r0, 0x14] - strb r3, [r0, 0x13] - strb r3, [r0, 0x1A] - strb r3, [r0, 0x19] - strb r3, [r0, 0x18] - strb r3, [r0, 0x17] - strb r3, [r0, 0x9] - strb r3, [r0, 0x11] - strb r3, [r0, 0x10] - strb r3, [r0, 0x12] - strb r3, [r0, 0x1C] - strb r3, [r0, 0x1D] - adds r1, 0x20 - adds r7, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _0804D0C8 -_0804D13E: - mov r2, r10 - cmp r2, r5 - blt _0804D0A6 -_0804D144: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804D084 - - thumb_func_start sub_804D154 -sub_804D154: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x114 - str r0, [sp, 0x100] - mov r9, r1 - mov r8, r2 - adds r4, r3, 0 - movs r0, 0x3 - bl DungeonRandInt - adds r3, r0, 0 - cmp r4, 0 - bge _0804D17E - negs r4, r4 - b _0804D180 -_0804D178: - movs r0, 0x1 - strb r0, [r4, 0xA] - b _0804D2B6 -_0804D17E: - adds r4, r3 -_0804D180: - movs r3, 0 - mov r0, r8 - mov r2, r9 - muls r2, r0 - cmp r3, r4 - bge _0804D19A - movs r1, 0x1 -_0804D18E: - mov r5, sp - adds r0, r5, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, r4 - blt _0804D18E -_0804D19A: - cmp r3, 0xFF - bgt _0804D1AC - movs r1, 0 -_0804D1A0: - mov r6, sp - adds r0, r6, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, 0xFF - ble _0804D1A0 -_0804D1AC: - adds r5, r2, 0 - movs r6, 0x3F -_0804D1B0: - adds r0, r5, 0 - bl DungeonRandInt - adds r4, r0, 0 - adds r0, r5, 0 - bl DungeonRandInt - mov r1, sp - adds r2, r1, r4 - ldrb r3, [r2] - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - subs r6, 0x1 - cmp r6, 0 - bge _0804D1B0 - movs r3, 0 - ldr r0, _0804D24C - str r3, [r0] - movs r7, 0 - mov r12, r0 - cmp r7, r9 - bge _0804D262 -_0804D1E0: - movs r5, 0 - adds r4, r7, 0x1 - str r4, [sp, 0x104] - cmp r5, r8 - bge _0804D25C - lsls r2, r7, 4 - subs r2, r7 - lsls r2, 5 - ldr r6, [sp, 0x100] - adds r0, r2, r6 - mov r1, r9 - movs r4, 0x1 - ands r1, r4 - str r1, [sp, 0x110] - mov r1, r9 - subs r1, 0x1 - adds r0, 0x20 - mov r10, r0 - adds r0, r6, 0 - adds r0, 0x8 - adds r2, r0 - lsrs r0, r1, 31 - adds r1, r0 - asrs r1, 1 -_0804D210: - ldrb r4, [r2] - cmp r4, 0 - bne _0804D254 - mov r6, r12 - ldr r0, [r6] - cmp r0, 0x1F - ble _0804D220 - strb r4, [r2, 0x2] -_0804D220: - mov r6, sp - adds r0, r6, r3 - ldrb r0, [r0] - cmp r0, 0 - beq _0804D250 - movs r0, 0x1 - strb r0, [r2, 0x2] - mov r6, r12 - ldr r0, [r6] - adds r0, 0x1 - str r0, [r6] - ldr r0, [sp, 0x110] - cmp r0, 0 - beq _0804D252 - cmp r7, r1 - bne _0804D252 - cmp r5, 0x1 - bne _0804D252 - mov r6, r10 - strb r4, [r6, 0xA] - b _0804D252 - .align 2, 0 -_0804D24C: .4byte gUnknown_202F1CC -_0804D250: - strb r0, [r2, 0x2] -_0804D252: - adds r3, 0x1 -_0804D254: - adds r2, 0x20 - adds r5, 0x1 - cmp r5, r8 - blt _0804D210 -_0804D25C: - ldr r7, [sp, 0x104] - cmp r7, r9 - blt _0804D1E0 -_0804D262: - mov r1, r12 - ldr r0, [r1] - cmp r0, 0x1 - bgt _0804D2BC - movs r1, 0 - movs r2, 0 -_0804D26E: - movs r7, 0 - cmp r2, r9 - bge _0804D2AC - movs r6, 0 -_0804D276: - movs r5, 0 - cmp r5, r8 - bge _0804D2A4 - lsls r0, r6, 5 - ldr r3, [sp, 0x100] - adds r4, r0, r3 -_0804D282: - ldrb r0, [r4, 0x8] - cmp r0, 0 - bne _0804D29C - movs r0, 0x64 - str r1, [sp, 0x108] - str r2, [sp, 0x10C] - bl DungeonRandInt - ldr r1, [sp, 0x108] - ldr r2, [sp, 0x10C] - cmp r0, 0x3B - bgt _0804D29C - b _0804D178 -_0804D29C: - adds r4, 0x20 - adds r5, 0x1 - cmp r5, r8 - blt _0804D282 -_0804D2A4: - adds r6, 0xF - adds r7, 0x1 - cmp r7, r9 - blt _0804D276 -_0804D2AC: - cmp r2, 0 - bne _0804D2B6 - adds r1, 0x1 - cmp r1, 0xC7 - ble _0804D26E -_0804D2B6: - ldr r1, _0804D2CC - movs r0, 0 - strb r0, [r1] -_0804D2BC: - add sp, 0x114 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804D2CC: .4byte gUnknown_202F1AD - thumb_func_end sub_804D154 - - thumb_func_start sub_804D2D0 -sub_804D2D0: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x38 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - str r3, [sp, 0xC] - movs r0, 0 - str r0, [sp, 0x10] - movs r1, 0 - str r1, [sp, 0x14] - cmp r1, r2 - blt _0804D2F2 - b _0804D520 -_0804D2F2: - movs r2, 0 - mov r10, r2 - ldr r3, [sp, 0x14] - adds r3, 0x1 - str r3, [sp, 0x28] - ldr r4, [sp, 0x4] - cmp r10, r4 - blt _0804D304 - b _0804D514 -_0804D304: - ldr r5, [sp, 0x14] - lsls r5, 5 - str r5, [sp, 0x1C] -_0804D30A: - mov r1, r10 - lsls r0, r1, 2 - ldr r2, [sp, 0xC] - adds r0, r2 - ldr r3, [r0] - adds r4, r3, 0x2 - mov r9, r4 - ldr r5, [sp, 0x14] - lsls r1, r5, 2 - ldr r2, [sp, 0x58] - adds r1, r2 - ldr r2, [r1] - adds r4, r2, 0x2 - str r4, [sp, 0x18] - ldr r0, [r0, 0x4] - subs r0, r3 - subs r4, r0, 0x4 - ldr r0, [r1, 0x4] - subs r0, r2 - subs r0, 0x3 - mov r8, r0 - mov r5, r10 - lsls r1, r5, 4 - subs r0, r1, r5 - lsls r0, 5 - ldr r2, [sp] - adds r0, r2 - ldr r3, [sp, 0x1C] - adds r7, r3, r0 - ldrb r0, [r7, 0x8] - str r1, [sp, 0x2C] - adds r5, 0x1 - str r5, [sp, 0x24] - cmp r0, 0 - beq _0804D352 - b _0804D508 -_0804D352: - ldrb r0, [r7, 0xA] - cmp r0, 0 - bne _0804D35A - b _0804D48C -_0804D35A: - movs r0, 0x5 - adds r1, r4, 0 - bl DungeonRandRange - adds r6, r0, 0 - movs r0, 0x4 - mov r1, r8 - bl DungeonRandRange - adds r5, r0, 0 - movs r1, 0x1 - adds r0, r6, 0 - orrs r0, r1 - cmp r0, r4 - bge _0804D37A - adds r6, r0, 0 -_0804D37A: - adds r0, r5, 0 - orrs r0, r1 - cmp r0, r8 - bge _0804D384 - adds r5, r0, 0 -_0804D384: - lsls r0, r5, 1 - adds r0, r5 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - cmp r6, r0 - ble _0804D394 - adds r6, r0, 0 -_0804D394: - lsls r0, r6, 1 - adds r0, r6 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - cmp r5, r0 - ble _0804D3A4 - adds r5, r0, 0 -_0804D3A4: - subs r0, r4, r6 - bl DungeonRandInt - adds r4, r0, 0 - add r4, r9 - mov r1, r8 - subs r0, r1, r5 - bl DungeonRandInt - ldr r2, [sp, 0x18] - adds r0, r2 - mov r8, r0 - adds r3, r4, r6 - adds r6, r0, r5 - strh r4, [r7] - strh r3, [r7, 0x4] - mov r5, r8 - strh r5, [r7, 0x2] - strh r6, [r7, 0x6] - ldr r0, [sp, 0x10] - adds r0, 0x1 - str r0, [sp, 0x20] - cmp r4, r3 - bge _0804D412 -_0804D3D4: - mov r5, r8 - adds r7, r4, 0x1 - cmp r5, r6 - bge _0804D40C - ldr r1, _0804D484 - mov r9, r1 -_0804D3E0: - adds r0, r4, 0 - adds r1, r5, 0 - str r3, [sp, 0x34] - bl GetTileMut - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileMut - mov r1, sp - ldrb r1, [r1, 0x10] - strb r1, [r0, 0x9] - adds r5, 0x1 - ldr r3, [sp, 0x34] - cmp r5, r6 - blt _0804D3E0 -_0804D40C: - adds r4, r7, 0 - cmp r4, r3 - blt _0804D3D4 -_0804D412: - movs r5, 0x1 - movs r0, 0x64 - bl DungeonRandInt - movs r1, 0 - cmp r0, 0x4F - bgt _0804D422 - movs r1, 0x1 -_0804D422: - adds r4, r1, 0 - ldr r0, _0804D488 - ldr r0, [r0] - cmp r0, 0 - bne _0804D42E - movs r4, 0 -_0804D42E: - movs r0, 0x4 - ldr r2, [sp, 0x5C] - ands r0, r2 - cmp r0, 0 - bne _0804D43A - movs r5, 0 -_0804D43A: - cmp r5, 0 - beq _0804D466 - cmp r4, 0 - beq _0804D44E - movs r0, 0x64 - bl DungeonRandInt - cmp r0, 0x31 - ble _0804D466 - movs r4, 0 -_0804D44E: - cmp r5, 0 - beq _0804D466 - ldr r3, [sp, 0x2C] - mov r5, r10 - subs r0, r3, r5 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - ldr r2, [sp, 0x1C] - adds r0, r2, r0 - movs r1, 0x1 - strb r1, [r0, 0x1C] -_0804D466: - cmp r4, 0 - beq _0804D47E - ldr r3, [sp, 0x2C] - mov r4, r10 - subs r0, r3, r4 - lsls r0, 5 - ldr r5, [sp] - adds r0, r5 - ldr r1, [sp, 0x1C] - adds r0, r1, r0 - movs r1, 0x1 - strb r1, [r0, 0x1D] -_0804D47E: - ldr r2, [sp, 0x20] - str r2, [sp, 0x10] - b _0804D508 - .align 2, 0 -_0804D484: .4byte 0x0000fffc -_0804D488: .4byte gUnknown_202F1C8 -_0804D48C: - movs r1, 0x2 - movs r3, 0x4 - movs r6, 0x2 - movs r2, 0x4 - mov r5, r10 - cmp r5, 0 - bne _0804D49C - movs r1, 0x1 -_0804D49C: - ldr r0, [sp, 0x14] - cmp r0, 0 - bne _0804D4A4 - movs r6, 0x1 -_0804D4A4: - ldr r0, [sp, 0x4] - subs r0, 0x1 - cmp r10, r0 - bne _0804D4AE - movs r3, 0x2 -_0804D4AE: - ldr r0, [sp, 0x8] - subs r0, 0x1 - ldr r5, [sp, 0x14] - cmp r5, r0 - bne _0804D4BA - movs r2, 0x2 -_0804D4BA: - mov r5, r9 - adds r0, r5, r1 - adds r1, r5, r4 - subs r1, r3 - str r2, [sp, 0x30] - bl DungeonRandRange - adds r5, r0, 0 - ldr r1, [sp, 0x18] - adds r0, r1, r6 - add r1, r8 - ldr r2, [sp, 0x30] - subs r1, r2 - bl DungeonRandRange - adds r4, r0, 0 - strh r5, [r7] - adds r0, r5, 0x1 - strh r0, [r7, 0x4] - strh r4, [r7, 0x2] - adds r0, r4, 0x1 - strh r0, [r7, 0x6] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r1, [r0] - ldr r3, _0804D530 - adds r2, r3, 0 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0xFE - strb r1, [r0, 0x9] -_0804D508: - ldr r4, [sp, 0x24] - mov r10, r4 - ldr r5, [sp, 0x4] - cmp r10, r5 - bge _0804D514 - b _0804D30A -_0804D514: - ldr r0, [sp, 0x28] - str r0, [sp, 0x14] - ldr r1, [sp, 0x8] - cmp r0, r1 - bge _0804D520 - b _0804D2F2 -_0804D520: - add sp, 0x38 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804D530: .4byte 0x0000fffc - thumb_func_end sub_804D2D0 - - thumb_func_start sub_804D534 -sub_804D534: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - adds r3, r0, 0 - adds r7, r1, 0 - mov r9, r2 - movs r1, 0 - cmp r1, r9 - bge _0804D5A0 -_0804D54A: - adds r0, r1, 0x1 - mov r8, r0 - cmp r7, 0 - ble _0804D59A - lsls r1, 5 - adds r0, r1, 0 - adds r0, 0x8 - adds r4, r3, r0 - adds r5, r3, r1 - adds r6, r7, 0 -_0804D55E: - ldrb r0, [r4] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0x6] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0x2] - cmp r0, 0 - beq _0804D58C - ldrb r0, [r4, 0x14] - cmp r0, 0 - bne _0804D58C - ldrb r0, [r4, 0x15] - cmp r0, 0 - beq _0804D58C - adds r0, r5, 0 - str r3, [sp] - bl sub_804F694 - ldr r3, [sp] -_0804D58C: - movs r0, 0xF0 - lsls r0, 1 - adds r4, r0 - adds r5, r0 - subs r6, 0x1 - cmp r6, 0 - bne _0804D55E -_0804D59A: - mov r1, r8 - cmp r1, r9 - blt _0804D54A -_0804D5A0: - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804D534 - - thumb_func_start sub_804D5B0 -sub_804D5B0: - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x8 - mov r9, r0 - adds r4, r1, 0 - adds r5, r2, 0 - adds r6, r3, 0 - adds r0, r4, 0 - bl DungeonRandInt - mov r8, r0 - adds r0, r5, 0 - bl DungeonRandInt - str r0, [sp] - str r6, [sp, 0x4] - mov r0, r9 - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl sub_804D5F0 - add sp, 0x8 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_804D5B0 - - thumb_func_start sub_804D5F0 -sub_804D5F0: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - adds r7, r3, 0 - ldr r6, [sp, 0x40] - ldr r0, [sp, 0x44] - ldrb r0, [r0, 0x5] - str r0, [sp, 0xC] - movs r0, 0x4 - bl DungeonRandInt - adds r5, r0, 0 - movs r1, 0 - mov r10, r1 - ldr r2, [sp, 0xC] - cmp r10, r2 - blt _0804D620 - b _0804D726 -_0804D620: - lsls r4, r6, 5 - mov r9, r4 - lsls r0, r7, 4 - subs r0, r7 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - mov r8, r0 -_0804D630: - movs r0, 0x8 - bl DungeonRandInt - adds r4, r0, 0 - movs r0, 0x4 - bl DungeonRandInt - cmp r4, 0x3 - bgt _0804D644 - adds r5, r0, 0 -_0804D644: - mov r4, r10 - adds r4, 0x1 -_0804D648: - movs r1, 0 - movs r0, 0x3 - ands r0, r5 - cmp r0, 0x1 - beq _0804D670 - cmp r0, 0x1 - bgt _0804D65C - cmp r0, 0 - beq _0804D666 - b _0804D686 -_0804D65C: - cmp r0, 0x2 - beq _0804D676 - cmp r0, 0x3 - beq _0804D67C - b _0804D686 -_0804D666: - ldr r0, [sp, 0x4] - subs r0, 0x1 - cmp r7, r0 - blt _0804D68A - b _0804D684 -_0804D670: - cmp r6, 0 - bgt _0804D68A - b _0804D684 -_0804D676: - cmp r7, 0 - bgt _0804D68A - b _0804D684 -_0804D67C: - ldr r0, [sp, 0x8] - subs r0, 0x1 - cmp r6, r0 - blt _0804D68A -_0804D684: - adds r5, 0x1 -_0804D686: - cmp r1, 0 - beq _0804D648 -_0804D68A: - movs r1, 0x3 - ands r1, r5 - cmp r1, 0x1 - beq _0804D6C6 - cmp r1, 0x1 - bgt _0804D69C - cmp r1, 0 - beq _0804D6A6 - b _0804D71E -_0804D69C: - cmp r1, 0x2 - beq _0804D6E2 - cmp r1, 0x3 - beq _0804D704 - b _0804D71E -_0804D6A6: - mov r1, r9 - add r1, r8 - movs r0, 0xF0 - lsls r0, 1 - adds r2, r1, r0 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D71E - movs r0, 0x1 - strb r0, [r1, 0x16] - strb r0, [r2, 0x15] - movs r1, 0xF0 - lsls r1, 1 - add r8, r1 - adds r7, 0x1 - b _0804D71E -_0804D6C6: - mov r2, r9 - add r2, r8 - adds r3, r2, 0 - subs r3, 0x20 - ldrb r0, [r3, 0x8] - cmp r0, 0 - bne _0804D71E - strb r1, [r2, 0x13] - strb r1, [r3, 0x14] - movs r2, 0x20 - negs r2, r2 - add r9, r2 - subs r6, 0x1 - b _0804D71E -_0804D6E2: - mov r1, r9 - add r1, r8 - ldr r0, _0804D700 - adds r2, r1, r0 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D71E - movs r0, 0x1 - strb r0, [r1, 0x15] - strb r0, [r2, 0x16] - ldr r1, _0804D700 - add r8, r1 - subs r7, 0x1 - b _0804D71E - .align 2, 0 -_0804D700: .4byte 0xfffffe20 -_0804D704: - mov r1, r9 - add r1, r8 - adds r2, r1, 0 - adds r2, 0x20 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D71E - movs r0, 0x1 - strb r0, [r1, 0x14] - strb r0, [r2, 0x13] - movs r1, 0x20 - add r9, r1 - adds r6, 0x1 -_0804D71E: - mov r10, r4 - ldr r2, [sp, 0xC] - cmp r10, r2 - blt _0804D630 -_0804D726: - ldr r4, [sp, 0x44] - ldrb r0, [r4, 0xB] - cmp r0, 0 - beq _0804D730 - b _0804D8B8 -_0804D730: - movs r0, 0 - mov r9, r0 - movs r7, 0 - ldr r1, [sp, 0x4] - cmp r9, r1 - blt _0804D73E - b _0804D8B0 -_0804D73E: - movs r2, 0x1 - mov r8, r2 -_0804D742: - movs r6, 0 - adds r4, r7, 0x1 - str r4, [sp, 0x14] - ldr r0, [sp, 0x8] - cmp r6, r0 - blt _0804D750 - b _0804D8A6 -_0804D750: - lsls r1, r7, 4 - str r1, [sp, 0x10] - subs r0, r1, r7 - lsls r0, 5 - ldr r2, [sp] - adds r3, r0, r2 -_0804D75C: - lsls r0, r6, 5 - adds r2, r0, r3 - ldrb r1, [r2, 0x8] - adds r4, r0, 0 - adds r0, r6, 0x1 - str r0, [sp, 0x18] - cmp r1, 0 - beq _0804D76E - b _0804D89C -_0804D76E: - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804D776 - b _0804D89C -_0804D776: - ldrb r0, [r2, 0x13] - negs r1, r0 - orrs r1, r0 - lsrs r1, 31 - ldrb r0, [r2, 0x14] - cmp r0, 0 - beq _0804D786 - adds r1, 0x1 -_0804D786: - ldrb r0, [r2, 0x15] - cmp r0, 0 - beq _0804D78E - adds r1, 0x1 -_0804D78E: - ldrb r0, [r2, 0x16] - cmp r0, 0 - beq _0804D796 - adds r1, 0x1 -_0804D796: - cmp r1, 0x1 - beq _0804D79C - b _0804D89C -_0804D79C: - movs r0, 0x4 - str r3, [sp, 0x1C] - bl DungeonRandInt - adds r5, r0, 0 - movs r2, 0 - mov r10, r2 - ldr r1, [sp, 0x10] - subs r0, r1, r7 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - adds r1, r4, r0 - ldr r3, [sp, 0x1C] -_0804D7B8: - movs r0, 0x3 - ands r0, r5 - cmp r0, 0x1 - beq _0804D7E0 - cmp r0, 0x1 - bgt _0804D7CA - cmp r0, 0 - beq _0804D7D4 - b _0804D800 -_0804D7CA: - cmp r0, 0x2 - beq _0804D7E8 - cmp r0, 0x3 - beq _0804D7F0 - b _0804D800 -_0804D7D4: - ldr r0, [sp, 0x4] - subs r0, 0x1 - cmp r7, r0 - bge _0804D7FE - ldrb r0, [r1, 0x16] - b _0804D7FA -_0804D7E0: - cmp r6, 0 - ble _0804D7FE - ldrb r0, [r1, 0x13] - b _0804D7FA -_0804D7E8: - cmp r7, 0 - ble _0804D7FE - ldrb r0, [r1, 0x15] - b _0804D7FA -_0804D7F0: - ldr r0, [sp, 0x8] - subs r0, 0x1 - cmp r6, r0 - bge _0804D7FE - ldrb r0, [r1, 0x14] -_0804D7FA: - cmp r0, 0 - beq _0804D80E -_0804D7FE: - adds r5, 0x1 -_0804D800: - mov r0, r10 - cmp r0, 0 - bne _0804D80E - adds r2, 0x1 - cmp r2, 0x7 - ble _0804D7B8 - b _0804D89C -_0804D80E: - movs r2, 0x3 - ands r2, r5 - cmp r2, 0x1 - beq _0804D844 - cmp r2, 0x1 - bgt _0804D820 - cmp r2, 0 - beq _0804D82A - b _0804D89C -_0804D820: - cmp r2, 0x2 - beq _0804D85C - cmp r2, 0x3 - beq _0804D880 - b _0804D89C -_0804D82A: - adds r1, r4, r3 - movs r4, 0xF0 - lsls r4, 1 - adds r2, r1, r4 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804D89C - mov r0, r8 - strb r0, [r1, 0x16] - strb r0, [r2, 0x15] - movs r1, 0x1 - mov r9, r1 - b _0804D89C -_0804D844: - adds r1, r4, r3 - movs r4, 0xF0 - lsls r4, 1 - adds r0, r1, r4 - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _0804D89C - strb r2, [r1, 0x13] - adds r0, r1, 0 - subs r0, 0x20 - strb r2, [r0, 0x14] - b _0804D898 -_0804D85C: - adds r1, r4, r3 - movs r2, 0xF0 - lsls r2, 1 - adds r0, r1, r2 - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _0804D89C - mov r4, r8 - strb r4, [r1, 0x15] - ldr r2, _0804D87C - adds r0, r1, r2 - strb r4, [r0, 0x16] - movs r4, 0x1 - mov r9, r4 - b _0804D89C - .align 2, 0 -_0804D87C: .4byte 0xfffffe20 -_0804D880: - adds r1, r4, r3 - movs r2, 0xF0 - lsls r2, 1 - adds r0, r1, r2 - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _0804D89C - mov r4, r8 - strb r4, [r1, 0x14] - adds r0, r1, 0 - adds r0, 0x20 - strb r4, [r0, 0x13] -_0804D898: - movs r0, 0x1 - mov r9, r0 -_0804D89C: - ldr r6, [sp, 0x18] - ldr r1, [sp, 0x8] - cmp r6, r1 - bge _0804D8A6 - b _0804D75C -_0804D8A6: - ldr r7, [sp, 0x14] - ldr r2, [sp, 0x4] - cmp r7, r2 - bge _0804D8B0 - b _0804D742 -_0804D8B0: - mov r4, r9 - cmp r4, 0 - beq _0804D8B8 - b _0804D730 -_0804D8B8: - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804D5F0 - - thumb_func_start sub_804D8C8 -sub_804D8C8: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x58 - str r0, [sp, 0xC] - str r1, [sp, 0x10] - str r2, [sp, 0x14] - str r3, [sp, 0x18] - ldr r0, [sp, 0x7C] - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x1C] - movs r0, 0 - str r0, [sp, 0x20] - cmp r0, r1 - bge _0804D968 -_0804D8EC: - movs r1, 0 - mov r10, r1 - ldr r2, [sp, 0x20] - adds r2, 0x1 - str r2, [sp, 0x38] - ldr r3, [sp, 0x14] - cmp r10, r3 - bge _0804D95E - ldr r4, [sp, 0x20] - lsls r1, r4, 4 - subs r1, r4 - movs r3, 0 - lsls r1, 5 - ldr r0, [sp, 0xC] - adds r0, 0x8 - adds r1, r0 -_0804D90C: - ldrb r2, [r1] - cmp r2, 0 - beq _0804D91C - strb r3, [r1, 0xF] - strb r3, [r1, 0x10] - strb r3, [r1, 0x11] - strb r3, [r1, 0x12] - b _0804D952 -_0804D91C: - ldr r5, [sp, 0x20] - cmp r5, 0 - bgt _0804D924 - strb r2, [r1, 0xD] -_0804D924: - mov r6, r10 - cmp r6, 0 - bgt _0804D92C - strb r2, [r1, 0xB] -_0804D92C: - ldr r0, [sp, 0x10] - subs r0, 0x1 - ldr r7, [sp, 0x20] - cmp r7, r0 - blt _0804D938 - strb r2, [r1, 0xE] -_0804D938: - ldr r0, [sp, 0x14] - subs r0, 0x1 - cmp r10, r0 - blt _0804D942 - strb r2, [r1, 0xC] -_0804D942: - ldrb r0, [r1, 0xB] - strb r0, [r1, 0xF] - ldrb r0, [r1, 0xC] - strb r0, [r1, 0x10] - ldrb r0, [r1, 0xD] - strb r0, [r1, 0x11] - ldrb r0, [r1, 0xE] - strb r0, [r1, 0x12] -_0804D952: - adds r1, 0x20 - movs r0, 0x1 - add r10, r0 - ldr r2, [sp, 0x14] - cmp r10, r2 - blt _0804D90C -_0804D95E: - ldr r3, [sp, 0x38] - str r3, [sp, 0x20] - ldr r4, [sp, 0x10] - cmp r3, r4 - blt _0804D8EC -_0804D968: - movs r5, 0 - str r5, [sp, 0x20] - ldr r6, [sp, 0x10] - cmp r5, r6 - blt _0804D974 - b _0804DBC6 -_0804D974: - movs r7, 0 - mov r10, r7 - ldr r0, [sp, 0x20] - adds r0, 0x1 - str r0, [sp, 0x38] - ldr r1, [sp, 0x14] - cmp r10, r1 - blt _0804D986 - b _0804DBBA -_0804D986: - ldr r2, [sp, 0x20] - lsls r2, 4 - str r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r1, r2, r3 - lsls r1, 5 - movs r4, 0 - str r4, [sp, 0x48] - ldr r5, [sp, 0xC] - movs r6, 0xF0 - lsls r6, 1 - adds r0, r5, r6 - adds r0, r1 - mov r8, r0 - adds r5, r1, r5 - ldr r7, [sp, 0xC] - ldr r2, _0804DA0C - adds r0, r7, r2 - adds r7, r1, r0 - ldr r3, [sp, 0x78] - str r3, [sp, 0x4C] - ldr r0, [sp, 0xC] - adds r0, 0x20 - adds r0, r1, r0 - str r0, [sp, 0x50] - ldr r0, [sp, 0xC] - subs r0, 0x20 - adds r6, r1, r0 - ldr r4, [sp, 0x20] - lsls r0, r4, 2 - ldr r1, [sp, 0x18] - adds r0, r1 - str r0, [sp, 0x24] -_0804D9C8: - ldr r2, [sp, 0x20] - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - ldr r3, [sp, 0xC] - adds r0, r3 - ldr r1, [sp, 0x48] - adds r4, r1, r0 - ldrb r0, [r4, 0x8] - cmp r0, 0 - beq _0804D9E0 - b _0804DB92 -_0804D9E0: - ldrb r0, [r4, 0xA] - cmp r0, 0 - beq _0804DA10 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r0, 0x1 - movs r3, 0x4 - ldrsh r1, [r4, r3] - subs r1, 0x1 - bl DungeonRandRange - mov r9, r0 - movs r1, 0x2 - ldrsh r0, [r4, r1] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r4, r0, 0 - b _0804DA1A - .align 2, 0 -_0804DA0C: .4byte 0xfffffe20 -_0804DA10: - movs r0, 0 - ldrsh r3, [r4, r0] - mov r9, r3 - movs r1, 0x2 - ldrsh r4, [r4, r1] -_0804DA1A: - ldrb r0, [r5, 0x17] - cmp r0, 0 - beq _0804DA74 - ldrb r0, [r6, 0x8] - cmp r0, 0 - bne _0804DA68 - ldrb r0, [r6, 0xA] - cmp r0, 0 - beq _0804DA40 - movs r2, 0 - ldrsh r0, [r6, r2] - adds r0, 0x1 - movs r3, 0x4 - ldrsh r1, [r6, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r2, r0, 0 - b _0804DA44 -_0804DA40: - movs r0, 0 - ldrsh r2, [r6, r0] -_0804DA44: - movs r3, 0x2 - ldrsh r1, [r5, r3] - movs r0, 0x6 - ldrsh r3, [r6, r0] - subs r3, 0x1 - mov r12, r3 - movs r3, 0x1 - str r3, [sp] - ldr r3, [sp, 0x24] - ldr r0, [r3] - str r0, [sp, 0x4] - ldr r3, [sp, 0x4C] - ldr r0, [r3] - str r0, [sp, 0x8] - mov r0, r9 - mov r3, r12 - bl sub_804E328 -_0804DA68: - movs r0, 0 - strb r0, [r5, 0x17] - strb r0, [r6, 0x18] - movs r1, 0x1 - strb r1, [r5, 0xB] - strb r1, [r6, 0xB] -_0804DA74: - ldrb r0, [r5, 0x18] - cmp r0, 0 - beq _0804DAD4 - ldr r2, [sp, 0x50] - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804DAC6 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804DA9C - movs r3, 0x20 - ldrsh r0, [r5, r3] - adds r0, 0x1 - movs r2, 0x24 - ldrsh r1, [r5, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r2, r0, 0 - b _0804DAA0 -_0804DA9C: - movs r3, 0x20 - ldrsh r2, [r5, r3] -_0804DAA0: - movs r0, 0x6 - ldrsh r1, [r5, r0] - subs r1, 0x1 - movs r0, 0x22 - ldrsh r3, [r5, r0] - mov r12, r3 - movs r3, 0x1 - str r3, [sp] - ldr r3, [sp, 0x24] - ldr r0, [r3] - str r0, [sp, 0x4] - ldr r3, [sp, 0x4C] - ldr r0, [r3, 0x4] - subs r0, 0x1 - str r0, [sp, 0x8] - mov r0, r9 - mov r3, r12 - bl sub_804E328 -_0804DAC6: - movs r0, 0 - strb r0, [r5, 0x18] - ldr r1, [sp, 0x50] - strb r0, [r1, 0x17] - movs r2, 0x1 - strb r2, [r5, 0xB] - strb r2, [r1, 0xB] -_0804DAD4: - ldrb r0, [r5, 0x19] - cmp r0, 0 - beq _0804DB2E - ldrb r0, [r7, 0x8] - cmp r0, 0 - bne _0804DB22 - ldrb r0, [r7, 0xA] - cmp r0, 0 - beq _0804DAFA - movs r3, 0x2 - ldrsh r0, [r7, r3] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r7, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804DAFE -_0804DAFA: - movs r0, 0x2 - ldrsh r3, [r7, r0] -_0804DAFE: - movs r1, 0 - ldrsh r0, [r5, r1] - movs r1, 0 - ldrsh r2, [r7, r1] - subs r2, 0x1 - mov r9, r2 - movs r2, 0 - str r2, [sp] - ldr r2, [sp, 0x24] - ldr r1, [r2] - str r1, [sp, 0x4] - ldr r2, [sp, 0x4C] - ldr r1, [r2] - str r1, [sp, 0x8] - adds r1, r4, 0 - mov r2, r9 - bl sub_804E328 -_0804DB22: - movs r3, 0 - strb r3, [r5, 0x19] - strb r3, [r7, 0x1A] - movs r0, 0x1 - strb r0, [r5, 0xB] - strb r0, [r7, 0xB] -_0804DB2E: - ldrb r0, [r5, 0x1A] - cmp r0, 0 - beq _0804DB92 - mov r1, r8 - ldrb r0, [r1, 0x8] - cmp r0, 0 - bne _0804DB84 - ldrb r0, [r1, 0xA] - cmp r0, 0 - beq _0804DB56 - movs r2, 0x2 - ldrsh r0, [r1, r2] - adds r0, 0x1 - movs r3, 0x6 - ldrsh r1, [r1, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804DB5C -_0804DB56: - mov r0, r8 - movs r1, 0x2 - ldrsh r3, [r0, r1] -_0804DB5C: - movs r2, 0x4 - ldrsh r0, [r5, r2] - subs r0, 0x1 - mov r1, r8 - movs r2, 0 - ldrsh r1, [r1, r2] - mov r9, r1 - movs r1, 0 - str r1, [sp] - ldr r2, [sp, 0x24] - ldr r1, [r2, 0x4] - subs r1, 0x1 - str r1, [sp, 0x4] - ldr r2, [sp, 0x4C] - ldr r1, [r2] - str r1, [sp, 0x8] - adds r1, r4, 0 - mov r2, r9 - bl sub_804E328 -_0804DB84: - movs r3, 0 - strb r3, [r5, 0x1A] - mov r4, r8 - strb r3, [r4, 0x19] - movs r0, 0x1 - strb r0, [r5, 0xB] - strb r0, [r4, 0xB] -_0804DB92: - ldr r1, [sp, 0x48] - adds r1, 0x20 - str r1, [sp, 0x48] - movs r2, 0x20 - add r8, r2 - adds r5, 0x20 - adds r7, 0x20 - ldr r3, [sp, 0x4C] - adds r3, 0x4 - str r3, [sp, 0x4C] - ldr r4, [sp, 0x50] - adds r4, 0x20 - str r4, [sp, 0x50] - adds r6, 0x20 - movs r0, 0x1 - add r10, r0 - ldr r1, [sp, 0x14] - cmp r10, r1 - bge _0804DBBA - b _0804D9C8 -_0804DBBA: - ldr r2, [sp, 0x38] - str r2, [sp, 0x20] - ldr r3, [sp, 0x10] - cmp r2, r3 - bge _0804DBC6 - b _0804D974 -_0804DBC6: - ldr r4, [sp, 0x1C] - cmp r4, 0 - beq _0804DBCE - b _0804E026 -_0804DBCE: - movs r5, 0 - str r5, [sp, 0x20] - ldr r6, [sp, 0x10] - cmp r5, r6 - blt _0804DBDA - b _0804E026 -_0804DBDA: - movs r7, 0 - mov r10, r7 - ldr r0, [sp, 0x20] - adds r0, 0x1 - str r0, [sp, 0x38] - ldr r1, [sp, 0x14] - cmp r10, r1 - blt _0804DBEC - b _0804E018 -_0804DBEC: - movs r0, 0x64 - bl DungeonRandInt - mov r2, r10 - adds r2, 0x1 - str r2, [sp, 0x3C] - cmp r0, 0x4 - ble _0804DBFE - b _0804E00C -_0804DBFE: - mov r3, r10 - lsls r1, r3, 5 - ldr r4, [sp, 0x20] - lsls r2, r4, 4 - subs r0, r2, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - adds r4, r1, r0 - ldrb r0, [r4, 0x8] - str r1, [sp, 0x44] - str r2, [sp, 0x40] - cmp r0, 0 - beq _0804DC1C - b _0804E00C -_0804DC1C: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _0804DC24 - b _0804E00C -_0804DC24: - ldrb r0, [r4, 0x12] - cmp r0, 0 - beq _0804DC2C - b _0804E00C -_0804DC2C: - ldrb r0, [r4, 0x9] - cmp r0, 0 - beq _0804DC34 - b _0804E00C -_0804DC34: - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804DC3C - b _0804E00C -_0804DC3C: - movs r0, 0x4 - bl DungeonRandInt - cmp r0, 0x1 - bne _0804DC48 - b _0804DD50 -_0804DC48: - cmp r0, 0x1 - bgt _0804DC52 - cmp r0, 0 - beq _0804DC60 - b _0804E00C -_0804DC52: - cmp r0, 0x2 - bne _0804DC58 - b _0804DE3C -_0804DC58: - cmp r0, 0x3 - bne _0804DC5E - b _0804DF30 -_0804DC5E: - b _0804E00C -_0804DC60: - ldr r6, [sp, 0x20] - cmp r6, 0 - bgt _0804DC68 - b _0804E00C -_0804DC68: - ldr r7, _0804DD48 - adds r2, r4, r7 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DC74 - b _0804E00C -_0804DC74: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DC7C - b _0804E00C -_0804DC7C: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DC84 - b _0804E00C -_0804DC84: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DC8C - b _0804E00C -_0804DC8C: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DC94 - b _0804E00C -_0804DC94: - movs r1, 0 - ldrsh r0, [r2, r1] - str r0, [sp, 0x28] - ldrh r3, [r4, 0x2] - movs r5, 0x2 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x2] - movs r6, 0x2 - ldrsh r0, [r2, r6] - cmp r1, r0 - ble _0804DCAC - adds r3, r5, 0 -_0804DCAC: - lsls r0, r3, 16 - asrs r0, 16 - mov r9, r0 - movs r0, 0x4 - ldrsh r7, [r4, r0] - mov r10, r7 - ldrh r3, [r4, 0x6] - movs r5, 0x6 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x6] - movs r6, 0x6 - ldrsh r0, [r2, r6] - cmp r1, r0 - bge _0804DCCA - adds r3, r5, 0 -_0804DCCA: - lsls r0, r3, 16 - asrs r7, r0, 16 - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r8, r0 - ldr r5, [sp, 0x28] - cmp r5, r10 - bge _0804DD16 -_0804DCE4: - mov r4, r9 - adds r6, r5, 0x1 - cmp r9, r7 - bge _0804DD10 - ldr r0, _0804DD4C - adds r3, r0, 0 -_0804DCF0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileMut - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r8 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DCF0 -_0804DD10: - adds r5, r6, 0 - cmp r5, r10 - blt _0804DCE4 -_0804DD16: - ldr r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r0, r2, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x44] - adds r0, r5, r0 - ldr r6, _0804DD48 - adds r3, r0, r6 - mov r1, sp - ldrh r1, [r1, 0x28] - strh r1, [r3] - mov r2, r10 - strh r2, [r3, 0x4] - mov r4, r9 - strh r4, [r3, 0x2] - strh r7, [r3, 0x6] - movs r5, 0x1 - strb r5, [r0, 0x12] - strb r5, [r3, 0x12] - movs r6, 0 - strb r6, [r0, 0xB] - strb r5, [r0, 0x11] - b _0804E00C - .align 2, 0 -_0804DD48: .4byte 0xfffffe20 -_0804DD4C: .4byte 0x0000fffc -_0804DD50: - mov r7, r10 - cmp r7, 0 - bgt _0804DD58 - b _0804E00C -_0804DD58: - adds r2, r4, 0 - subs r2, 0x20 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DD64 - b _0804E00C -_0804DD64: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DD6C - b _0804E00C -_0804DD6C: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DD74 - b _0804E00C -_0804DD74: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DD7C - b _0804E00C -_0804DD7C: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DD84 - b _0804E00C -_0804DD84: - ldrh r3, [r4] - movs r0, 0 - ldrsh r1, [r4, r0] - ldrh r5, [r2] - movs r6, 0 - ldrsh r0, [r2, r6] - cmp r1, r0 - ble _0804DD96 - adds r3, r5, 0 -_0804DD96: - lsls r0, r3, 16 - asrs r0, 16 - str r0, [sp, 0x2C] - movs r0, 0x2 - ldrsh r7, [r2, r0] - mov r10, r7 - ldrh r3, [r4, 0x4] - movs r5, 0x4 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x4] - movs r6, 0x4 - ldrsh r0, [r2, r6] - cmp r1, r0 - bge _0804DDB4 - adds r3, r5, 0 -_0804DDB4: - lsls r0, r3, 16 - asrs r0, 16 - mov r8, r0 - movs r0, 0x6 - ldrsh r7, [r4, r0] - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r9, r0 - ldr r5, [sp, 0x2C] - cmp r5, r8 - bge _0804DE06 -_0804DDD4: - mov r4, r10 - adds r6, r5, 0x1 - cmp r10, r7 - bge _0804DE00 - ldr r0, _0804DE38 - adds r3, r0, 0 -_0804DDE0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileMut - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r9 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DDE0 -_0804DE00: - adds r5, r6, 0 - cmp r5, r8 - blt _0804DDD4 -_0804DE06: - ldr r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r0, r2, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x44] - adds r0, r5, r0 - adds r3, r0, 0 - subs r3, 0x20 - mov r6, sp - ldrh r6, [r6, 0x2C] - strh r6, [r3] - mov r1, r8 - strh r1, [r3, 0x4] - mov r2, r10 - strh r2, [r3, 0x2] - strh r7, [r3, 0x6] - movs r4, 0x1 - strb r4, [r0, 0x12] - strb r4, [r3, 0x12] - movs r5, 0 - strb r5, [r0, 0xB] - strb r4, [r0, 0x11] - b _0804E00C - .align 2, 0 -_0804DE38: .4byte 0x0000fffc -_0804DE3C: - ldr r0, [sp, 0x10] - subs r0, 0x2 - ldr r6, [sp, 0x20] - cmp r6, r0 - ble _0804DE48 - b _0804E00C -_0804DE48: - movs r7, 0xF0 - lsls r7, 1 - adds r2, r4, r7 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DE56 - b _0804E00C -_0804DE56: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DE5E - b _0804E00C -_0804DE5E: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DE66 - b _0804E00C -_0804DE66: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DE6E - b _0804E00C -_0804DE6E: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DE76 - b _0804E00C -_0804DE76: - movs r1, 0 - ldrsh r0, [r4, r1] - str r0, [sp, 0x30] - ldrh r3, [r2, 0x2] - movs r5, 0x2 - ldrsh r1, [r2, r5] - ldrh r5, [r4, 0x2] - movs r6, 0x2 - ldrsh r0, [r4, r6] - cmp r1, r0 - ble _0804DE8E - adds r3, r5, 0 -_0804DE8E: - lsls r0, r3, 16 - asrs r0, 16 - mov r9, r0 - movs r0, 0x4 - ldrsh r7, [r2, r0] - mov r10, r7 - ldrh r3, [r2, 0x6] - movs r5, 0x6 - ldrsh r1, [r2, r5] - ldrh r2, [r4, 0x6] - movs r6, 0x6 - ldrsh r0, [r4, r6] - cmp r1, r0 - bge _0804DEAC - adds r3, r2, 0 -_0804DEAC: - lsls r0, r3, 16 - asrs r7, r0, 16 - movs r0, 0x2 - ldrsh r1, [r4, r0] - ldr r0, [sp, 0x30] - bl GetTile - ldrb r0, [r0, 0x9] - mov r8, r0 - ldr r5, [sp, 0x30] - cmp r5, r10 - bge _0804DEF6 -_0804DEC4: - mov r4, r9 - adds r6, r5, 0x1 - cmp r9, r7 - bge _0804DEF0 - ldr r1, _0804DF2C - adds r3, r1, 0 -_0804DED0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileMut - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r2, r8 - strb r2, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DED0 -_0804DEF0: - adds r5, r6, 0 - cmp r5, r10 - blt _0804DEC4 -_0804DEF6: - ldr r3, [sp, 0x40] - ldr r4, [sp, 0x20] - subs r0, r3, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - ldr r6, [sp, 0x44] - adds r0, r6, r0 - mov r1, sp - ldrh r1, [r1, 0x30] - strh r1, [r0] - mov r2, r10 - strh r2, [r0, 0x4] - mov r3, r9 - strh r3, [r0, 0x2] - strh r7, [r0, 0x6] - movs r4, 0xF0 - lsls r4, 1 - adds r1, r0, r4 - movs r5, 0x1 - strb r5, [r1, 0x12] - strb r5, [r0, 0x12] - movs r6, 0 - strb r6, [r1, 0xB] - strb r5, [r1, 0x11] - b _0804E00C - .align 2, 0 -_0804DF2C: .4byte 0x0000fffc -_0804DF30: - ldr r0, [sp, 0x14] - subs r0, 0x2 - cmp r10, r0 - bgt _0804E00C - adds r3, r4, 0 - adds r3, 0x20 - ldrb r0, [r3, 0xB] - cmp r0, 0 - beq _0804E00C - ldrb r0, [r3, 0x8] - cmp r0, 0 - bne _0804E00C - ldrb r0, [r3, 0xA] - cmp r0, 0 - beq _0804E00C - ldrb r0, [r3, 0x9] - cmp r0, 0 - bne _0804E00C - ldrb r0, [r3, 0x12] - cmp r0, 0 - bne _0804E00C - ldrh r2, [r4, 0x20] - movs r7, 0x20 - ldrsh r1, [r4, r7] - ldrh r5, [r4] - movs r6, 0 - ldrsh r0, [r4, r6] - cmp r1, r0 - ble _0804DF6C - adds r2, r5, 0 -_0804DF6C: - lsls r0, r2, 16 - asrs r0, 16 - str r0, [sp, 0x34] - movs r7, 0x2 - ldrsh r6, [r4, r7] - ldrh r2, [r3, 0x4] - movs r0, 0x4 - ldrsh r1, [r3, r0] - ldrh r5, [r4, 0x4] - movs r7, 0x4 - ldrsh r0, [r4, r7] - cmp r1, r0 - bge _0804DF88 - adds r2, r5, 0 -_0804DF88: - lsls r0, r2, 16 - asrs r0, 16 - mov r8, r0 - movs r0, 0x6 - ldrsh r3, [r3, r0] - movs r1, 0 - ldrsh r0, [r4, r1] - adds r1, r6, 0 - str r3, [sp, 0x54] - bl GetTile - ldrb r0, [r0, 0x9] - mov r10, r0 - ldr r5, [sp, 0x34] - ldr r3, [sp, 0x54] - cmp r5, r8 - bge _0804DFDE -_0804DFAA: - adds r4, r6, 0 - adds r7, r5, 0x1 - cmp r6, r3 - bge _0804DFD8 - ldr r2, _0804E038 - mov r9, r2 -_0804DFB6: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileMut - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r10 - strb r1, [r0, 0x9] - adds r4, 0x1 - ldr r3, [sp, 0x54] - cmp r4, r3 - blt _0804DFB6 -_0804DFD8: - adds r5, r7, 0 - cmp r5, r8 - blt _0804DFAA -_0804DFDE: - ldr r2, [sp, 0x40] - ldr r4, [sp, 0x20] - subs r0, r2, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - ldr r7, [sp, 0x44] - adds r0, r7, r0 - mov r1, sp - ldrh r1, [r1, 0x34] - strh r1, [r0] - mov r2, r8 - strh r2, [r0, 0x4] - strh r6, [r0, 0x2] - strh r3, [r0, 0x6] - adds r1, r0, 0 - adds r1, 0x20 - movs r3, 0x1 - strb r3, [r1, 0x12] - strb r3, [r0, 0x12] - movs r4, 0 - strb r4, [r1, 0xB] - strb r3, [r1, 0x11] -_0804E00C: - ldr r5, [sp, 0x3C] - mov r10, r5 - ldr r6, [sp, 0x14] - cmp r10, r6 - bge _0804E018 - b _0804DBEC -_0804E018: - ldr r7, [sp, 0x38] - str r7, [sp, 0x20] - adds r0, r7, 0 - ldr r1, [sp, 0x10] - cmp r0, r1 - bge _0804E026 - b _0804DBDA -_0804E026: - add sp, 0x58 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804E038: .4byte 0x0000fffc - thumb_func_end sub_804D8C8 - - thumb_func_start sub_804E03C -sub_804E03C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x44 - str r0, [sp] - str r1, [sp, 0x4] - str r2, [sp, 0x8] - movs r0, 0 - str r0, [sp, 0xC] - cmp r0, r1 - blt _0804E058 - b _0804E318 -_0804E058: - movs r2, 0 - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0x28] - ldr r3, [sp, 0x8] - cmp r2, r3 - blt _0804E068 - b _0804E30C -_0804E068: - ldr r4, [sp, 0xC] - lsls r4, 4 - str r4, [sp, 0x14] - ldr r6, [sp, 0xC] - subs r0, r4, r6 - lsls r0, 5 - ldr r1, [sp] - adds r0, r1 - str r0, [sp, 0x18] -_0804E07A: - lsls r0, r2, 5 - ldr r3, [sp, 0x18] - adds r4, r0, r3 - ldrb r1, [r4, 0x8] - str r0, [sp, 0x34] - adds r2, 0x1 - str r2, [sp, 0x2C] - cmp r1, 0 - beq _0804E08E - b _0804E302 -_0804E08E: - ldrb r0, [r4, 0x11] - cmp r0, 0 - beq _0804E096 - b _0804E302 -_0804E096: - ldrb r0, [r4, 0x12] - cmp r0, 0 - beq _0804E09E - b _0804E302 -_0804E09E: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _0804E0A6 - b _0804E302 -_0804E0A6: - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804E0AE - b _0804E302 -_0804E0AE: - ldrb r0, [r4, 0x9] - cmp r0, 0 - beq _0804E0B6 - b _0804E302 -_0804E0B6: - ldrb r0, [r4, 0x10] - cmp r0, 0 - beq _0804E0BE - b _0804E302 -_0804E0BE: - ldrb r0, [r4, 0x1C] - cmp r0, 0 - bne _0804E0C6 - b _0804E302 -_0804E0C6: - movs r0, 0x64 - bl DungeonRandInt - cmp r0, 0x3B - bgt _0804E0D2 - b _0804E302 -_0804E0D2: - movs r6, 0x4 - ldrsh r2, [r4, r6] - movs r1, 0 - ldrsh r0, [r4, r1] - subs r2, r0 - movs r3, 0x6 - ldrsh r0, [r4, r3] - movs r6, 0x2 - ldrsh r1, [r4, r6] - subs r0, r1 - adds r2, r0 - str r2, [sp, 0x10] - adds r0, r2, 0 - cmp r2, 0 - bge _0804E0F2 - adds r0, 0x3 -_0804E0F2: - asrs r0, 2 - str r0, [sp, 0x10] - cmp r0, 0 - bne _0804E0FE - movs r0, 0x1 - str r0, [sp, 0x10] -_0804E0FE: - movs r1, 0 - ldr r2, [sp, 0x10] - cmp r1, r2 - blt _0804E108 - b _0804E302 -_0804E108: - ldr r3, [sp, 0x14] - ldr r4, [sp, 0xC] - subs r0, r3, r4 - lsls r0, 5 - ldr r6, [sp] - adds r0, r6 - ldr r2, [sp, 0x34] - adds r0, r2, r0 - str r0, [sp, 0x20] -_0804E11A: - movs r4, 0 - adds r1, 0x1 - str r1, [sp, 0x30] -_0804E120: - movs r0, 0x4 - bl DungeonRandInt - str r0, [sp, 0x1C] - cmp r0, 0x1 - beq _0804E14A - cmp r0, 0x1 - ble _0804E138 - cmp r0, 0x2 - beq _0804E168 - cmp r0, 0x3 - beq _0804E182 -_0804E138: - ldr r3, [sp, 0x20] - movs r6, 0 - ldrsh r7, [r3, r6] - movs r1, 0x2 - ldrsh r0, [r3, r1] - mov r8, r0 - cmp r4, 0 - bne _0804E19C - b _0804E15C -_0804E14A: - ldr r2, [sp, 0x20] - movs r3, 0x4 - ldrsh r0, [r2, r3] - subs r7, r0, 0x1 - movs r0, 0x2 - ldrsh r6, [r2, r0] - mov r8, r6 - cmp r4, 0 - beq _0804E162 -_0804E15C: - movs r3, 0 - movs r2, 0x1 - b _0804E1A0 -_0804E162: - movs r3, 0x1 - negs r3, r3 - b _0804E19E -_0804E168: - ldr r1, [sp, 0x20] - movs r2, 0x4 - ldrsh r0, [r1, r2] - subs r7, r0, 0x1 - movs r3, 0x6 - ldrsh r0, [r1, r3] - subs r0, 0x1 - mov r8, r0 - cmp r4, 0 - beq _0804E194 - movs r3, 0x1 - negs r3, r3 - b _0804E19E -_0804E182: - ldr r6, [sp, 0x20] - movs r0, 0 - ldrsh r7, [r6, r0] - movs r1, 0x6 - ldrsh r0, [r6, r1] - subs r0, 0x1 - mov r8, r0 - cmp r4, 0 - beq _0804E19C -_0804E194: - movs r3, 0 - movs r2, 0x1 - negs r2, r2 - b _0804E1A0 -_0804E19C: - movs r3, 0x1 -_0804E19E: - movs r2, 0 -_0804E1A0: - movs r6, 0 - mov r9, r6 - ldr r5, [sp, 0x34] - ldr r0, [sp, 0x14] - str r0, [sp, 0x40] - ldr r6, [sp, 0x18] - adds r1, r5, r6 - movs r6, 0 - ldrsh r0, [r1, r6] - mov r10, r0 - adds r4, 0x1 - str r4, [sp, 0x24] - cmp r7, r10 - bge _0804E1BE - b _0804E2F0 -_0804E1BE: - movs r4, 0x4 - ldrsh r0, [r1, r4] - cmp r7, r0 - blt _0804E1C8 - b _0804E2F0 -_0804E1C8: - ldr r6, [sp, 0x40] - ldr r1, [sp, 0xC] - subs r0, r6, r1 - lsls r0, 5 - ldr r4, [sp] - adds r0, r4 - adds r4, r5, r0 - movs r6, 0x2 - ldrsh r0, [r4, r6] - cmp r8, r0 - bge _0804E1E0 - b _0804E2F0 -_0804E1E0: - movs r1, 0x6 - ldrsh r0, [r4, r1] - cmp r8, r0 - blt _0804E1EA - b _0804E2F0 -_0804E1EA: - adds r0, r7, 0 - mov r1, r8 - str r2, [sp, 0x38] - str r3, [sp, 0x3C] - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - ldr r2, [sp, 0x38] - ldr r3, [sp, 0x3C] - cmp r0, 0x1 - bne _0804E2D0 - movs r6, 0 -_0804E206: - ldr r1, _0804E228 - lsls r0, r6, 2 - adds r0, r1 - movs r2, 0 - ldrsh r1, [r0, r2] - adds r1, r7 - mov r10, r1 - movs r3, 0x2 - ldrsh r0, [r0, r3] - add r0, r8 - mov r9, r0 - movs r3, 0 - movs r5, 0x1 - negs r5, r5 -_0804E222: - movs r4, 0x1 - negs r4, r4 - b _0804E22E - .align 2, 0 -_0804E228: .4byte gAdjacentTileOffsets -_0804E22C: - adds r4, 0x1 -_0804E22E: - cmp r4, 0x1 - bgt _0804E25A - mov r1, r10 - adds r0, r1, r4 - mov r2, r9 - adds r1, r2, r5 - str r3, [sp, 0x3C] - bl GetTile - adds r2, r0, 0 - ldrh r1, [r2] - movs r0, 0x3 - ands r0, r1 - ldr r3, [sp, 0x3C] - cmp r0, 0x1 - bne _0804E22C - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - bne _0804E256 - movs r3, 0x1 -_0804E256: - cmp r3, 0 - beq _0804E22C -_0804E25A: - cmp r3, 0 - bne _0804E26A - adds r5, 0x1 - cmp r5, 0x1 - ble _0804E222 - adds r6, 0x1 - cmp r6, 0x7 - ble _0804E206 -_0804E26A: - cmp r6, 0x8 - bne _0804E2F0 - movs r6, 0 - ldr r3, [sp, 0x1C] - lsls r1, r3, 3 - ldr r0, _0804E2C4 - adds r4, r1, r0 -_0804E278: - ldr r0, _0804E2C8 - lsls r1, r6, 2 - adds r1, r0 - movs r2, 0 - ldrsh r0, [r1, r2] - movs r3, 0x2 - ldrsh r1, [r1, r3] - adds r0, r7, r0 - add r1, r8 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - movs r1, 0 - cmp r0, 0x1 - bne _0804E29C - movs r1, 0x1 -_0804E29C: - ldrb r0, [r4] - cmp r0, r1 - bne _0804E2AA - adds r4, 0x2 - adds r6, 0x2 - cmp r6, 0x7 - ble _0804E278 -_0804E2AA: - cmp r6, 0x8 - bne _0804E2F0 - adds r0, r7, 0 - mov r1, r8 - bl GetTileMut - ldrh r2, [r0] - ldr r4, _0804E2CC - adds r1, r4, 0 - ands r2, r1 - strh r2, [r0] - b _0804E2F0 - .align 2, 0 -_0804E2C4: .4byte gUnknown_80F6DD5 -_0804E2C8: .4byte gAdjacentTileOffsets -_0804E2CC: .4byte 0x0000fffc -_0804E2D0: - adds r7, r3 - add r8, r2 - movs r6, 0x1 - add r9, r6 - mov r0, r9 - cmp r0, 0x9 - bgt _0804E2F0 - movs r1, 0 - ldrsh r0, [r4, r1] - cmp r7, r0 - blt _0804E2F0 - movs r6, 0x4 - ldrsh r0, [r4, r6] - cmp r7, r0 - bge _0804E2F0 - b _0804E1C8 -_0804E2F0: - ldr r4, [sp, 0x24] - cmp r4, 0x1 - bgt _0804E2F8 - b _0804E120 -_0804E2F8: - ldr r1, [sp, 0x30] - ldr r0, [sp, 0x10] - cmp r1, r0 - bge _0804E302 - b _0804E11A -_0804E302: - ldr r2, [sp, 0x2C] - ldr r1, [sp, 0x8] - cmp r2, r1 - bge _0804E30C - b _0804E07A -_0804E30C: - ldr r2, [sp, 0x28] - str r2, [sp, 0xC] - ldr r3, [sp, 0x4] - cmp r2, r3 - bge _0804E318 - b _0804E058 -_0804E318: - add sp, 0x44 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804E03C - - thumb_func_start sub_804E328 -sub_804E328: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r5, r0, 0 - adds r4, r1, 0 - str r2, [sp] - str r3, [sp, 0x4] - ldr r0, [sp, 0x28] - lsls r0, 24 - mov r10, r5 - mov r9, r4 - ldr r1, [sp, 0x2C] - mov r8, r1 - ldr r7, [sp, 0x30] - cmp r0, 0 - bne _0804E350 - b _0804E470 -_0804E350: - movs r6, 0 -_0804E352: - cmp r4, r7 - beq _0804E3A8 - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E360 - b _0804E57E -_0804E360: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E390 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - ldr r3, _0804E38C - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E39C - .align 2, 0 -_0804E38C: .4byte 0x0000fffc -_0804E390: - cmp r5, r10 - beq _0804E396 - b _0804E57E -_0804E396: - cmp r4, r9 - beq _0804E39C - b _0804E57E -_0804E39C: - cmp r4, r7 - bge _0804E3A4 - adds r4, 0x1 - b _0804E352 -_0804E3A4: - subs r4, 0x1 - b _0804E352 -_0804E3A8: - movs r6, 0 - ldr r0, [sp] - cmp r5, r0 - beq _0804E40A - movs r7, 0 -_0804E3B2: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E3BC - b _0804E57E -_0804E3BC: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E3EC - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - ldr r3, _0804E3E8 - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E3F8 - .align 2, 0 -_0804E3E8: .4byte 0x0000fffc -_0804E3EC: - cmp r5, r10 - beq _0804E3F2 - b _0804E57E -_0804E3F2: - cmp r4, r9 - beq _0804E3F8 - b _0804E57E -_0804E3F8: - ldr r0, [sp] - cmp r5, r0 - bge _0804E402 - adds r5, 0x1 - b _0804E404 -_0804E402: - subs r5, 0x1 -_0804E404: - ldr r1, [sp] - cmp r5, r1 - bne _0804E3B2 -_0804E40A: - movs r6, 0 - ldr r3, [sp, 0x4] - cmp r4, r3 - bne _0804E414 - b _0804E57E -_0804E414: - movs r7, 0 -_0804E416: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E420 - b _0804E57E -_0804E420: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E450 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - ldr r3, _0804E44C - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E45C - .align 2, 0 -_0804E44C: .4byte 0x0000fffc -_0804E450: - cmp r5, r10 - beq _0804E456 - b _0804E57E -_0804E456: - cmp r4, r9 - beq _0804E45C - b _0804E57E -_0804E45C: - ldr r0, [sp, 0x4] - cmp r4, r0 - bge _0804E466 - adds r4, 0x1 - b _0804E468 -_0804E466: - subs r4, 0x1 -_0804E468: - ldr r1, [sp, 0x4] - cmp r4, r1 - bne _0804E416 - b _0804E57E -_0804E470: - movs r6, 0 - cmp r5, r8 - beq _0804E4C6 - movs r7, 0 -_0804E478: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - ble _0804E482 - b _0804E57E -_0804E482: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E4B0 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - ldr r3, _0804E4AC - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E4B8 - .align 2, 0 -_0804E4AC: .4byte 0x0000fffc -_0804E4B0: - cmp r5, r10 - bne _0804E57E - cmp r4, r9 - bne _0804E57E -_0804E4B8: - cmp r5, r8 - bge _0804E4C0 - adds r5, 0x1 - b _0804E4C2 -_0804E4C0: - subs r5, 0x1 -_0804E4C2: - cmp r5, r8 - bne _0804E478 -_0804E4C6: - movs r6, 0 - ldr r0, [sp, 0x4] - cmp r4, r0 - beq _0804E522 - movs r7, 0 -_0804E4D0: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - bgt _0804E57E - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E508 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - ldr r3, _0804E504 - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E510 - .align 2, 0 -_0804E504: .4byte 0x0000fffc -_0804E508: - cmp r5, r10 - bne _0804E57E - cmp r4, r9 - bne _0804E57E -_0804E510: - ldr r0, [sp, 0x4] - cmp r4, r0 - bge _0804E51A - adds r4, 0x1 - b _0804E51C -_0804E51A: - subs r4, 0x1 -_0804E51C: - ldr r1, [sp, 0x4] - cmp r4, r1 - bne _0804E4D0 -_0804E522: - movs r6, 0 - ldr r3, [sp] - cmp r5, r3 - beq _0804E57E - movs r7, 0 -_0804E52C: - adds r0, r6, 0 - adds r6, 0x1 - cmp r0, 0x37 - bgt _0804E57E - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804E564 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - ldr r3, _0804E560 - adds r1, r3, 0 - ands r2, r1 - movs r1, 0x1 - orrs r2, r1 - strh r2, [r0] - b _0804E56C - .align 2, 0 -_0804E560: .4byte 0x0000fffc -_0804E564: - cmp r5, r10 - bne _0804E57E - cmp r4, r9 - bne _0804E57E -_0804E56C: - ldr r0, [sp] - cmp r5, r0 - bge _0804E576 - adds r5, 0x1 - b _0804E578 -_0804E576: - subs r5, 0x1 -_0804E578: - ldr r1, [sp] - cmp r5, r1 - bne _0804E52C -_0804E57E: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804E328 - - thumb_func_start sub_804E590 -sub_804E590: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x40 - str r0, [sp, 0xC] - str r1, [sp, 0x10] - str r2, [sp, 0x14] - str r3, [sp, 0x18] - movs r0, 0 - str r0, [sp, 0x1C] - cmp r0, r1 - blt _0804E5AE - b _0804E8AA -_0804E5AE: - movs r1, 0x1 - mov r10, r1 -_0804E5B2: - movs r2, 0 - str r2, [sp, 0x20] - ldr r3, [sp, 0x1C] - adds r3, 0x1 - str r3, [sp, 0x2C] - ldr r4, [sp, 0x14] - cmp r2, r4 - blt _0804E5C4 - b _0804E89E -_0804E5C4: - ldr r5, [sp, 0x1C] - lsls r5, 4 - ldr r6, [sp, 0x1C] - subs r1, r5, r6 - lsls r1, 5 - ldr r2, [sp, 0xC] - movs r3, 0xF0 - lsls r3, 1 - adds r0, r2, r3 - adds r0, r1 - mov r8, r0 - adds r6, r1, r2 - ldr r4, _0804E6A4 - adds r0, r2, r4 - adds r7, r1, r0 - adds r0, r2, 0 - adds r0, 0x20 - adds r0, r1 - mov r9, r0 - ldr r5, [sp, 0x60] - str r5, [sp, 0x34] - adds r0, r2, 0 - subs r0, 0x20 - adds r1, r0 - str r1, [sp, 0x38] - movs r0, 0 - str r0, [sp, 0x3C] - ldr r1, [sp, 0x1C] - lsls r0, r1, 2 - ldr r2, [sp, 0x18] - adds r0, r2 - str r0, [sp, 0x28] -_0804E604: - ldr r3, [sp, 0x1C] - lsls r0, r3, 4 - subs r0, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x3C] - adds r4, r5, r0 - ldrb r0, [r4, 0x8] - cmp r0, 0 - beq _0804E61C - b _0804E874 -_0804E61C: - ldrb r0, [r4, 0x11] - cmp r0, 0 - beq _0804E624 - b _0804E874 -_0804E624: - ldrb r0, [r4, 0xB] - cmp r0, 0 - beq _0804E62C - b _0804E874 -_0804E62C: - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804E634 - b _0804E848 -_0804E634: - ldrb r0, [r4, 0x9] - cmp r0, 0 - beq _0804E63C - b _0804E848 -_0804E63C: - movs r1, 0 - ldrsh r0, [r4, r1] - adds r0, 0x1 - movs r2, 0x4 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - str r0, [sp, 0x24] - movs r3, 0x2 - ldrsh r0, [r4, r3] - adds r0, 0x1 - movs r5, 0x6 - ldrsh r1, [r4, r5] - subs r1, 0x1 - bl DungeonRandRange - adds r5, r0, 0 - ldr r0, [sp, 0x20] - cmp r0, 0 - ble _0804E6DC - subs r4, 0x20 - ldrb r0, [r4, 0x8] - cmp r0, 0 - bne _0804E6DC - ldrb r0, [r4, 0x12] - cmp r0, 0 - bne _0804E6DC - ldrb r0, [r4, 0xB] - cmp r0, 0 - beq _0804E6DC - ldrb r0, [r4, 0xA] - cmp r0, 0 - beq _0804E6A8 - movs r1, 0 - ldrsh r0, [r4, r1] - adds r0, 0x1 - movs r2, 0x4 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r5, r0, 0 - movs r3, 0x2 - ldrsh r0, [r4, r3] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - b _0804E6AC - .align 2, 0 -_0804E6A4: .4byte 0xfffffe20 -_0804E6A8: - movs r3, 0 - ldrsh r5, [r4, r3] -_0804E6AC: - movs r4, 0x2 - ldrsh r1, [r6, r4] - ldr r0, [sp, 0x38] - movs r2, 0x6 - ldrsh r3, [r0, r2] - subs r3, 0x1 - mov r4, r10 - str r4, [sp] - ldr r2, [sp, 0x28] - ldr r0, [r2] - str r0, [sp, 0x4] - ldr r4, [sp, 0x34] - ldr r0, [r4] - str r0, [sp, 0x8] - ldr r0, [sp, 0x24] - adds r2, r5, 0 - bl sub_804E328 - mov r5, r10 - strb r5, [r6, 0xB] - strb r5, [r6, 0x13] - ldr r0, [sp, 0x38] - strb r5, [r0, 0x14] - b _0804E874 -_0804E6DC: - ldr r0, [sp, 0x14] - subs r0, 0x1 - ldr r1, [sp, 0x20] - cmp r1, r0 - bge _0804E758 - mov r2, r9 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804E758 - ldrb r0, [r2, 0x12] - cmp r0, 0 - bne _0804E758 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804E758 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804E724 - movs r3, 0x20 - ldrsh r0, [r6, r3] - adds r0, 0x1 - movs r4, 0x24 - ldrsh r1, [r6, r4] - subs r1, 0x1 - bl DungeonRandRange - adds r5, r0, 0 - movs r1, 0x22 - ldrsh r0, [r6, r1] - adds r0, 0x1 - movs r2, 0x26 - ldrsh r1, [r6, r2] - subs r1, 0x1 - bl DungeonRandRange - b _0804E728 -_0804E724: - movs r3, 0x20 - ldrsh r5, [r6, r3] -_0804E728: - movs r4, 0x6 - ldrsh r1, [r6, r4] - subs r1, 0x1 - movs r0, 0x22 - ldrsh r3, [r6, r0] - mov r2, r10 - str r2, [sp] - ldr r4, [sp, 0x28] - ldr r0, [r4] - str r0, [sp, 0x4] - ldr r2, [sp, 0x34] - ldr r0, [r2, 0x4] - subs r0, 0x1 - str r0, [sp, 0x8] - ldr r0, [sp, 0x24] - adds r2, r5, 0 - bl sub_804E328 - mov r3, r10 - strb r3, [r6, 0xB] - strb r3, [r6, 0x14] - mov r4, r9 - strb r3, [r4, 0x13] - b _0804E874 -_0804E758: - ldr r0, [sp, 0x1C] - cmp r0, 0 - ble _0804E7C8 - ldrb r0, [r7, 0x8] - cmp r0, 0 - bne _0804E7C8 - ldrb r0, [r7, 0x12] - cmp r0, 0 - bne _0804E7C8 - ldrb r0, [r7, 0xB] - cmp r0, 0 - beq _0804E7C8 - ldrb r0, [r7, 0xA] - cmp r0, 0 - beq _0804E79A - movs r1, 0 - ldrsh r0, [r7, r1] - adds r0, 0x1 - movs r2, 0x4 - ldrsh r1, [r7, r2] - subs r1, 0x1 - bl DungeonRandRange - movs r3, 0x2 - ldrsh r0, [r7, r3] - adds r0, 0x1 - movs r4, 0x6 - ldrsh r1, [r7, r4] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804E79E -_0804E79A: - movs r0, 0x2 - ldrsh r3, [r7, r0] -_0804E79E: - movs r1, 0 - ldrsh r0, [r6, r1] - movs r4, 0 - ldrsh r2, [r7, r4] - subs r2, 0x1 - movs r1, 0 - str r1, [sp] - ldr r4, [sp, 0x28] - ldr r1, [r4] - str r1, [sp, 0x4] - ldr r4, [sp, 0x34] - ldr r1, [r4] - str r1, [sp, 0x8] - adds r1, r5, 0 - bl sub_804E328 - mov r5, r10 - strb r5, [r6, 0xB] - strb r5, [r6, 0x15] - strb r5, [r7, 0x16] - b _0804E874 -_0804E7C8: - ldr r0, [sp, 0x10] - subs r0, 0x1 - ldr r1, [sp, 0x1C] - cmp r1, r0 - bge _0804E874 - mov r2, r8 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804E874 - ldrb r0, [r2, 0x12] - cmp r0, 0 - bne _0804E874 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804E874 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804E812 - movs r3, 0 - ldrsh r0, [r2, r3] - adds r0, 0x1 - movs r4, 0x4 - ldrsh r1, [r2, r4] - subs r1, 0x1 - bl DungeonRandRange - mov r1, r8 - movs r2, 0x2 - ldrsh r0, [r1, r2] - adds r0, 0x1 - movs r3, 0x6 - ldrsh r1, [r1, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804E818 -_0804E812: - mov r4, r8 - movs r0, 0x2 - ldrsh r3, [r4, r0] -_0804E818: - movs r1, 0x4 - ldrsh r0, [r6, r1] - subs r0, 0x1 - mov r4, r8 - movs r1, 0 - ldrsh r2, [r4, r1] - movs r1, 0 - str r1, [sp] - ldr r4, [sp, 0x28] - ldr r1, [r4, 0x4] - subs r1, 0x1 - str r1, [sp, 0x4] - ldr r4, [sp, 0x34] - ldr r1, [r4] - str r1, [sp, 0x8] - adds r1, r5, 0 - bl sub_804E328 - mov r5, r10 - strb r5, [r6, 0xB] - strb r5, [r6, 0x16] - mov r0, r8 - strb r5, [r0, 0x15] - b _0804E874 -_0804E848: - movs r1, 0 - ldrsh r0, [r6, r1] - movs r2, 0x2 - ldrsh r1, [r6, r2] - bl GetTileMut - ldrh r1, [r0] - ldr r3, _0804E99C - adds r2, r3, 0 - ands r1, r2 - strh r1, [r0] - ldrh r1, [r0, 0x4] - ldr r4, _0804E9A0 - adds r2, r4, 0 - ands r1, r2 - ldr r5, _0804E9A4 - adds r2, r5, 0 - ands r1, r2 - subs r3, 0x1 - adds r2, r3, 0 - ands r1, r2 - strh r1, [r0, 0x4] -_0804E874: - movs r4, 0x20 - add r8, r4 - adds r6, 0x20 - adds r7, 0x20 - add r9, r4 - ldr r5, [sp, 0x34] - adds r5, 0x4 - str r5, [sp, 0x34] - ldr r0, [sp, 0x38] - adds r0, 0x20 - str r0, [sp, 0x38] - ldr r1, [sp, 0x3C] - adds r1, 0x20 - str r1, [sp, 0x3C] - ldr r2, [sp, 0x20] - adds r2, 0x1 - str r2, [sp, 0x20] - ldr r3, [sp, 0x14] - cmp r2, r3 - bge _0804E89E - b _0804E604 -_0804E89E: - ldr r4, [sp, 0x2C] - str r4, [sp, 0x1C] - ldr r5, [sp, 0x10] - cmp r4, r5 - bge _0804E8AA - b _0804E5B2 -_0804E8AA: - movs r6, 0 - str r6, [sp, 0x1C] - ldr r0, [sp, 0x10] - cmp r6, r0 - bge _0804E98A -_0804E8B4: - movs r1, 0 - str r1, [sp, 0x20] - ldr r2, [sp, 0x1C] - adds r2, 0x1 - str r2, [sp, 0x2C] - ldr r3, [sp, 0x14] - cmp r1, r3 - bge _0804E980 - ldr r4, [sp, 0x1C] - lsls r4, 4 - mov r9, r4 -_0804E8CA: - ldr r5, [sp, 0x20] - lsls r2, r5, 5 - ldr r6, [sp, 0x1C] - lsls r3, r6, 4 - subs r0, r3, r6 - lsls r0, 5 - ldr r1, [sp, 0xC] - adds r4, r0, r1 - adds r1, r2, r4 - ldrb r0, [r1, 0x8] - mov r8, r2 - adds r5, 0x1 - str r5, [sp, 0x30] - cmp r0, 0 - bne _0804E976 - ldrb r0, [r1, 0x11] - cmp r0, 0 - bne _0804E976 - ldrb r0, [r1, 0xB] - cmp r0, 0 - bne _0804E976 - ldrb r0, [r1, 0xF] - cmp r0, 0 - bne _0804E976 - movs r6, 0 - ldrsh r5, [r1, r6] - movs r6, 0x4 - ldrsh r0, [r1, r6] - cmp r5, r0 - bge _0804E976 - mov r10, r4 -_0804E908: - ldr r1, [sp, 0x1C] - subs r0, r3, r1 - lsls r0, 5 - ldr r3, [sp, 0xC] - adds r0, r3 - adds r0, r2, r0 - movs r6, 0x2 - ldrsh r4, [r0, r6] - movs r1, 0x6 - ldrsh r0, [r0, r1] - adds r7, r5, 0x1 - cmp r4, r0 - bge _0804E95C - mov r6, r8 - add r6, r10 -_0804E926: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - ldr r3, _0804E99C - adds r1, r3, 0 - ands r2, r1 - strh r2, [r0] - ldrh r2, [r0, 0x4] - adds r3, 0x1 - adds r1, r3, 0 - ands r2, r1 - adds r3, 0x1 - adds r1, r3, 0 - ands r2, r1 - subs r3, 0x3 - adds r1, r3, 0 - ands r2, r1 - strh r2, [r0, 0x4] - movs r1, 0xFF - strb r1, [r0, 0x9] - adds r4, 0x1 - movs r1, 0x6 - ldrsh r0, [r6, r1] - cmp r4, r0 - blt _0804E926 -_0804E95C: - adds r5, r7, 0 - mov r2, r8 - mov r3, r9 - ldr r4, [sp, 0x1C] - subs r0, r3, r4 - lsls r0, 5 - ldr r6, [sp, 0xC] - adds r0, r6 - adds r0, r2, r0 - movs r1, 0x4 - ldrsh r0, [r0, r1] - cmp r5, r0 - blt _0804E908 -_0804E976: - ldr r2, [sp, 0x30] - str r2, [sp, 0x20] - ldr r3, [sp, 0x14] - cmp r2, r3 - blt _0804E8CA -_0804E980: - ldr r4, [sp, 0x2C] - str r4, [sp, 0x1C] - ldr r5, [sp, 0x10] - cmp r4, r5 - blt _0804E8B4 -_0804E98A: - add sp, 0x40 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804E99C: .4byte 0x0000fffc -_0804E9A0: .4byte 0x0000fffe -_0804E9A4: .4byte 0x0000fffd - thumb_func_end sub_804E590 - - thumb_func_start sub_804E9A8 -sub_804E9A8: - push {r4,r5,lr} - adds r4, r0, 0 - lsls r1, 24 - lsls r2, 24 - lsrs r2, 24 - ldrh r0, [r4] - ldr r5, _0804E9D8 - adds r3, r5, 0 - ands r3, r0 - strh r3, [r4] - cmp r1, 0 - beq _0804E9D0 - ldrb r0, [r4, 0x9] - cmp r0, r2 - bne _0804E9D0 - adds r0, r3, 0 - ands r0, r5 - movs r1, 0x2 - orrs r0, r1 - strh r0, [r4] -_0804E9D0: - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_0804E9D8: .4byte 0x0000fffc - thumb_func_end sub_804E9A8 - - thumb_func_start sub_804E9DC -sub_804E9DC: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - movs r5, 0 - movs r0, 0x3 - mov r8, r0 - movs r7, 0x8 - ldr r3, _0804EAF0 - mov r9, r3 -_0804E9F2: - movs r4, 0 - adds r6, r5, 0x1 - mov r10, r6 -_0804E9F8: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - adds r6, r4, 0x1 - cmp r0, 0x1 - beq _0804EA0E - b _0804EB0E -_0804EA0E: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r0, 0xFF - bne _0804EAF4 - cmp r5, 0 - ble _0804EA4E - subs r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileMut - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EA4E - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - strh r1, [r2] - adds r0, r1, 0 - mov r6, r8 - ands r0, r6 - cmp r0, 0x2 - bne _0804EA4E - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] -_0804EA4E: - cmp r4, 0 - ble _0804EA82 - subs r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileMut - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EA82 - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - orrs r1, r7 - strh r1, [r2] - adds r0, r1, 0 - mov r6, r8 - ands r0, r6 - cmp r0, 0x2 - bne _0804EA82 - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] -_0804EA82: - adds r6, r4, 0x1 - cmp r4, 0x1E - bgt _0804EABA - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileMut - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EABA - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - mov r12, r3 - orrs r1, r7 - strh r1, [r2] - adds r0, r1, 0 - mov r3, r8 - ands r0, r3 - cmp r0, 0x2 - bne _0804EABA - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] -_0804EABA: - cmp r5, 0x36 - bgt _0804EB0E - mov r0, r10 - adds r1, r4, 0 - bl GetTileMut - adds r2, r0, 0 - ldrb r0, [r2, 0x9] - cmp r0, 0xFF - beq _0804EB0E - ldrh r0, [r2] - adds r1, r0, 0 - orrs r1, r7 - movs r3, 0 - orrs r1, r7 - strh r1, [r2] - adds r0, r1, 0 - mov r4, r8 - ands r0, r4 - cmp r0, 0x2 - bne _0804EB0E - mov r0, r9 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r2] - b _0804EB0E - .align 2, 0 -_0804EAF0: .4byte 0x0000fffc -_0804EAF4: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r0, 0xFE - bne _0804EB0E - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0xFF - strb r1, [r0, 0x9] -_0804EB0E: - adds r4, r6, 0 - cmp r4, 0x1F - bgt _0804EB16 - b _0804E9F8 -_0804EB16: - mov r5, r10 - cmp r5, 0x37 - bgt _0804EB1E - b _0804E9F2 -_0804EB1E: - bl sub_804EB30 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804E9DC - - thumb_func_start sub_804EB30 -sub_804EB30: - push {r4-r7,lr} - ldr r0, _0804EBB4 - ldr r6, [r0] - movs r2, 0 - movs r1, 0x1F - ldr r3, _0804EBB8 - adds r0, r6, r3 -_0804EB3E: - strh r2, [r0] - subs r0, 0x2 - subs r1, 0x1 - cmp r1, 0 - bge _0804EB3E - movs r5, 0 -_0804EB4A: - movs r4, 0 - adds r7, r5, 0x1 -_0804EB4E: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _0804EBA2 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r3, [r0, 0x9] - cmp r3, 0x1F - bhi _0804EBA2 - lsls r0, r3, 1 - ldr r2, _0804EBBC - adds r1, r6, r2 - adds r2, r1, r0 - movs r1, 0 - ldrsh r0, [r2, r1] - cmp r0, 0x1F - bgt _0804EBA2 - lsls r0, 2 - lsls r1, r3, 7 - adds r0, r1 - adds r0, r6, r0 - ldr r3, _0804EBC0 - adds r0, r3 - strh r5, [r0] - movs r3, 0 - ldrsh r0, [r2, r3] - lsls r0, 2 - adds r0, r1 - adds r0, r6, r0 - ldr r1, _0804EBC4 - adds r0, r1 - strh r4, [r0] - ldrh r0, [r2] - adds r0, 0x1 - strh r0, [r2] -_0804EBA2: - adds r4, 0x1 - cmp r4, 0x1F - ble _0804EB4E - adds r5, r7, 0 - cmp r5, 0x37 - ble _0804EB4A - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804EBB4: .4byte gDungeon -_0804EBB8: .4byte 0x00010882 -_0804EBBC: .4byte 0x00010844 -_0804EBC0: .4byte 0x00010884 -_0804EBC4: .4byte 0x00010886 - thumb_func_end sub_804EB30 - - thumb_func_start sub_804EBC8 -sub_804EBC8: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x58 - str r0, [sp, 0x40] - str r1, [sp, 0x44] - mov r10, r2 - adds r4, r3, 0 - ldr r0, _0804EE90 - ldr r0, [r0] - mov r8, r0 - ldr r1, _0804EE94 - ldr r0, _0804EE98 - strh r0, [r1] - movs r0, 0x1 - negs r0, r0 - strh r0, [r1, 0x2] - ldr r0, _0804EE9C - ldrb r0, [r0] - cmp r0, 0 - beq _0804EBF8 - b _0804EED4 -_0804EBF8: - bl sub_8043D10 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _0804EC06 - b _0804EED4 -_0804EC06: - cmp r4, 0 - bne _0804EC0C - b _0804EED4 -_0804EC0C: - movs r0, 0x64 - bl DungeonRandInt - cmp r4, r0 - bgt _0804EC18 - b _0804EED4 -_0804EC18: - movs r5, 0 - add r7, sp, 0x20 - adds r1, r7, 0 - mov r0, sp -_0804EC20: - strh r5, [r0] - strh r5, [r1] - adds r1, 0x2 - adds r0, 0x2 - adds r5, 0x1 - cmp r5, 0xE - ble _0804EC20 - movs r5, 0xC7 -_0804EC30: - movs r0, 0xF - bl DungeonRandInt - adds r4, r0, 0 - movs r0, 0xF - bl DungeonRandInt - lsls r4, 1 - mov r1, sp - adds r2, r1, r4 - movs r4, 0 - ldrsh r3, [r2, r4] - lsls r0, 1 - adds r1, r0 - ldrh r0, [r1] - strh r0, [r2] - strh r3, [r1] - subs r5, 0x1 - cmp r5, 0 - bge _0804EC30 - adds r6, r7, 0 - movs r5, 0xC7 -_0804EC5C: - movs r0, 0xF - bl DungeonRandInt - adds r4, r0, 0 - movs r0, 0xF - bl DungeonRandInt - lsls r4, 1 - adds r4, r6, r4 - movs r1, 0 - ldrsh r2, [r4, r1] - lsls r0, 1 - adds r0, r6, r0 - ldrh r1, [r0] - strh r1, [r4] - strh r2, [r0] - subs r5, 0x1 - cmp r5, 0 - bge _0804EC5C - movs r5, 0 -_0804EC84: - lsls r0, r5, 1 - add r0, sp - movs r3, 0 - ldrsh r2, [r0, r3] - mov r9, r2 - ldr r4, [sp, 0x44] - cmp r9, r4 - blt _0804EC96 - b _0804EECC -_0804EC96: - movs r4, 0 -_0804EC98: - lsls r0, r4, 1 - adds r0, r7, r0 - movs r2, 0 - ldrsh r1, [r0, r2] - cmp r1, r10 - blt _0804ECA6 - b _0804EEC4 -_0804ECA6: - lsls r1, 5 - mov r3, r9 - lsls r2, r3, 4 - subs r0, r2, r3 - lsls r0, 5 - ldr r3, [sp, 0x40] - adds r0, r3 - adds r3, r1, r0 - ldrb r0, [r3, 0x8] - str r1, [sp, 0x4C] - str r2, [sp, 0x48] - cmp r0, 0 - beq _0804ECC2 - b _0804EEC4 -_0804ECC2: - ldrb r0, [r3, 0x11] - cmp r0, 0 - beq _0804ECCA - b _0804EEC4 -_0804ECCA: - ldrb r0, [r3, 0x12] - cmp r0, 0 - beq _0804ECD2 - b _0804EEC4 -_0804ECD2: - ldrb r0, [r3, 0xB] - cmp r0, 0 - bne _0804ECDA - b _0804EEC4 -_0804ECDA: - ldrb r0, [r3, 0xA] - cmp r0, 0 - bne _0804ECE2 - b _0804EEC4 -_0804ECE2: - ldrb r0, [r3, 0x9] - cmp r0, 0 - beq _0804ECEA - b _0804EEC4 -_0804ECEA: - ldrb r0, [r3, 0x10] - cmp r0, 0 - beq _0804ECF2 - b _0804EEC4 -_0804ECF2: - ldrb r0, [r3, 0x1D] - cmp r0, 0 - beq _0804ECFA - b _0804EEC4 -_0804ECFA: - movs r0, 0x4 - ldrsh r1, [r3, r0] - movs r2, 0 - ldrsh r0, [r3, r2] - subs r1, r0 - cmp r1, 0 - bge _0804ED0A - negs r1, r1 -_0804ED0A: - cmp r1, 0x4 - bgt _0804ED10 - b _0804EEC4 -_0804ED10: - movs r0, 0x6 - ldrsh r1, [r3, r0] - movs r2, 0x2 - ldrsh r0, [r3, r2] - subs r1, r0 - cmp r1, 0 - bge _0804ED20 - negs r1, r1 -_0804ED20: - cmp r1, 0x3 - bgt _0804ED26 - b _0804EEC4 -_0804ED26: - ldr r1, _0804EEA0 - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x1 - strb r0, [r3, 0xC] - ldr r2, _0804EEA4 - movs r4, 0 - ldrsh r0, [r3, r4] - adds r0, 0x1 - str r0, [r2] - movs r7, 0x4 - ldrsh r0, [r3, r7] - subs r0, 0x1 - str r0, [r2, 0x8] - movs r0, 0x2 - ldrsh r1, [r3, r0] - adds r1, 0x1 - str r1, [r2, 0x4] - movs r4, 0x6 - ldrsh r3, [r3, r4] - subs r0, r3, 0x1 - str r0, [r2, 0xC] - subs r0, r1 - mov r10, r2 - cmp r0, 0x2 - bgt _0804ED5C - str r3, [r2, 0xC] -_0804ED5C: - ldr r0, _0804EEA8 - add r0, r8 - ldr r1, _0804EEAC - str r1, [r0] - ldr r0, _0804EEB0 - add r0, r8 - str r1, [r0] - ldr r0, _0804EEB4 - add r0, r8 - ldr r1, _0804EEB8 - str r1, [r0] - ldr r0, _0804EEBC - add r0, r8 - str r1, [r0] - mov r7, r10 - ldr r5, [r7] - ldr r0, [r7, 0x8] - cmp r5, r0 - bge _0804EDFA - mov r3, r10 -_0804ED84: - ldr r4, [r3, 0x4] - ldr r0, [r3, 0xC] - adds r1, r5, 0x1 - str r1, [sp, 0x54] - cmp r4, r0 - bge _0804EDF0 - ldr r6, _0804EEA8 - add r6, r8 - ldr r2, _0804EEA4 - mov r10, r2 -_0804ED98: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x50] - bl GetTileMut - ldrh r2, [r0] - movs r1, 0x20 - orrs r1, r2 - strh r1, [r0] - ldrh r2, [r0, 0x4] - ldr r7, _0804EEC0 - adds r1, r7, 0 - ands r2, r1 - adds r7, 0x7 - adds r1, r7, 0 - ands r2, r1 - strh r2, [r0, 0x4] - ldr r0, [r6] - ldr r3, [sp, 0x50] - cmp r0, r5 - ble _0804EDC4 - str r5, [r6] -_0804EDC4: - ldr r1, _0804EEB0 - add r1, r8 - ldr r0, [r1] - cmp r0, r4 - ble _0804EDD0 - str r4, [r1] -_0804EDD0: - ldr r1, _0804EEB4 - add r1, r8 - ldr r0, [r1] - cmp r0, r5 - bge _0804EDDC - str r5, [r1] -_0804EDDC: - ldr r1, _0804EEBC - add r1, r8 - ldr r0, [r1] - cmp r0, r4 - bge _0804EDE8 - str r4, [r1] -_0804EDE8: - adds r4, 0x1 - ldr r0, [r3, 0xC] - cmp r4, r0 - blt _0804ED98 -_0804EDF0: - ldr r5, [sp, 0x54] - mov r1, r10 - ldr r0, [r1, 0x8] - cmp r5, r0 - blt _0804ED84 -_0804EDFA: - ldr r3, [sp, 0x4C] - ldr r2, [sp, 0x48] - mov r4, r9 - subs r0, r2, r4 - lsls r0, 5 - ldr r7, [sp, 0x40] - adds r1, r0, r7 - adds r0, r3, r1 - movs r4, 0 - ldrsh r5, [r0, r4] - movs r7, 0x4 - ldrsh r0, [r0, r7] - cmp r5, r0 - bge _0804EE6C - mov r8, r1 -_0804EE18: - mov r1, r9 - subs r0, r2, r1 - lsls r0, 5 - ldr r2, [sp, 0x40] - adds r0, r2 - adds r0, r3, r0 - movs r3, 0x2 - ldrsh r4, [r0, r3] - movs r7, 0x6 - ldrsh r0, [r0, r7] - adds r1, r5, 0x1 - str r1, [sp, 0x54] - cmp r4, r0 - bge _0804EE52 - ldr r6, [sp, 0x4C] - add r6, r8 -_0804EE38: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0, 0x4] - movs r1, 0x10 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x1 - movs r2, 0x6 - ldrsh r0, [r6, r2] - cmp r4, r0 - blt _0804EE38 -_0804EE52: - ldr r5, [sp, 0x54] - ldr r3, [sp, 0x4C] - ldr r2, [sp, 0x48] - mov r4, r9 - subs r0, r2, r4 - lsls r0, 5 - ldr r7, [sp, 0x40] - adds r0, r7 - adds r0, r3, r0 - movs r1, 0x4 - ldrsh r0, [r0, r1] - cmp r5, r0 - blt _0804EE18 -_0804EE6C: - ldr r2, _0804EEA4 - ldr r0, [r2] - ldr r1, [r2, 0x8] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r5, r0, 1 - ldr r0, [r2, 0x4] - ldr r1, [r2, 0xC] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r4, r0, 1 - ldr r0, _0804EE94 - strh r5, [r0] - strh r4, [r0, 0x2] - b _0804EED4 - .align 2, 0 -_0804EE90: .4byte gDungeon -_0804EE94: .4byte gUnknown_202F1D8 -_0804EE98: .4byte 0x0000ffff -_0804EE9C: .4byte gUnknown_202F1AB -_0804EEA0: .4byte gUnknown_202F1AA -_0804EEA4: .4byte gUnknown_202F1B8 -_0804EEA8: .4byte 0x0000e240 -_0804EEAC: .4byte 0x0000270f -_0804EEB0: .4byte 0x0000e244 -_0804EEB4: .4byte 0x0000e248 -_0804EEB8: .4byte 0xffffd8f1 -_0804EEBC: .4byte 0x0000e24c -_0804EEC0: .4byte 0x0000fff7 -_0804EEC4: - adds r4, 0x1 - cmp r4, 0xE - bgt _0804EECC - b _0804EC98 -_0804EECC: - adds r5, 0x1 - cmp r5, 0xE - bgt _0804EED4 - b _0804EC84 -_0804EED4: - add sp, 0x58 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804EBC8 - - thumb_func_start sub_804EEE4 -sub_804EEE4: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x108 - str r0, [sp, 0x100] - mov r8, r1 - adds r7, r2, 0 - adds r4, r3, 0 - ldr r5, _0804F094 - ldr r0, [r5] - str r0, [sp, 0x104] - cmp r4, 0 - bne _0804EF04 - b _0804F0C0 -_0804EF04: - movs r0, 0x64 - bl DungeonRandInt - cmp r4, r0 - bgt _0804EF10 - b _0804F0C0 -_0804EF10: - ldr r0, _0804F098 - ldrb r0, [r0] - cmp r0, 0 - beq _0804EF1A - b _0804F0C0 -_0804EF1A: - ldr r0, [r5] - movs r1, 0xD1 - lsls r1, 3 - adds r0, r1 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, 0 - beq _0804EF2C - b _0804F0C0 -_0804EF2C: - bl sub_8043D10 - lsls r0, 24 - cmp r0, 0 - beq _0804EF38 - b _0804F0C0 -_0804EF38: - movs r6, 0 - movs r1, 0 - cmp r1, r8 - bge _0804EF94 -_0804EF40: - adds r2, r1, 0x1 - cmp r7, 0 - ble _0804EF8E - lsls r0, r1, 4 - subs r0, r1 - lsls r0, 5 - ldr r1, [sp, 0x100] - adds r1, 0x8 - adds r1, r0, r1 - adds r3, r7, 0 -_0804EF54: - ldrb r0, [r1] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x9] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x3] - cmp r0, 0 - beq _0804EF86 - ldrb r0, [r1, 0x2] - cmp r0, 0 - beq _0804EF86 - ldrb r0, [r1, 0x4] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x7] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x8] - cmp r0, 0 - bne _0804EF86 - ldrb r0, [r1, 0x1] - cmp r0, 0 - bne _0804EF86 - adds r6, 0x1 -_0804EF86: - adds r1, 0x20 - subs r3, 0x1 - cmp r3, 0 - bne _0804EF54 -_0804EF8E: - adds r1, r2, 0 - cmp r1, r8 - blt _0804EF40 -_0804EF94: - cmp r6, 0 - bne _0804EF9A - b _0804F0C0 -_0804EF9A: - movs r1, 0 - mov r0, sp - adds r0, 0xFF -_0804EFA0: - strb r1, [r0] - subs r0, 0x1 - cmp r0, sp - bge _0804EFA0 - mov r1, sp - movs r0, 0x1 - strb r0, [r1] - movs r5, 0x3F -_0804EFB0: - adds r0, r6, 0 - bl DungeonRandInt - adds r4, r0, 0 - adds r0, r6, 0 - bl DungeonRandInt - mov r3, sp - adds r2, r3, r4 - ldrb r3, [r2] - mov r4, sp - adds r1, r4, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - subs r5, 0x1 - cmp r5, 0 - bge _0804EFB0 - movs r5, 0 - movs r1, 0 - cmp r1, r8 - bge _0804F0C0 - ldr r6, [sp, 0x100] - mov r9, r6 - movs r4, 0 -_0804EFE2: - movs r3, 0 - cmp r3, r7 - bge _0804F0B2 - mov r10, r3 - lsls r0, r4, 5 - ldr r6, [sp, 0x100] - adds r2, r0, r6 -_0804EFF0: - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0x11] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804F0A6 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804F0A6 - ldrb r0, [r2, 0xC] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0xF] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0x10] - cmp r0, 0 - bne _0804F0A6 - ldrb r0, [r2, 0x9] - cmp r0, 0 - bne _0804F0A6 - mov r6, sp - adds r0, r6, r5 - ldrb r0, [r0] - cmp r0, 0 - beq _0804F0A4 - ldr r1, _0804F09C - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x1 - strb r0, [r2, 0xE] - movs r0, 0 - ldrsh r5, [r2, r0] - movs r1, 0x4 - ldrsh r0, [r2, r1] - cmp r5, r0 - bge _0804F0C0 - mov r2, r10 - add r2, r9 - mov r8, r2 -_0804F046: - mov r1, r10 - add r1, r9 - movs r3, 0x2 - ldrsh r4, [r1, r3] - movs r6, 0x6 - ldrsh r0, [r1, r6] - adds r7, r5, 0x1 - cmp r4, r0 - bge _0804F086 - adds r6, r1, 0 -_0804F05A: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - movs r1, 0x40 - orrs r1, r2 - strh r1, [r0] - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTile - ldrb r1, [r0, 0x9] - ldr r2, [sp, 0x104] - ldr r3, _0804F0A0 - adds r0, r2, r3 - strb r1, [r0] - adds r4, 0x1 - movs r1, 0x6 - ldrsh r0, [r6, r1] - cmp r4, r0 - blt _0804F05A -_0804F086: - adds r5, r7, 0 - mov r2, r8 - movs r3, 0x4 - ldrsh r0, [r2, r3] - cmp r5, r0 - blt _0804F046 - b _0804F0C0 - .align 2, 0 -_0804F094: .4byte gDungeon -_0804F098: .4byte gUnknown_202F1AA -_0804F09C: .4byte gUnknown_202F1AB -_0804F0A0: .4byte 0x00003a0c -_0804F0A4: - adds r5, 0x1 -_0804F0A6: - movs r6, 0x20 - add r10, r6 - adds r2, 0x20 - adds r3, 0x1 - cmp r3, r7 - blt _0804EFF0 -_0804F0B2: - movs r0, 0xF0 - lsls r0, 1 - add r9, r0 - adds r4, 0xF - adds r1, 0x1 - cmp r1, r8 - blt _0804EFE2 -_0804F0C0: - add sp, 0x108 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804EEE4 - - thumb_func_start sub_804F0D0 -sub_804F0D0: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x104 - str r0, [sp, 0x100] - mov r10, r1 - mov r9, r2 - adds r4, r3, 0 - ldr r0, _0804F244 - ldr r5, [r0] - cmp r4, 0 - bne _0804F0EE - b _0804F266 -_0804F0EE: - movs r0, 0x64 - bl DungeonRandInt - cmp r4, r0 - bgt _0804F0FA - b _0804F266 -_0804F0FA: - ldr r1, _0804F248 - adds r0, r5, r1 - movs r3, 0 - ldrsh r0, [r0, r3] - cmp r0, 0 - blt _0804F108 - b _0804F266 -_0804F108: - movs r5, 0 - movs r6, 0 - cmp r6, r10 - bge _0804F184 -_0804F110: - adds r7, r6, 0x1 - mov r4, r9 - cmp r4, 0 - ble _0804F17E - lsls r0, r6, 4 - subs r0, r6 - lsls r0, 5 - ldr r6, [sp, 0x100] - adds r2, r0, r6 -_0804F122: - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0x11] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804F176 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804F176 - ldrb r0, [r2, 0xC] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0xF] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0xE] - cmp r0, 0 - bne _0804F176 - ldrb r0, [r2, 0x9] - cmp r0, 0 - bne _0804F176 - movs r1, 0x4 - ldrsh r0, [r2, r1] - movs r3, 0 - ldrsh r1, [r2, r3] - subs r0, r1 - movs r3, 0x1 - ands r0, r3 - cmp r0, 0 - beq _0804F176 - movs r6, 0x6 - ldrsh r0, [r2, r6] - movs r6, 0x2 - ldrsh r1, [r2, r6] - subs r0, r1 - ands r0, r3 - cmp r0, 0 - beq _0804F176 - adds r5, 0x1 -_0804F176: - adds r2, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _0804F122 -_0804F17E: - adds r6, r7, 0 - cmp r6, r10 - blt _0804F110 -_0804F184: - cmp r5, 0 - beq _0804F266 - movs r1, 0 - mov r0, sp - adds r0, 0xFF -_0804F18E: - strb r1, [r0] - subs r0, 0x1 - cmp r0, sp - bge _0804F18E - mov r1, sp - movs r0, 0x1 - strb r0, [r1] - movs r7, 0x3F - mov r8, r7 -_0804F1A0: - adds r0, r5, 0 - bl DungeonRandInt - adds r4, r0, 0 - adds r0, r5, 0 - bl DungeonRandInt - mov r1, sp - adds r2, r1, r4 - ldrb r3, [r2] - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - movs r3, 0x1 - negs r3, r3 - add r8, r3 - mov r4, r8 - cmp r4, 0 - bge _0804F1A0 - movs r6, 0 - mov r8, r6 - cmp r6, r10 - bge _0804F266 - ldr r7, [sp, 0x100] - mov r12, r7 -_0804F1D4: - movs r4, 0 - cmp r4, r9 - bge _0804F25A - mov r2, r12 - mov r5, r12 -_0804F1DE: - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0x11] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0xB] - cmp r0, 0 - beq _0804F250 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804F250 - ldrb r0, [r2, 0xC] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0xF] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0xE] - cmp r0, 0 - bne _0804F250 - ldrb r0, [r2, 0x9] - cmp r0, 0 - bne _0804F250 - movs r1, 0x4 - ldrsh r0, [r2, r1] - movs r3, 0 - ldrsh r1, [r2, r3] - subs r0, r1 - movs r3, 0x1 - ands r0, r3 - cmp r0, 0 - beq _0804F250 - movs r7, 0x6 - ldrsh r0, [r2, r7] - movs r7, 0x2 - ldrsh r1, [r2, r7] - subs r0, r1 - ands r0, r3 - cmp r0, 0 - beq _0804F250 - mov r0, sp - add r0, r8 - ldrb r0, [r0] - cmp r0, 0 - beq _0804F24C - adds r0, r5, 0 - movs r1, 0 - bl sub_804F278 - b _0804F266 - .align 2, 0 -_0804F244: .4byte gDungeon -_0804F248: .4byte 0x00003a16 -_0804F24C: - movs r0, 0x1 - add r8, r0 -_0804F250: - adds r2, 0x20 - adds r5, 0x20 - adds r4, 0x1 - cmp r4, r9 - blt _0804F1DE -_0804F25A: - movs r1, 0xF0 - lsls r1, 1 - add r12, r1 - adds r6, 0x1 - cmp r6, r10 - blt _0804F1D4 -_0804F266: - add sp, 0x104 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F0D0 - - thumb_func_start sub_804F278 -sub_804F278: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - adds r4, r0, 0 - lsls r1, 24 - lsrs r1, 24 - mov r8, r1 - ldr r1, _0804F2B0 - movs r0, 0x1 - strb r0, [r1] - movs r0, 0x1 - strb r0, [r4, 0x10] - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r9, r0 - movs r5, 0 - ldrsh r0, [r4, r5] - adds r6, r0, 0x1 - b _0804F2F0 - .align 2, 0 -_0804F2B0: .4byte gUnknown_202F1AC -_0804F2B4: - movs r2, 0x2 - ldrsh r1, [r4, r2] - subs r1, 0x1 - adds r0, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F2EE - movs r5, 0x2 - ldrsh r3, [r4, r5] - subs r1, r3, 0x1 - movs r0, 0 - ldrsh r2, [r4, r0] - movs r5, 0x4 - ldrsh r0, [r4, r5] - str r0, [sp] - movs r5, 0x6 - ldrsh r0, [r4, r5] - str r0, [sp, 0x4] - mov r0, r8 - str r0, [sp, 0x8] - mov r5, r9 - str r5, [sp, 0xC] - adds r0, r6, 0 - bl sub_804F494 -_0804F2EE: - adds r6, 0x2 -_0804F2F0: - movs r1, 0x4 - ldrsh r0, [r4, r1] - subs r0, 0x1 - cmp r6, r0 - blt _0804F2B4 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r5, r0, 0x1 - movs r6, 0x6 - ldrsh r0, [r4, r6] - b _0804F342 -_0804F306: - movs r1, 0x4 - ldrsh r0, [r4, r1] - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F33C - movs r2, 0x4 - ldrsh r0, [r4, r2] - movs r6, 0 - ldrsh r2, [r4, r6] - movs r1, 0x2 - ldrsh r3, [r4, r1] - str r0, [sp] - movs r6, 0x6 - ldrsh r1, [r4, r6] - str r1, [sp, 0x4] - mov r1, r8 - str r1, [sp, 0x8] - mov r6, r9 - str r6, [sp, 0xC] - adds r1, r5, 0 - bl sub_804F494 -_0804F33C: - adds r5, 0x2 - movs r1, 0x6 - ldrsh r0, [r4, r1] -_0804F342: - subs r0, 0x1 - cmp r5, r0 - blt _0804F306 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r6, r0, 0x1 - movs r5, 0x4 - ldrsh r0, [r4, r5] - b _0804F392 -_0804F354: - movs r0, 0x6 - ldrsh r1, [r4, r0] - adds r0, r6, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F38C - movs r2, 0x6 - ldrsh r1, [r4, r2] - movs r5, 0 - ldrsh r2, [r4, r5] - movs r0, 0x2 - ldrsh r3, [r4, r0] - movs r5, 0x4 - ldrsh r0, [r4, r5] - str r0, [sp] - adds r0, r1, 0 - str r0, [sp, 0x4] - mov r0, r8 - str r0, [sp, 0x8] - mov r5, r9 - str r5, [sp, 0xC] - adds r0, r6, 0 - bl sub_804F494 -_0804F38C: - adds r6, 0x2 - movs r1, 0x4 - ldrsh r0, [r4, r1] -_0804F392: - subs r0, 0x1 - cmp r6, r0 - blt _0804F354 - movs r2, 0x2 - ldrsh r0, [r4, r2] - adds r5, r0, 0x1 - movs r6, 0x6 - ldrsh r0, [r4, r6] - b _0804F3E4 -_0804F3A4: - movs r1, 0 - ldrsh r0, [r4, r1] - subs r0, 0x1 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - beq _0804F3DE - movs r6, 0 - ldrsh r2, [r4, r6] - subs r0, r2, 0x1 - movs r1, 0x2 - ldrsh r3, [r4, r1] - movs r6, 0x4 - ldrsh r1, [r4, r6] - str r1, [sp] - movs r6, 0x6 - ldrsh r1, [r4, r6] - str r1, [sp, 0x4] - mov r1, r8 - str r1, [sp, 0x8] - mov r6, r9 - str r6, [sp, 0xC] - adds r1, r5, 0 - bl sub_804F494 -_0804F3DE: - adds r5, 0x2 - movs r1, 0x6 - ldrsh r0, [r4, r1] -_0804F3E4: - subs r0, 0x1 - cmp r5, r0 - blt _0804F3A4 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r6, r0, 0x3 - b _0804F478 -_0804F3F2: - movs r1, 0x2 - ldrsh r0, [r4, r1] - adds r5, r0, 0x3 - movs r2, 0x6 - ldrsh r0, [r4, r2] - subs r0, 0x3 - adds r1, r6, 0x2 - mov r10, r1 - cmp r5, r0 - bge _0804F476 - ldr r2, _0804F434 - adds r7, r2, 0 -_0804F40A: - adds r0, r6, 0 - adds r1, r5, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0804F46A - mov r0, r8 - cmp r0, 0 - beq _0804F438 - subs r0, r6, 0x1 - adds r1, r5, 0 - bl GetTileMut - ldrh r1, [r0] - ands r1, r7 - movs r2, 0x2 - orrs r1, r2 - b _0804F444 - .align 2, 0 -_0804F434: .4byte 0x0000fffc -_0804F438: - subs r0, r6, 0x1 - adds r1, r5, 0 - bl GetTileMut - ldrh r1, [r0] - ands r1, r7 -_0804F444: - strh r1, [r0] - movs r1, 0 - ldrsh r2, [r4, r1] - movs r0, 0x2 - ldrsh r3, [r4, r0] - movs r1, 0x4 - ldrsh r0, [r4, r1] - str r0, [sp] - movs r1, 0x6 - ldrsh r0, [r4, r1] - str r0, [sp, 0x4] - mov r0, r8 - str r0, [sp, 0x8] - mov r1, r9 - str r1, [sp, 0xC] - adds r0, r6, 0 - adds r1, r5, 0 - bl sub_804F494 -_0804F46A: - adds r5, 0x2 - movs r2, 0x6 - ldrsh r0, [r4, r2] - subs r0, 0x3 - cmp r5, r0 - blt _0804F40A -_0804F476: - mov r6, r10 -_0804F478: - movs r5, 0x4 - ldrsh r0, [r4, r5] - subs r0, 0x3 - cmp r6, r0 - blt _0804F3F2 - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F278 - - thumb_func_start sub_804F494 -sub_804F494: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r5, r0, 0 - adds r4, r1, 0 - str r2, [sp] - str r3, [sp, 0x4] - ldr r0, [sp, 0x30] - ldr r1, [sp, 0x34] - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r1, 24 - mov r8, r1 - movs r0, 0x3 - mov r10, r0 -_0804F4BA: - movs r0, 0x4 - bl DungeonRandInt - adds r6, r0, 0 - movs r7, 0 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl sub_804E9A8 -_0804F4D6: - adds r0, r6, 0 - mov r1, r10 - ands r0, r1 - cmp r0, 0x1 - beq _0804F4F6 - cmp r0, 0x1 - bgt _0804F4EA - cmp r0, 0 - beq _0804F4F0 - b _0804F506 -_0804F4EA: - cmp r0, 0x2 - beq _0804F4FE - b _0804F506 -_0804F4F0: - movs r0, 0x2 - movs r1, 0 - b _0804F50A -_0804F4F6: - movs r0, 0 - movs r1, 0x2 - negs r1, r1 - b _0804F50A -_0804F4FE: - movs r0, 0x2 - negs r0, r0 - movs r1, 0 - b _0804F50A -_0804F506: - movs r0, 0 - movs r1, 0x2 -_0804F50A: - adds r0, r5, r0 - ldr r2, [sp] - cmp r2, r0 - bgt _0804F534 - ldr r3, [sp, 0x28] - cmp r3, r0 - ble _0804F534 - adds r1, r4, r1 - ldr r2, [sp, 0x4] - cmp r2, r1 - bgt _0804F534 - ldr r3, [sp, 0x2C] - cmp r3, r1 - ble _0804F534 - bl GetTile - ldrh r1, [r0] - mov r0, r10 - ands r0, r1 - cmp r0, 0x1 - beq _0804F53E -_0804F534: - adds r6, 0x1 - adds r7, 0x1 - cmp r7, 0x3 - bgt _0804F5B2 - b _0804F4D6 -_0804F53E: - mov r0, r10 - ands r0, r6 - cmp r0, 0x1 - beq _0804F570 - cmp r0, 0x1 - bgt _0804F550 - cmp r0, 0 - beq _0804F55A - b _0804F4BA -_0804F550: - cmp r0, 0x2 - beq _0804F586 - cmp r0, 0x3 - beq _0804F59C - b _0804F4BA -_0804F55A: - adds r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileMut - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl sub_804E9A8 - adds r5, 0x2 - b _0804F4BA -_0804F570: - subs r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileMut - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl sub_804E9A8 - subs r4, 0x2 - b _0804F4BA -_0804F586: - subs r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileMut - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl sub_804E9A8 - subs r5, 0x2 - b _0804F4BA -_0804F59C: - adds r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileMut - mov r1, r9 - mov r3, r8 - lsrs r2, r3, 24 - bl sub_804E9A8 - adds r4, 0x2 - b _0804F4BA -_0804F5B2: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F494 - - thumb_func_start sub_804F5C4 -sub_804F5C4: - ldrh r3, [r0] - ldr r2, _0804F5D4 - ands r2, r3 - movs r3, 0x2 - orrs r2, r3 - orrs r2, r1 - strh r2, [r0] - bx lr - .align 2, 0 -_0804F5D4: .4byte 0x0000fffc - thumb_func_end sub_804F5C4 - - thumb_func_start sub_804F5D8 -sub_804F5D8: - push {r4-r7,lr} - adds r5, r0, 0 - movs r0, 0 - ldrsh r6, [r5, r0] - b _0804F60C -_0804F5E2: - movs r0, 0x2 - ldrsh r4, [r5, r0] - movs r1, 0x6 - ldrsh r0, [r5, r1] - adds r7, r6, 0x1 - cmp r4, r0 - bge _0804F60A -_0804F5F0: - adds r0, r6, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0, 0x4] - movs r1, 0x20 - orrs r1, r2 - strh r1, [r0, 0x4] - adds r4, 0x1 - movs r1, 0x6 - ldrsh r0, [r5, r1] - cmp r4, r0 - blt _0804F5F0 -_0804F60A: - adds r6, r7, 0 -_0804F60C: - movs r1, 0x4 - ldrsh r0, [r5, r1] - cmp r6, r0 - blt _0804F5E2 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F5D8 - - thumb_func_start sub_804F61C -sub_804F61C: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - mov r9, r0 - mov r8, r1 - movs r7, 0x1 - negs r7, r7 - b _0804F67A -_0804F62E: - movs r5, 0x1 - negs r5, r5 - b _0804F666 -_0804F634: - cmp r7, 0 - beq _0804F63C - cmp r5, 0 - bne _0804F660 -_0804F63C: - adds r0, r6, 0 - adds r1, r4, 0 - bl GetTile - ldrh r1, [r0] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0x1 - bne _0804F660 - adds r0, r6, 0 - adds r1, r4, 0 - bl GetTile - ldrb r0, [r0, 0x9] - cmp r0, 0xFF - bne _0804F660 - movs r0, 0x1 - b _0804F686 -_0804F660: - adds r5, 0x1 - cmp r5, 0x1 - bgt _0804F672 -_0804F666: - mov r0, r8 - adds r4, r0, r5 - cmp r4, 0 - blt _0804F660 - cmp r4, 0x1F - ble _0804F634 -_0804F672: - adds r7, 0x1 - cmp r7, 0x1 - bgt _0804F684 - mov r0, r9 -_0804F67A: - adds r6, r0, r7 - cmp r6, 0 - blt _0804F672 - cmp r6, 0x37 - ble _0804F62E -_0804F684: - movs r0, 0 -_0804F686: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_804F61C - - thumb_func_start sub_804F694 -sub_804F694: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r7, r0, 0 - movs r0, 0x6 - bl DungeonRandInt - subs r0, 0x1 - cmp r0, 0x4 - bls _0804F6B0 - b _0804FBD6 -_0804F6B0: - lsls r0, 2 - ldr r1, _0804F6BC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_0804F6BC: .4byte _0804F6C0 - .align 2, 0 -_0804F6C0: - .4byte _0804FB24 - .4byte _0804FA98 - .4byte _0804F9DC - .4byte _0804F826 - .4byte _0804F6D4 -_0804F6D4: - ldr r1, _0804F70C - ldr r0, [r1] - cmp r0, 0 - bne _0804F6DE - b _0804FBD6 -_0804F6DE: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl sub_804F5D8 - movs r0, 0x2 - bl DungeonRandInt - cmp r0, 0 - beq _0804F78E - movs r5, 0 - movs r1, 0 - ldrsh r0, [r7, r1] - movs r2, 0x4 - ldrsh r1, [r7, r2] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - mov r8, r0 - movs r3, 0x2 - ldrsh r4, [r7, r3] - b _0804F712 - .align 2, 0 -_0804F70C: .4byte gUnknown_202F1C8 -_0804F710: - adds r4, 0x1 -_0804F712: - movs r1, 0x6 - ldrsh r0, [r7, r1] - cmp r4, r0 - bge _0804F72A - mov r0, r8 - adds r1, r4, 0 - bl sub_804F61C - lsls r0, 24 - cmp r0, 0 - beq _0804F710 - movs r5, 0x1 -_0804F72A: - cmp r5, 0 - beq _0804F730 - b _0804FBD6 -_0804F730: - movs r2, 0x2 - ldrsh r4, [r7, r2] - movs r3, 0x6 - ldrsh r0, [r7, r3] - cmp r4, r0 - bge _0804F754 -_0804F73C: - mov r0, r8 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 - adds r4, 0x1 - movs r5, 0x6 - ldrsh r0, [r7, r5] - cmp r4, r0 - blt _0804F73C -_0804F754: - movs r0, 0 - ldrsh r5, [r7, r0] - cmp r5, r8 - blt _0804F75E - b _0804FBD2 -_0804F75E: - movs r1, 0x2 - ldrsh r4, [r7, r1] - movs r2, 0x6 - ldrsh r0, [r7, r2] - adds r6, r5, 0x1 - cmp r4, r0 - bge _0804F786 -_0804F76C: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - ldrh r2, [r0] - movs r1, 0x80 - orrs r1, r2 - strh r1, [r0] - adds r4, 0x1 - movs r3, 0x6 - ldrsh r0, [r7, r3] - cmp r4, r0 - blt _0804F76C -_0804F786: - adds r5, r6, 0 - cmp r5, r8 - blt _0804F75E - b _0804FBD2 -_0804F78E: - movs r5, 0 - movs r4, 0x2 - ldrsh r0, [r7, r4] - movs r2, 0x6 - ldrsh r1, [r7, r2] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - mov r8, r0 - movs r3, 0 - ldrsh r4, [r7, r3] - b _0804F7AA -_0804F7A8: - adds r4, 0x1 -_0804F7AA: - movs r1, 0x4 - ldrsh r0, [r7, r1] - cmp r4, r0 - bge _0804F7C2 - adds r0, r4, 0 - mov r1, r8 - bl sub_804F61C - lsls r0, 24 - cmp r0, 0 - beq _0804F7A8 - movs r5, 0x1 -_0804F7C2: - cmp r5, 0 - beq _0804F7C8 - b _0804FBD6 -_0804F7C8: - movs r2, 0 - ldrsh r4, [r7, r2] - movs r3, 0x4 - ldrsh r0, [r7, r3] - cmp r4, r0 - bge _0804F7EC -_0804F7D4: - adds r0, r4, 0 - mov r1, r8 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 - adds r4, 0x1 - movs r5, 0x4 - ldrsh r0, [r7, r5] - cmp r4, r0 - blt _0804F7D4 -_0804F7EC: - movs r0, 0x2 - ldrsh r5, [r7, r0] - cmp r5, r8 - blt _0804F7F6 - b _0804FBD2 -_0804F7F6: - movs r1, 0 - ldrsh r4, [r7, r1] - movs r2, 0x4 - ldrsh r0, [r7, r2] - adds r6, r5, 0x1 - cmp r4, r0 - bge _0804F81E -_0804F804: - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileMut - ldrh r2, [r0] - movs r1, 0x80 - orrs r1, r2 - strh r1, [r0] - adds r4, 0x1 - movs r3, 0x4 - ldrsh r0, [r7, r3] - cmp r4, r0 - blt _0804F804 -_0804F81E: - adds r5, r6, 0 - cmp r5, r8 - blt _0804F7F6 - b _0804FBD2 -_0804F826: - movs r4, 0x4 - ldrsh r3, [r7, r4] - movs r5, 0 - ldrsh r1, [r7, r5] - subs r0, r3, r1 - cmp r0, 0x5 - bgt _0804F836 - b _0804FBD6 -_0804F836: - movs r0, 0x6 - ldrsh r4, [r7, r0] - movs r5, 0x2 - ldrsh r2, [r7, r5] - subs r0, r4, r2 - cmp r0, 0x5 - bgt _0804F846 - b _0804FBD6 -_0804F846: - adds r0, r1, r3 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - str r0, [sp] - adds r0, r2, r4 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - str r0, [sp, 0x4] - ldr r1, _0804F9D8 - ldr r0, [r1] - cmp r0, 0 - bne _0804F864 - b _0804FBD6 -_0804F864: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl sub_804F5D8 - ldr r5, [sp] - subs r5, 0x2 - ldr r0, [sp, 0x4] - subs r0, 0x2 - mov r10, r0 - adds r0, r5, 0 - mov r1, r10 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - ldr r1, [sp] - subs r1, 0x1 - mov r9, r1 - mov r0, r9 - mov r1, r10 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - ldr r0, [sp] - mov r1, r10 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - ldr r2, [sp] - adds r2, 0x1 - mov r8, r2 - mov r0, r8 - mov r1, r10 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - ldr r6, [sp, 0x4] - subs r6, 0x1 - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - adds r0, r5, 0 - ldr r1, [sp, 0x4] - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - ldr r4, [sp, 0x4] - adds r4, 0x1 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r9 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - ldr r0, [sp] - adds r1, r4, 0 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - mov r1, r10 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - adds r1, r6, 0 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - ldr r1, [sp, 0x4] - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r8 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0x4 - bl sub_804F5C4 - mov r0, r9 - adds r1, r6, 0 - bl GetTileMut - ldrh r2, [r0, 0x4] - movs r1, 0x4 - orrs r1, r2 - strh r1, [r0, 0x4] - mov r0, r9 - adds r1, r6, 0 - bl GetTileMut - ldrh r1, [r0, 0x4] - movs r2, 0x40 - orrs r1, r2 - strh r1, [r0, 0x4] - ldr r0, [sp] - adds r1, r6, 0 - bl GetTileMut - ldrh r1, [r0, 0x4] - movs r4, 0x2 - orrs r1, r4 - strh r1, [r0, 0x4] - mov r0, r9 - ldr r1, [sp, 0x4] - bl GetTileMut - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - ldr r0, [sp] - ldr r1, [sp, 0x4] - bl GetTileMut - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - mov r0, r9 - adds r1, r6, 0 - bl GetTileMut - ldrh r1, [r0, 0x4] - movs r4, 0x10 - orrs r1, r4 - strh r1, [r0, 0x4] - ldr r0, [sp] - adds r1, r6, 0 - bl GetTileMut - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - mov r0, r9 - ldr r1, [sp, 0x4] - bl GetTileMut - ldrh r1, [r0, 0x4] - orrs r1, r4 - strh r1, [r0, 0x4] - ldr r0, [sp] - ldr r1, [sp, 0x4] - bl GetTileMut - ldrh r1, [r0, 0x4] - orrs r4, r1 - strh r4, [r0, 0x4] - b _0804FBD2 - .align 2, 0 -_0804F9D8: .4byte gUnknown_202F1C8 -_0804F9DC: - movs r4, 0x4 - ldrsh r3, [r7, r4] - movs r5, 0 - ldrsh r2, [r7, r5] - subs r0, r3, r2 - cmp r0, 0x4 - bgt _0804F9EC - b _0804FBD6 -_0804F9EC: - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r4, 0x2 - ldrsh r1, [r7, r4] - subs r0, r1 - cmp r0, 0x4 - bgt _0804F9FC - b _0804FBD6 -_0804F9FC: - adds r0, r2, 0x2 - subs r1, r3, 0x3 - bl DungeonRandRange - adds r4, r0, 0 - movs r5, 0x2 - ldrsh r0, [r7, r5] - adds r0, 0x2 - movs r2, 0x6 - ldrsh r1, [r7, r2] - subs r1, 0x3 - bl DungeonRandRange - mov r10, r0 - movs r3, 0 - ldrsh r0, [r7, r3] - adds r0, 0x2 - movs r5, 0x4 - ldrsh r1, [r7, r5] - subs r1, 0x3 - bl DungeonRandRange - mov r9, r0 - movs r1, 0x2 - ldrsh r0, [r7, r1] - adds r0, 0x2 - movs r2, 0x6 - ldrsh r1, [r7, r2] - subs r1, 0x3 - bl DungeonRandRange - adds r6, r0, 0 - ldr r1, _0804FA94 - ldr r0, [r1] - cmp r0, 0 - bne _0804FA46 - b _0804FBD6 -_0804FA46: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl sub_804F5D8 - cmp r4, r9 - ble _0804FA5A - adds r0, r4, 0 - mov r4, r9 - mov r9, r0 -_0804FA5A: - cmp r10, r6 - ble _0804FA64 - mov r0, r10 - mov r10, r6 - adds r6, r0, 0 -_0804FA64: - adds r5, r4, 0 - cmp r5, r9 - ble _0804FA6C - b _0804FBD2 -_0804FA6C: - mov r4, r10 - adds r3, r5, 0x1 - mov r8, r3 - cmp r4, r6 - bgt _0804FA8A -_0804FA76: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 - adds r4, 0x1 - cmp r4, r6 - ble _0804FA76 -_0804FA8A: - mov r5, r8 - cmp r5, r9 - ble _0804FA6C - b _0804FBD2 - .align 2, 0 -_0804FA94: .4byte gUnknown_202F1C8 -_0804FA98: - movs r4, 0x4 - ldrsh r0, [r7, r4] - movs r5, 0 - ldrsh r1, [r7, r5] - subs r0, r1 - movs r2, 0x1 - ands r0, r2 - cmp r0, 0 - bne _0804FAAC - b _0804FBD6 -_0804FAAC: - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r3, 0x2 - ldrsh r1, [r7, r3] - subs r0, r1 - ands r0, r2 - cmp r0, 0 - bne _0804FABE - b _0804FBD6 -_0804FABE: - ldr r1, _0804FB20 - ldr r0, [r1] - cmp r0, 0 - bne _0804FAC8 - b _0804FBD6 -_0804FAC8: - subs r0, 0x1 - str r0, [r1] - adds r0, r7, 0 - bl sub_804F5D8 - movs r6, 0x3F -_0804FAD4: - movs r4, 0x4 - ldrsh r0, [r7, r4] - movs r5, 0 - ldrsh r1, [r7, r5] - subs r0, r1 - bl DungeonRandInt - adds r4, r0, 0 - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r2, 0x2 - ldrsh r1, [r7, r2] - subs r0, r1 - bl DungeonRandInt - adds r2, r0, 0 - adds r0, r4, r2 - movs r5, 0x1 - ands r0, r5 - cmp r0, 0 - beq _0804FB14 - movs r3, 0 - ldrsh r0, [r7, r3] - adds r0, r4 - movs r4, 0x2 - ldrsh r1, [r7, r4] - adds r1, r2 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 -_0804FB14: - subs r6, 0x1 - cmp r6, 0 - bge _0804FAD4 - strb r5, [r7, 0x9] - b _0804FBD6 - .align 2, 0 -_0804FB20: .4byte gUnknown_202F1C8 -_0804FB24: - ldr r1, _0804FBC0 - ldr r0, [r1] - cmp r0, 0 - beq _0804FBD6 - subs r0, 0x1 - str r0, [r1] - movs r5, 0x4 - ldrsh r3, [r7, r5] - movs r0, 0 - ldrsh r2, [r7, r0] - subs r6, r3, r2 - movs r4, 0x1 - adds r0, r6, 0 - ands r0, r4 - cmp r0, 0 - beq _0804FB54 - movs r1, 0x6 - ldrsh r0, [r7, r1] - movs r5, 0x2 - ldrsh r1, [r7, r5] - subs r0, r1 - ands r0, r4 - cmp r0, 0 - bne _0804FBC4 -_0804FB54: - adds r0, r2, r3 - lsrs r1, r0, 31 - adds r0, r1 - asrs r5, r0, 1 - movs r0, 0x2 - ldrsh r3, [r7, r0] - movs r1, 0x6 - ldrsh r2, [r7, r1] - adds r0, r3, r2 - lsrs r1, r0, 31 - adds r0, r1 - asrs r4, r0, 1 - cmp r6, 0x4 - ble _0804FBAE - subs r0, r2, r3 - cmp r0, 0x4 - ble _0804FBAE - adds r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 - adds r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 - subs r0, r5, 0x1 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 - subs r1, r4, 0x1 - adds r0, r5, 0 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 -_0804FBAE: - adds r0, r5, 0 - adds r1, r4, 0 - bl GetTileMut - movs r1, 0 - bl sub_804F5C4 - b _0804FBD2 - .align 2, 0 -_0804FBC0: .4byte gUnknown_202F1C8 -_0804FBC4: - adds r0, r7, 0 - bl sub_804F5D8 - adds r0, r7, 0 - movs r1, 0x1 - bl sub_804F278 -_0804FBD2: - movs r0, 0x1 - strb r0, [r7, 0x9] -_0804FBD6: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_804F694 - - .align 2,0 diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index 96fb070ae..d3ee800d0 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -5,395 +5,6 @@ .text - thumb_func_start sub_8051654 -sub_8051654: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - str r0, [sp] - ldr r4, _080516EC - ldr r1, [r4, 0x8] - ldr r0, [r4] - subs r1, r0 - subs r1, 0x2 - movs r0, 0x3 - bl DungeonRandRange - mov r8, r0 - cmp r0, 0x2 - bgt _0805167C - movs r0, 0x3 - mov r8, r0 -_0805167C: - ldr r1, [r4, 0xC] - ldr r0, [r4, 0x4] - subs r1, r0 - subs r1, 0x2 - movs r0, 0x3 - bl DungeonRandRange - mov r9, r0 - cmp r0, 0x2 - bgt _08051694 - movs r1, 0x3 - mov r9, r1 -_08051694: - movs r0, 0x2 - movs r1, 0x4 - bl DungeonRandRange - mov r10, r0 - movs r5, 0 - cmp r5, r10 - bge _08051734 - ldr r0, [r4, 0x8] - ldr r1, [r4] - subs r0, r1 - cmp r0, r8 - ble _08051734 - adds r6, r4, 0 -_080516B0: - movs r0, 0x64 - bl DungeonRandInt - cmp r0, 0x31 - bgt _080516F4 - ldr r4, [r6, 0x4] - ldr r0, [r6, 0xC] - adds r7, r5, 0x1 - cmp r4, r0 - bge _080516E4 - ldr r5, _080516EC - ldr r0, _080516F0 - adds r2, r0, 0 -_080516CA: - ldr r0, [r5] - adds r1, r4, 0 - str r2, [sp, 0xC] - bl GetTileMut - ldrh r1, [r0] - ldr r2, [sp, 0xC] - ands r1, r2 - strh r1, [r0] - adds r4, 0x1 - ldr r0, [r5, 0xC] - cmp r4, r0 - blt _080516CA -_080516E4: - ldr r0, [r6] - adds r0, 0x1 - str r0, [r6] - b _08051724 - .align 2, 0 -_080516EC: .4byte sKecleonShopPosition -_080516F0: .4byte 0x0000ffdf -_080516F4: - ldr r0, [r6, 0x8] - subs r0, 0x1 - str r0, [r6, 0x8] - ldr r4, [r6, 0x4] - ldr r0, [r6, 0xC] - adds r7, r5, 0x1 - cmp r4, r0 - bge _08051724 - ldr r5, _08051784 - ldr r1, _08051788 - adds r2, r1, 0 -_0805170A: - ldr r0, [r5, 0x8] - adds r1, r4, 0 - str r2, [sp, 0xC] - bl GetTileMut - ldrh r1, [r0] - ldr r2, [sp, 0xC] - ands r1, r2 - strh r1, [r0] - adds r4, 0x1 - ldr r0, [r5, 0xC] - cmp r4, r0 - blt _0805170A -_08051724: - adds r5, r7, 0 - cmp r5, r10 - bge _08051734 - ldr r0, [r6, 0x8] - ldr r1, [r6] - subs r0, r1 - cmp r0, r8 - bgt _080516B0 -_08051734: - movs r5, 0 - ldr r3, _08051784 - cmp r5, r10 - bge _080517CE - ldr r0, [r3, 0xC] - ldr r1, [r3, 0x4] - subs r0, r1 - cmp r0, r9 - ble _080517CE - adds r6, r3, 0 -_08051748: - movs r0, 0x64 - bl DungeonRandInt - cmp r0, 0x31 - bgt _0805178C - ldr r4, [r6] - ldr r0, [r6, 0x8] - adds r7, r5, 0x1 - cmp r4, r0 - bge _0805177C - ldr r5, _08051784 - ldr r0, _08051788 - adds r2, r0, 0 -_08051762: - ldr r1, [r5, 0x4] - adds r0, r4, 0 - str r2, [sp, 0xC] - bl GetTileMut - ldrh r1, [r0] - ldr r2, [sp, 0xC] - ands r1, r2 - strh r1, [r0] - adds r4, 0x1 - ldr r0, [r5, 0x8] - cmp r4, r0 - blt _08051762 -_0805177C: - ldr r0, [r6, 0x4] - adds r0, 0x1 - str r0, [r6, 0x4] - b _080517BC - .align 2, 0 -_08051784: .4byte sKecleonShopPosition -_08051788: .4byte 0x0000ffdf -_0805178C: - ldr r0, [r6, 0xC] - subs r0, 0x1 - str r0, [r6, 0xC] - ldr r4, [r6] - ldr r0, [r6, 0x8] - adds r7, r5, 0x1 - cmp r4, r0 - bge _080517BC - ldr r5, _080518E4 - ldr r1, _080518E8 - adds r2, r1, 0 -_080517A2: - ldr r1, [r5, 0xC] - adds r0, r4, 0 - str r2, [sp, 0xC] - bl GetTileMut - ldrh r1, [r0] - ldr r2, [sp, 0xC] - ands r1, r2 - strh r1, [r0] - adds r4, 0x1 - ldr r0, [r5, 0x8] - cmp r4, r0 - blt _080517A2 -_080517BC: - adds r5, r7, 0 - ldr r3, _080518E4 - cmp r5, r10 - bge _080517CE - ldr r1, [r6, 0xC] - ldr r0, [r6, 0x4] - subs r1, r0 - cmp r1, r9 - bgt _08051748 -_080517CE: - ldr r7, [r3] - ldr r0, [r3, 0x8] - cmp r7, r0 - bge _08051824 - adds r4, r3, 0 - mov r9, r3 -_080517DA: - ldr r5, [r4, 0x4] - ldr r0, [r4, 0xC] - adds r1, r7, 0x1 - mov r8, r1 - cmp r5, r0 - bge _0805181A - ldr r3, _080518E4 - ldr r0, _080518E8 - adds r6, r0, 0 -_080517EC: - adds r0, r7, 0 - adds r1, r5, 0 - str r3, [sp, 0x10] - bl GetTileMut - adds r2, r0, 0 - ldrh r1, [r2] - movs r0, 0x20 - ands r0, r1 - ldr r3, [sp, 0x10] - cmp r0, 0 - beq _08051812 - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08051812 - adds r0, r1, 0 - ands r0, r6 - strh r0, [r2] -_08051812: - adds r5, 0x1 - ldr r0, [r4, 0xC] - cmp r5, r0 - blt _080517EC -_0805181A: - mov r7, r8 - mov r1, r9 - ldr r0, [r1, 0x8] - cmp r7, r0 - blt _080517DA -_08051824: - ldr r0, [r3] - ldr r1, [r3, 0x8] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r2, r0, 1 - ldr r0, [r3, 0x4] - ldr r1, [r3, 0xC] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - subs r0, 0x1 - mov r10, r0 - movs r0, 0 - mov r9, r0 - subs r7, r2, 0x1 - adds r0, r2, 0x2 - cmp r7, r0 - bge _080518D2 - adds r2, r0, 0 - str r2, [sp, 0x4] -_08051850: - mov r5, r10 - adds r0, r5, 0x3 - adds r1, r7, 0x1 - mov r8, r1 - mov r1, r9 - adds r1, 0x1 - str r1, [sp, 0x8] - cmp r5, r0 - bge _080518C6 - movs r3, 0 -_08051864: - adds r0, r7, 0 - adds r1, r5, 0 - str r3, [sp, 0x10] - bl GetTileMut - adds r6, r0, 0 - ldrh r1, [r6] - movs r0, 0x20 - ands r0, r1 - ldr r3, [sp, 0x10] - cmp r0, 0 - beq _080518BA - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - bne _080518BA - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - bne _080518BA - mov r0, r9 - lsls r2, r0, 1 - adds r2, r3 - ldr r0, [sp] - ldrb r1, [r0, 0x18] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 1 - adds r2, r0 - ldr r1, _080518EC - adds r2, r1 - movs r0, 0 - ldrsh r4, [r2, r0] - movs r0, 0x64 - bl DungeonRandInt - ldr r3, [sp, 0x10] - cmp r4, r0 - ble _080518BA - ldrh r1, [r6, 0x4] - movs r0, 0x2 - orrs r0, r1 - strh r0, [r6, 0x4] -_080518BA: - adds r5, 0x1 - adds r3, 0x6 - mov r0, r10 - adds r0, 0x3 - cmp r5, r0 - blt _08051864 -_080518C6: - mov r7, r8 - ldr r1, [sp, 0x8] - mov r9, r1 - ldr r0, [sp, 0x4] - cmp r7, r0 - blt _08051850 -_080518D2: - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080518E4: .4byte sKecleonShopPosition -_080518E8: .4byte 0x0000ffdf -_080518EC: .4byte gUnknown_80F57D4 - thumb_func_end sub_8051654 - - thumb_func_start sub_80518F0 -sub_80518F0: - push {r4-r7,lr} - movs r5, 0 - movs r6, 0x10 - movs r7, 0 -_080518F8: - adds r0, r5, 0 - movs r1, 0x1 - bl GetTileMut - adds r4, r0, 0 - bl ResetTile - cmp r5, 0 - beq _0805190E - cmp r5, 0x37 - bne _08051914 -_0805190E: - ldrh r0, [r4] - orrs r0, r6 - strh r0, [r4] -_08051914: - adds r0, r5, 0 - movs r1, 0x1E - bl GetTileMut - adds r4, r0, 0 - bl ResetTile - cmp r5, 0 - beq _0805192A - cmp r5, 0x37 - bne _08051930 -_0805192A: - ldrh r0, [r4] - orrs r0, r6 - strh r0, [r4] -_08051930: - adds r5, 0x1 - cmp r5, 0x37 - ble _080518F8 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80518F0 thumb_func_start sub_805193C sub_805193C: diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 3552b93e7..a54ba636a 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -120,7 +120,8 @@ typedef struct UnkDungeonGlobal_unk181E8_sub #define ROOM_FLAG_ALLOW_IMPERFECTIONS 0x4 // Sizeof: 0x1C -typedef struct UnkDungeonGlobal_unk1C574 +// Defines many of the key properties for dungeon generation, such as the type of layout, base number of rooms, and floor connectivity. +typedef struct FloorProperties { u8 unk0; s8 roomDensity; @@ -149,7 +150,7 @@ typedef struct UnkDungeonGlobal_unk1C574 u8 unk18; u8 unk19; u8 unk1A; -} UnkDungeonGlobal_unk1C574; +} FloorProperties; typedef struct UnkDungeonGlobal_unk1C590 { @@ -428,7 +429,7 @@ typedef struct Dungeon struct UnkStructDungeon1BDD4 unk1BDD4; struct MessageLogString messageLogStrings[MESSAGE_LOG_STRINGS_COUNT]; /* 0x1C570 */ DungeonLocation unk1C570; - /* 0x1C574 */ UnkDungeonGlobal_unk1C574 unk1C574; + /* 0x1C574 */ FloorProperties unk1C574; /* 0x1C590 */ UnkDungeonGlobal_unk1C590 unk1C590[4]; u16 unk1CD70[20]; UnkDungeonGlobal_unk1CD98 unk1CD98[32]; diff --git a/src/code_803D110.c b/src/code_803D110.c index 85ee55690..d50933701 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -54,7 +54,7 @@ struct UnkDungeonFileData struct UnkDataFileStruct { struct UnkDungeonFileData **unk0; - UnkDungeonGlobal_unk1C574 *unk4; + FloorProperties *unk4; u16 **unk8; UnkDungeonGlobal_unk1CD98 **unkC; u16 **unk10; diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index ce503bacd..4397f6f91 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -13,7 +13,6 @@ extern struct FileArchive gDungeonFileArchive; extern void ResetFloor(void); extern void ResetFloor(void); -extern void sub_80518F0(void); extern void GenerateOneRoomMonsterHouseFloor(void); extern void ResolveInvalidSpawns(void); extern void GenerateTwoRoomsWithMonsterHouseFloor(void); @@ -66,7 +65,7 @@ struct GridCell #define GRID_CELL_LEN 15 -static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr); +static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, FloorProperties *floorProps); static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 fixedRoomSizeX, s32 fixedRoomSizeY); void sub_8051438(struct GridCell *gridCell, s32 fixedRoomId); void sub_8051288(s32 fixedRoomId); @@ -79,8 +78,8 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY); -static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr); -void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr); +static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps); +void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps); void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain); void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex); @@ -94,19 +93,20 @@ void sub_804FC74(void); void sub_804EB30(void); void sub_804E9DC(void); void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); -bool8 GenerateFixedFloor(s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr); -void GenerateStandardFloor(s32 a0, s32 a1, UnkDungeonGlobal_unk1C574 *a2); -void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *a0); -void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *a0); -void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *a0); -void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *a0); -void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *a0); -void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr); -void sub_8051654(UnkDungeonGlobal_unk1C574 *unkPtr); -void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr); -void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); -void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse); +bool8 GenerateFixedFloor(s32 fixedRoomId, FloorProperties *floorProps); +void GenerateStandardFloor(s32 a0, s32 a1, FloorProperties *a2); +void GenerateOuterRingFloor(FloorProperties *a0); +void GenerateCrossroadsFloor(FloorProperties *a0); +void GenerateLineFloor(FloorProperties *a0); +void GenerateCrossFloor(FloorProperties *a0); +void GenerateBeetleFloor(FloorProperties *a0); +void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps); +void sub_8051654(FloorProperties *floorProps); +void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps); +void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); +void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); +void ResetInnerBoundaryTileRows(void); EWRAM_DATA u8 gUnknown_202F1A8 = 0; EWRAM_DATA u8 gUnknown_202F1A9 = 0; @@ -167,7 +167,7 @@ void sub_804AFAC(void) s32 x, y; s32 i, j, k; bool8 r10 = FALSE; - UnkDungeonGlobal_unk1C574 *unkPtr = &gDungeon->unk1C574; + FloorProperties *floorProps = &gDungeon->unk1C574; gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); sHasKecleonShop = FALSE; @@ -176,8 +176,8 @@ void sub_804AFAC(void) gUnknown_202F1A8 = (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_WATER); sStairsRoomIndex = 0xFF; sFloorSize = 0; - sKecleonShopChance = unkPtr->kecleonShopChance; - sMonsterHouseChance = unkPtr->monsterHouseChance; + sKecleonShopChance = floorProps->kecleonShopChance; + sMonsterHouseChance = floorProps->monsterHouseChance; sSecondSpawn = 1; sKecleonShopPosition.unk0 = -1; sKecleonShopPosition.unk8 = -1; @@ -186,12 +186,12 @@ void sub_804AFAC(void) ResetFloor(); - gDungeon->unk664 = unkPtr->unk6; + gDungeon->unk664 = floorProps->unk6; gDungeon->unk3A09 = 0; gDungeon->unk3A0A = 0; - sSecondaryStructuresBudget = unkPtr->secondaryStructuresBudget; + sSecondaryStructuresBudget = floorProps->secondaryStructuresBudget; for (i = 0; i < 10; i++) { bool32 r4 = 0; @@ -214,12 +214,12 @@ void sub_804AFAC(void) gDungeon->forceMonsterHouse = 0; if (gDungeon->fixedRoomId != 0) { // Check for a full-floor fixed room, if this is the case, generation is done. - if (GenerateFixedFloor(gDungeon->fixedRoomId, unkPtr)) { + if (GenerateFixedFloor(gDungeon->fixedRoomId, floorProps)) { break; } } else { - u8 r7 = unkPtr->unk0; + u8 r7 = floorProps->unk0; k = 32; while (1) { @@ -256,18 +256,18 @@ void sub_804AFAC(void) case 1: y = DungeonRandInt(2) + 2; sFloorSize = 1; - GenerateStandardFloor(4, y, unkPtr); + GenerateStandardFloor(4, y, floorProps); r10 = TRUE; break; case 11: y = DungeonRandInt(2) + 2; sFloorSize = 2; - GenerateStandardFloor(4, y, unkPtr); + GenerateStandardFloor(4, y, floorProps); r10 = TRUE; break; case 0: default: - GenerateStandardFloor(x, y, unkPtr); + GenerateStandardFloor(x, y, floorProps); r10 = TRUE; break; case 2: @@ -275,11 +275,11 @@ void sub_804AFAC(void) gDungeon->forceMonsterHouse = 1; break; case 3: - GenerateOuterRingFloor(unkPtr); + GenerateOuterRingFloor(floorProps); r10 = TRUE; break; case 4: - GenerateCrossroadsFloor(unkPtr); + GenerateCrossroadsFloor(floorProps); r10 = TRUE; break; case 5: @@ -287,23 +287,23 @@ void sub_804AFAC(void) gDungeon->forceMonsterHouse = 1; break; case 6: - GenerateLineFloor(unkPtr); + GenerateLineFloor(floorProps); r10 = TRUE; break; case 7: - GenerateCrossFloor(unkPtr); + GenerateCrossFloor(floorProps); break; case 9: - GenerateBeetleFloor(unkPtr); + GenerateBeetleFloor(floorProps); break; case 10: - GenerateOuterRoomsFloor(x, y, unkPtr); + GenerateOuterRoomsFloor(x, y, floorProps); r10 = TRUE; break; } } - sub_80518F0(); + ResetInnerBoundaryTileRows(); EnsureImpassableTilesAreWalls(); if (gUnknown_202F1A9 == 0) { s32 countSp = 0; @@ -348,11 +348,11 @@ void sub_804AFAC(void) } sub_804E9DC(); if (r10) { - GenerateSecondaryTerrainFormations(1, unkPtr); + GenerateSecondaryTerrainFormations(1, floorProps); } - r4 = (DungeonRandInt(100) < unkPtr->connectedToTop); - SpawnNonEnemies(unkPtr, r4); - SpawnEnemies(unkPtr, r4); + r4 = (DungeonRandInt(100) < floorProps->connectedToTop); + SpawnNonEnemies(floorProps, r4); + SpawnEnemies(floorProps, r4); ResolveInvalidSpawns(); if (gDungeon->playerSpawn.x != -1 && gDungeon->playerSpawn.y != -1) { @@ -370,8 +370,8 @@ void sub_804AFAC(void) GenerateOneRoomMonsterHouseFloor(); gDungeon->forceMonsterHouse = TRUE; sub_804E9DC(); - SpawnNonEnemies(unkPtr, FALSE); - SpawnEnemies(unkPtr, FALSE); + SpawnNonEnemies(floorProps, FALSE); + SpawnEnemies(floorProps, FALSE); ResolveInvalidSpawns(); } @@ -380,7 +380,7 @@ void sub_804AFAC(void) } if (sKecleonShopPosition.unk0 >= 0) { - sub_8051654(unkPtr); + sub_8051654(floorProps); gDungeon->unk3A0A = 1; } else { @@ -773,7 +773,7 @@ void NAKED sub_804AFAC(void) " movs r1, 0x1\n" " mov r10, r1\n" "_0804B2F6:\n" -" bl sub_80518F0\n" +" bl ResetInnerBoundaryTileRows\n" " bl EnsureImpassableTilesAreWalls\n" " ldr r0, _0804B4B4\n" " ldrb r0, [r0]\n" @@ -1083,7 +1083,7 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) * 6. Create additional "extra hallways" with random walks outside of existing rooms * 7. Finalize extra room details with imperfections (unused in vanilla?), and structures with secondary terrain */ -void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1093,26 +1093,26 @@ void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C5 InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->roomDensity); + AssignRooms(grid, gridSizeX, gridSizeY, floorProps->roomDensity); - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); - AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, floorProps); CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->mazeRoomChance); + GenerateMazeRoom(grid, gridSizeX, gridSizeY, floorProps->mazeRoomChance); GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } // GenerateOuterRingFloor - Generates on a 6x4 grid, with the outer border of grid cells being hallways and the inner 4x2 grid being rooms. -void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateOuterRingFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1245,7 +1245,7 @@ void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *unkPtr) grid[5][2].connectedToBottom = TRUE; grid[5][3].connectedToTop = TRUE; - AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, floorProps); CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); @@ -1253,7 +1253,7 @@ void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *unkPtr) GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } @@ -1261,7 +1261,7 @@ void GenerateOuterRingFloor(UnkDungeonGlobal_unk1C574 *unkPtr) * GenerateCrossroadsFloor - Generates a floor layout with hallways on the inside and rooms on the outside, with empty corners. * Also nicknamed "Ladder Layout" by some. */ -void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateCrossroadsFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1387,12 +1387,12 @@ void GenerateCrossroadsFloor(UnkDungeonGlobal_unk1C574 *unkPtr) GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } // GenerateLineFloor - Generates a floor layout with 5 grid cells in a horizontal line. -void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateLineFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1414,10 +1414,10 @@ void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) gridSizeX = 5, gridSizeY = 1; InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->roomDensity); - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); + AssignRooms(grid, gridSizeX, gridSizeY, floorProps->roomDensity); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); - AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, unkPtr); + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, floorProps); CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, disableRoomMerging); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); @@ -1425,12 +1425,12 @@ void GenerateLineFloor(UnkDungeonGlobal_unk1C574 *unkPtr) GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } // GenerateCrossFloor - Generates a floor layout with 5 rooms arranged in a "plus" or "cross" configuration. -void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateCrossFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1463,7 +1463,7 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) grid[0][2].isInvalid = TRUE; grid[2][2].isInvalid = TRUE; - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); grid[0][1].connectedToRight = TRUE; grid[1][1].connectedToLeft = TRUE; @@ -1480,13 +1480,13 @@ void GenerateCrossFloor(UnkDungeonGlobal_unk1C574 *unkPtr) GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } // GenerateBeetleFloor - Generates a floor layout in a "beetle" shape, with a // 3x3 grid of rooms, a merged center column, and hallways along each row -void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateBeetleFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1512,7 +1512,7 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) } } - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); // Connect rooms in the same row together for (y = 0; y < 3; y++) { @@ -1532,7 +1532,7 @@ void GenerateBeetleFloor(UnkDungeonGlobal_unk1C574 *unkPtr) GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); } @@ -1569,7 +1569,7 @@ static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct Grid // GenerateOuterRoomsFloor - Generates a floor layout with a ring of rooms and nothing on the interior. // This layout is bugged and will not properly connect rooms for gridSizeX < 3. -void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1595,7 +1595,7 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un } } - CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, unkPtr->roomFlags); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); // Maybe Todo: Add EpicYoshiMaster's fixed implementation of this function @@ -1638,16 +1638,16 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, UnkDungeonGlobal_un EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); - GenerateMazeRoom(grid, gridSizeX, gridSizeY, unkPtr->mazeRoomChance); + GenerateMazeRoom(grid, gridSizeX, gridSizeY, floorProps->mazeRoomChance); GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); - GenerateExtraHallways(grid, gridSizeX, gridSizeY, unkPtr->numExtraHallways); + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); GenerateRoomImperfections(grid, gridSizeX, gridSizeY); GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } -bool8 GenerateFixedFloor(s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr) +bool8 GenerateFixedFloor(s32 fixedRoomId, FloorProperties *floorProps) { s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->x; s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->y; @@ -1668,12 +1668,12 @@ bool8 GenerateFixedFloor(s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr) gridSizeY = DUNGEON_MAX_SIZE_Y / (fixedRoomSizeY + 4); if (gridSizeY <= 1) gridSizeY = 1; - sub_804C790(gridSizeX, gridSizeY, fixedRoomSizeX, fixedRoomSizeY, fixedRoomId, unkPtr); + sub_804C790(gridSizeX, gridSizeY, fixedRoomSizeX, fixedRoomSizeY, fixedRoomId, floorProps); return FALSE; } } -static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, UnkDungeonGlobal_unk1C574 *unkPtr) +static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, FloorProperties *floorProps) { s32 tries; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; @@ -1684,7 +1684,7 @@ static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fi GetGridPositions(listX, listY, gridSizeX, gridSizeY); InitDungeonGrid(grid, gridSizeX, gridSizeY); - AssignRooms(grid, gridSizeX, gridSizeY, unkPtr->roomDensity); + AssignRooms(grid, gridSizeX, gridSizeY, floorProps->roomDensity); for (cursorX = 0; cursorX < gridSizeX; cursorX++) { for (cursorY = 0; cursorY < gridSizeY; cursorY++) { grid[cursorX][cursorY].unk27 = 1; @@ -1700,7 +1700,7 @@ static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fi } CreateRoomsAndAnchorsForFixedFloor(grid, gridSizeX, gridSizeY, listX, listY, r10, fixedRoomSizeX, fixedRoomSizeY); if (gridSizeX != 1 || gridSizeY != 1) { - AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, unkPtr); + AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, floorProps); CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); } @@ -2365,12 +2365,12 @@ void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_L } } -static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, UnkDungeonGlobal_unk1C574 *unkPtr) +static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps) { s32 cursorX = DungeonRandInt(gridSizeX); s32 cursorY = DungeonRandInt(gridSizeY); - AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, unkPtr); + AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, floorProps); } /* @@ -2392,12 +2392,12 @@ static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][ * */ -void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, UnkDungeonGlobal_unk1C574 *unkPtr) +void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps) { s32 i; s32 x = cursorX; s32 y = cursorY; - s32 floorConnectivity = unkPtr->floorConnectivity; + s32 floorConnectivity = floorProps->floorConnectivity; // Draw a random connection direction. // Connect the current cell with the cell to the: // 0: east @@ -2490,7 +2490,7 @@ void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN } } - if (unkPtr->allowDeadEnds) + if (floorProps->allowDeadEnds) return; // No dead ends, add some extra connections! @@ -4617,7 +4617,7 @@ void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count) */ extern const s16 gUnknown_80F4DA0; extern const s16 gUnknown_80F4DA4; -void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse) +void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) { struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; s32 count; @@ -4722,7 +4722,7 @@ void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHous } if (count != 0) { - s32 numItems = unkPtr->itemDensity; + s32 numItems = floorProps->itemDensity; if (numItems != 0) { // Add variation to the item count numItems = DungeonRandRange(numItems - 2, numItems + 2); @@ -4763,7 +4763,7 @@ void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHous } if (count != 0) { - s32 numItems = unkPtr->buriedItemDensity; + s32 numItems = floorProps->buriedItemDensity; if (numItems != 0) { // Add variation to the item count @@ -4879,7 +4879,7 @@ void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHous } if (count != 0) { - s32 numTraps = DungeonRandRange(unkPtr->trapDensity / 2, unkPtr->trapDensity); + s32 numTraps = DungeonRandRange(floorProps->trapDensity / 2, floorProps->trapDensity); if (numTraps > 0) { s32 trapIndex; @@ -4953,7 +4953,7 @@ void SpawnNonEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHous /* * SpawnEnemies - Spawns all enemies, including those in forced monster houses */ -void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse) +void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) { struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; s32 count; @@ -4962,7 +4962,7 @@ void SpawnEnemies(UnkDungeonGlobal_unk1C574 *unkPtr, bool8 isEmptyMonsterHouse) s32 x, y; Dungeon *dungeon = gDungeon; s32 numEnemies, numMonsterHouseEnemies; - s32 enemyDensity = unkPtr->enemyDensity; + s32 enemyDensity = floorProps->enemyDensity; if (enemyDensity > 0) { // Positive means value with variance @@ -5150,7 +5150,7 @@ extern const s32 gUnknown_80F6DF8[8]; // https://decomp.me/scratch/sA4YH - Blue // https://decomp.me/scratch/SNyV8 - Sky #ifdef NONMATCHING -void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr) +void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) { s32 densityN; s32 x, y; @@ -5159,7 +5159,7 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk s32 numToGen; s32 numTilesFill; - if (!(unkPtr->roomFlags & flag)) + if (!(floorProps->roomFlags & flag)) return; // Generate 1-3 "river+lake" formations @@ -5321,7 +5321,7 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk } // Generate standalone lakes secondary_terrain_density # of times - for (densityN = 0; densityN < unkPtr->unk15; densityN++) { + for (densityN = 0; densityN < floorProps->unk15; densityN++) { s32 x, y; bool8 table[10][10]; // Try to pick a random tile in the interior to seed the "lake" @@ -5408,7 +5408,7 @@ void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unk } #else -NAKED void GenerateSecondaryTerrainFormations(u32 flag, UnkDungeonGlobal_unk1C574 *unkPtr) +NAKED void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) { asm_unified("\n" " push {r4-r7,lr}\n" @@ -6396,9 +6396,10 @@ static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LE } } -extern u8 *gUnknown_202F1DC; -extern u8 gUnknown_202F1E0; -extern u8 gUnknown_202F1E1; +static EWRAM_DATA u8 *gUnknown_202F1DC = NULL; +static EWRAM_DATA u8 gUnknown_202F1E0 = 0; +static EWRAM_DATA u8 gUnknown_202F1E1 = 0; +static UNUSED EWRAM_DATA s32 sUnusedEwram = 0; u8 sub_80511F0(void) { @@ -6544,11 +6545,130 @@ void sub_8051438(struct GridCell *gridCell, s32 fixedRoomId) } } -/* -void sub_8051654(UnkDungeonGlobal_unk1C574 *unkPtr) +extern const s16 gUnknown_80F57D4[][3][3]; + +void sub_8051654(FloorProperties *floorProps) { + s32 i, n; + s32 x, y; + s32 middleX, middleY; + s32 rangeX = 3, rangeY = 3; + s32 xIndex, yIndex; + s32 r10; + // Note: These loops make no sense as the range is always at least 3 - which means the loop always breaks after the first iteration. + // In fact, pmd red's compiler optimizes out these loops completely. These are however needed to match and were NOT optimized by blue's compiler which proves that's how it was written. + for (n = 0; n < 20; n++) { + rangeX = DungeonRandRange(3, (sKecleonShopPosition.maxX - sKecleonShopPosition.minX) - 2); + if (rangeX < 3) + rangeX = 3; + if (rangeX >= 3) + break; + } + + for (n = 0; n < 20; n++) { + rangeY = DungeonRandRange(3, (sKecleonShopPosition.maxY - sKecleonShopPosition.minY) - 2); + if (rangeY < 3) + rangeY = 3; + if (rangeY >= 3) + break; + } + + r10 = DungeonRandRange(2, 4); + for (i = 0; i < r10; i++) { + if (sKecleonShopPosition.maxX - sKecleonShopPosition.minX <= rangeX) + break; + + if (DungeonRandInt(100) < 50) { + s32 y; + for (y = sKecleonShopPosition.minY; y < sKecleonShopPosition.maxY; y++) { + GetTileMut(sKecleonShopPosition.minX, y)->terrainType &= ~(TERRAIN_TYPE_SHOP); + } + sKecleonShopPosition.minX++; + } + else { + s32 y; + sKecleonShopPosition.maxX--; + for (y = sKecleonShopPosition.minY; y < sKecleonShopPosition.maxY; y++) { + GetTileMut(sKecleonShopPosition.maxX, y)->terrainType &= ~(TERRAIN_TYPE_SHOP); + } + } + } + + for (i = 0; i < r10; i++) { + if (sKecleonShopPosition.maxY - sKecleonShopPosition.minY <= rangeY) + break; + + if (DungeonRandInt(100) < 50) { + s32 x; + for (x = sKecleonShopPosition.minX; x < sKecleonShopPosition.maxX; x++) { + GetTileMut(x, sKecleonShopPosition.minY)->terrainType &= ~(TERRAIN_TYPE_SHOP); + } + sKecleonShopPosition.minY++; + } + else { + s32 x; + sKecleonShopPosition.maxY--; + for (x = sKecleonShopPosition.minX; x < sKecleonShopPosition.maxX; x++) { + GetTileMut(x, sKecleonShopPosition.maxY)->terrainType &= ~(TERRAIN_TYPE_SHOP); + } + } + } + + for (x = sKecleonShopPosition.minX; x < sKecleonShopPosition.maxX; x++) { + for (y = sKecleonShopPosition.minY; y < sKecleonShopPosition.maxY; y++) { + Tile *tile = GetTileMut(x, y); + if (!(tile->terrainType & TERRAIN_TYPE_SHOP)) + continue; + if (!(tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION)) + continue; + + tile->terrainType &= ~(TERRAIN_TYPE_SHOP); + } + } + + middleX = (sKecleonShopPosition.minX + sKecleonShopPosition.maxX) / 2 - 1; + middleY = (sKecleonShopPosition.minY + sKecleonShopPosition.maxY) / 2 - 1; + xIndex = 0; + for (x = middleX; x < middleX + 3; x++, xIndex++) { + yIndex = 0; + for (y = middleY; y < middleY + 3; y++, yIndex++) { + Tile *tile = GetTileMut(x, y); + if (!(tile->terrainType & TERRAIN_TYPE_SHOP)) + continue; + if ((tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE)) + continue; + if ((tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION)) + continue; + + if (gUnknown_80F57D4[floorProps->unk18][yIndex][xIndex] > DungeonRandInt(100)) { + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + } + } + } } -*/ -// +/* + * ResetInnerBoundaryTileRows - Resets inner boundary tile rows (y == 1 and y == 30) + * to their initial state of all wall tiles, with impassable walls at the edges. + * + * This is needed because during generation these soft border walls may have been altered or breached. + */ +void ResetInnerBoundaryTileRows(void) +{ + s32 x; + + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + Tile *tile = GetTileMut(x, 1); + ResetTile(tile); + if (x == 0 || x == DUNGEON_MAX_SIZE_X - 1) { + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + + tile = GetTileMut(x, 30); + ResetTile(tile); + if (x == 0 || x == DUNGEON_MAX_SIZE_X - 1) { + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + } +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 8dc3653f5..6a701c8dd 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -275,14 +275,6 @@ gUnknown_202EE76: /* 202EE76 (sub_804513C - sub_8082A08) */ .include "src/dungeon_map_access.o" .include "src/dungeon_generation.o" - -gUnknown_202F1DC: /* 202F1DC (sub_80511F0 - sub_8051438) */ - .space 0x4 -gUnknown_202F1E0: /* 202F1E0 (sub_80511F0) */ - .space 0x1 -gUnknown_202F1E1: /* 202F1E1 (sub_80511F0 - sub_8051438) */ - .space 0x7 - .include "src/dungeon_message.o" .include "src/dungeon_move.o" .include "src/code_805D8C8_1.o" From 9c461115bbe25891c6125612cd873a6b075ffa26 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 18 Nov 2024 17:16:24 +0100 Subject: [PATCH 24/30] GenerateFloor matched --- include/dungeon_generation.h | 21 + include/structs/str_dungeon.h | 6 +- src/code_8042B34.c | 5 +- src/code_806FDF4.c | 6 +- src/code_80848F0.c | 10 +- src/dungeon_engine.c | 2 +- src/dungeon_generation.c | 986 ++++++++-------------------------- src/dungeon_serializer.c | 4 +- sym_ewram.txt | 2 +- 9 files changed, 248 insertions(+), 794 deletions(-) diff --git a/include/dungeon_generation.h b/include/dungeon_generation.h index fda8a171d..10a187d2b 100644 --- a/include/dungeon_generation.h +++ b/include/dungeon_generation.h @@ -9,6 +9,26 @@ #define GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE 60 // (0 to 100) probability that a room will not have imperfections, if it was already flagged for them #define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 // (0 to 100) probability that a room will be flagged to have a secondary structure. +enum FloorLayout { + LAYOUT_LARGE, + LAYOUT_SMALL, + LAYOUT_ONE_ROOM_MONSTER_HOUSE, + LAYOUT_OUTER_RING, + LAYOUT_CROSSROADS, + LAYOUT_TWO_ROOMS_WITH_MONSTER_HOUSE, + LAYOUT_LINE, + LAYOUT_CROSS, + LAYOUT_LARGE_0x8, + LAYOUT_BEETLE, + LAYOUT_OUTER_ROOMS, + LAYOUT_MEDIUM, + LAYOUT_UNUSED_0xC, + LAYOUT_UNUSED_0xD, + LAYOUT_UNUSED_0xE, + LAYOUT_UNUSED_0xF, + NUM_FLOOR_LAYOUTS +}; + enum FloorSize { FLOOR_SIZE_LARGE, FLOOR_SIZE_SMALL, @@ -31,6 +51,7 @@ enum SecondaryStructureType { SECONDARY_STRUCTURE_DIVIDER, // A "divider" of secondary terrain will split the room in half randomly either horizontally or vertically. }; +void GenerateFloor(void); bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); #endif diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index a54ba636a..c8e6473ad 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -123,7 +123,7 @@ typedef struct UnkDungeonGlobal_unk181E8_sub // Defines many of the key properties for dungeon generation, such as the type of layout, base number of rooms, and floor connectivity. typedef struct FloorProperties { - u8 unk0; + u8 layout; s8 roomDensity; u8 unk2; u8 unk3; @@ -148,7 +148,7 @@ typedef struct FloorProperties u8 unk16; u8 unk17; u8 unk18; - u8 unk19; + u8 itemlessMonsterHouseChance; // Chance that a monster house will be itemless u8 unk1A; } FloorProperties; @@ -371,7 +371,7 @@ typedef struct Dungeon /* 0x3A0E */ s16 tileset; /* 0x3A10 */ s16 unk3A10; /* 0x3A12 */ s16 unk3A12; - /* 0x3A14 */ s16 fixedRoomId; + /* 0x3A14 */ s16 fixedRoomNumber; /* 0x3A16 */ s16 unk3A16; /* 0x3A18 */ Tile tiles[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X]; /* 0xEA18 */ DungeonPos playerSpawn; diff --git a/src/code_8042B34.c b/src/code_8042B34.c index 4be53a2ab..5630bb3d3 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -311,7 +311,6 @@ extern void sub_803DF60(void); extern void sub_803E02C(void); extern void sub_8049840(void); extern void sub_80847D4(void); -extern void sub_804AFAC(void); extern void sub_8043D60(void); extern void sub_806890C(void); extern void sub_8068614(void); @@ -607,7 +606,7 @@ void xxx_dungeon_8042F6C(struct UnkStruct_xxx_dungeon_8042F6C *r8) gDungeon->weather.weather = 0; gDungeon->tileset = gDungeon->unk1C574.unk2; gDungeon->unk3A10 = gDungeon->unk1C574.unk3; - gDungeon->fixedRoomId = gDungeon->unk1C574.unk12; + gDungeon->fixedRoomNumber = gDungeon->unk1C574.unk12; sub_807E5E4(0); sub_80842F0(); } @@ -637,7 +636,7 @@ void xxx_dungeon_8042F6C(struct UnkStruct_xxx_dungeon_8042F6C *r8) ShowDungeonNameBanner(); if (!r6) { - sub_804AFAC(); + GenerateFloor(); gDungeon->unk644.windTurns = GetTurnLimit(gDungeon->unk644.dungeonLocation.id); gDungeon->unk644.unk36 = 0; } diff --git a/src/code_806FDF4.c b/src/code_806FDF4.c index 49adaa4ab..c2df5330a 100644 --- a/src/code_806FDF4.c +++ b/src/code_806FDF4.c @@ -197,13 +197,13 @@ bool8 sub_806F660(Entity *pokemon,Entity *target) targetInfo = target->info; iVar8 = -1; size = GetBodySize(targetInfo->apparentID); - if ((1 < ((u16)(gDungeon->fixedRoomId - 4))) && (gDungeon->fixedRoomId != 9) && (gDungeon->fixedRoomId != 0xf)) { - if ((u16)(gDungeon->fixedRoomId - 0x2cU) < 5) { + if ((1 < ((u16)(gDungeon->fixedRoomNumber - 4))) && (gDungeon->fixedRoomNumber != 9) && (gDungeon->fixedRoomNumber != 0xf)) { + if ((u16)(gDungeon->fixedRoomNumber - 0x2cU) < 5) { if (gDungeon->unk644.unk18 == 0) { return FALSE; } } - else if (gDungeon->fixedRoomId == 0x31) { + else if (gDungeon->fixedRoomNumber == 0x31) { if (gDungeon->unk644.unk15 == 0) { return FALSE; } diff --git a/src/code_80848F0.c b/src/code_80848F0.c index ed04c983c..e6efa7cec 100644 --- a/src/code_80848F0.c +++ b/src/code_80848F0.c @@ -20,18 +20,18 @@ void sub_8084854(struct unkData_8107234 *); void sub_80847D4(void) { - u32 fixedRoomId; + u32 fixedRoomNumber; s32 index; gDungeon->unk3A0D = 0; gDungeon->unk1356C = 0; sub_8040A84(); for(index = 0; index < 0x3e7 && gUnknown_8107234[index].unk0[0] != 0; index++) { - fixedRoomId = gDungeon->fixedRoomId; - if (fixedRoomId - 0x1c < 0x16) { - fixedRoomId = 0x1b; + fixedRoomNumber = gDungeon->fixedRoomNumber; + if (fixedRoomNumber - 0x1c < 0x16) { + fixedRoomNumber = 0x1b; } - if (fixedRoomId == gUnknown_8107234[index].unk0[0]) + if (fixedRoomNumber == gUnknown_8107234[index].unk0[0]) { sub_8084854(&gUnknown_8107234[index]); break; diff --git a/src/dungeon_engine.c b/src/dungeon_engine.c index 2175fe96b..e06cd4688 100644 --- a/src/dungeon_engine.c +++ b/src/dungeon_engine.c @@ -34,7 +34,7 @@ static bool8 xxx_dungeon_80442D0(bool8); bool8 IsBossFight() { - if (gDungeon->fixedRoomId != 0 && gDungeon->fixedRoomId <= 0x31) + if (gDungeon->fixedRoomNumber != 0 && gDungeon->fixedRoomNumber <= 0x31) { return TRUE; } diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 4397f6f91..240c9fae8 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -65,10 +65,10 @@ struct GridCell #define GRID_CELL_LEN 15 -static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, FloorProperties *floorProps); +static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomNumber, FloorProperties *floorProps); static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 fixedRoomSizeX, s32 fixedRoomSizeY); -void sub_8051438(struct GridCell *gridCell, s32 fixedRoomId); -void sub_8051288(s32 fixedRoomId); +void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber); +void sub_8051288(s32 fixedRoomNumber); void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); @@ -91,9 +91,9 @@ void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s void EnsureImpassableTilesAreWalls(void); void sub_804FC74(void); void sub_804EB30(void); -void sub_804E9DC(void); +void FinalizeJunctions(void); void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); -bool8 GenerateFixedFloor(s32 fixedRoomId, FloorProperties *floorProps); +bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps); void GenerateStandardFloor(s32 a0, s32 a1, FloorProperties *a2); void GenerateOuterRingFloor(FloorProperties *a0); void GenerateCrossroadsFloor(FloorProperties *a0); @@ -108,20 +108,20 @@ void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); void ResetInnerBoundaryTileRows(void); -EWRAM_DATA u8 gUnknown_202F1A8 = 0; -EWRAM_DATA u8 gUnknown_202F1A9 = 0; +EWRAM_DATA bool8 gUnknown_202F1A8 = FALSE; +static EWRAM_DATA bool8 sInvalidGeneration = FALSE; static EWRAM_DATA bool8 sHasKecleonShop = FALSE; -EWRAM_DATA bool8 sHasMonsterHouse = FALSE; +static EWRAM_DATA bool8 sHasMonsterHouse = FALSE; static EWRAM_DATA bool8 sHasMaze = FALSE; static EWRAM_DATA bool8 sSecondSpawn = FALSE; static EWRAM_DATA u8 sFloorSize = 0; static EWRAM_DATA s16 sKecleonShopChance = 0; static EWRAM_DATA s16 sMonsterHouseChance = 0; static EWRAM_DATA u8 sStairsRoomIndex = 0; -EWRAM_DATA struct MinMaxPosition sKecleonShopPosition = {0}; +static EWRAM_DATA struct MinMaxPosition sKecleonShopPosition = {0}; static EWRAM_DATA s32 sSecondaryStructuresBudget = 0; static EWRAM_DATA s32 sNumRooms = 0; -EWRAM_DATA s32 gUnknown_202F1D0 = 0; +static EWRAM_DATA s32 sFloorLayout = 0; static EWRAM_DATA s32 sNumTilesReachableFromStairs = 0; static EWRAM_DATA DungeonPos sKecleonShopMiddlePos = {0}; @@ -160,13 +160,32 @@ struct FixedRoomsData u8 unk3[0]; // Not sure about the size; }; -// Some weird-ass regswap prevents the function from being matched - https://decomp.me/scratch/9SUV3 -#ifdef NONMATCHING -void sub_804AFAC(void) +/* + * GenerateFloor - The Master Function for generating a dungeon floor + * + * Runs based on 3 loop levels of safety + * + * Innermost Loop: 32 attempts for deciding the maximum rooms in each dimension for the floor + * - The dimensions are capped at 6x4 (but we can randomize outside this range and fail) + * - Must maintain a certain number of tiles per grid cell in both dimensions + * - If this loop fails 32 times, defaults to a 4x4 maximum + * + * Inner Main Loop: 10 attempts for the main layout of a floor + * - This loop can fail by being marked invalid during generation + * - Or, it can fail by having < 2 rooms or < 20 room tiles + * - This occurs prior to secondary terrain generation + * - If the loop fails 10 times, defaults to generating a One-Room Monster House + * + * Outermost Loop: 10 attempts for everything involved in generating a layout + * - This is where secondary terrain generation and junction additions takes place + * - This loop can fail during spawn location verification (can you get to the stairs?) + * - If the loop fails 10 times, defaults to generating a One-Room Monster House + */ +void GenerateFloor(void) { s32 x, y; - s32 i, j, k; - bool8 r10 = FALSE; + s32 spawnAttempts; + bool8 secondaryGen = FALSE; FloorProperties *floorProps = &gDungeon->unk1C574; gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); @@ -178,208 +197,238 @@ void sub_804AFAC(void) sFloorSize = 0; sKecleonShopChance = floorProps->kecleonShopChance; sMonsterHouseChance = floorProps->monsterHouseChance; - sSecondSpawn = 1; - sKecleonShopPosition.unk0 = -1; - sKecleonShopPosition.unk8 = -1; - sKecleonShopPosition.unk4 = -1; - sKecleonShopPosition.unkC = -1; + sSecondSpawn = TRUE; + sKecleonShopPosition.minX = -1; + sKecleonShopPosition.maxX = -1; + sKecleonShopPosition.minY = -1; + sKecleonShopPosition.maxY = -1; ResetFloor(); - gDungeon->unk664 = floorProps->unk6; + gDungeon->unk644.unk20 = abs(floorProps->enemyDensity); gDungeon->unk3A09 = 0; gDungeon->unk3A0A = 0; sSecondaryStructuresBudget = floorProps->secondaryStructuresBudget; - for (i = 0; i < 10; i++) { - bool32 r4 = 0; + for (spawnAttempts = 0; spawnAttempts < 10; spawnAttempts++) { + s32 genAttempts; + bool32 isEmptyMonsterHouse; gDungeon->playerSpawn.x = -1; gDungeon->playerSpawn.y = -1; gDungeon->stairsSpawn.x = -1; gDungeon->stairsSpawn.y = -1; - for (j = 0; j < 10; j++) { - gDungeon->unk3A16 = j; - if (j > 0) { + // Actual generation attempts, up to 10 times per entity + for (genAttempts = 0; genAttempts < 10; genAttempts++) { + gDungeon->unk3A16 = genAttempts; + if (genAttempts > 0) { sSecondaryStructuresBudget = 0; } - gUnknown_202F1A9 = 0; + sInvalidGeneration = FALSE; sKecleonShopMiddlePos.x = -1; sKecleonShopMiddlePos.y = -1; + ResetFloor(); + gDungeon->playerSpawn.x = -1; gDungeon->playerSpawn.y = -1; - gDungeon->forceMonsterHouse = 0; - if (gDungeon->fixedRoomId != 0) { + gDungeon->forceMonsterHouse = FALSE; + if (gDungeon->fixedRoomNumber != 0) { // Check for a full-floor fixed room, if this is the case, generation is done. - if (GenerateFixedFloor(gDungeon->fixedRoomId, floorProps)) { + if (ProcessFixedRoom(gDungeon->fixedRoomNumber, floorProps)) { break; } } else { - u8 r7 = floorProps->unk0; + s32 gridSizeX, gridSizeY; + s32 attempts; + u8 layout = floorProps->layout; - k = 32; + // Attempt to generate random grid dimensions + attempts = 32; while (1) { - if (r7 != 8) { - x = DungeonRandRange(2, 9); - y = DungeonRandRange(2, 8); + if (layout != LAYOUT_LARGE_0x8) { + gridSizeX = DungeonRandRange(2, 9); + gridSizeY = DungeonRandRange(2, 8); } else { - x = DungeonRandRange(2, 5); - y = DungeonRandRange(2, 4); + gridSizeX = DungeonRandRange(2, 5); + gridSizeY = DungeonRandRange(2, 4); } - if (x <= 6 && y <= 4) { + // Limit overall dimensions + if (gridSizeX <= 6 && gridSizeY <= 4) { break; } - if (--k == 0) { - x = 4; - y = 4; + if (--attempts == 0) { + // We failed to generate random grid dimensions, default to 4x4 + gridSizeX = 4; + gridSizeY = 4; break; } } - if (DUNGEON_MAX_SIZE_X / x < 8) { - x = 1; + // Make sure there are at least 7 tiles per grid cell in both + // dimensions. Otherwise, the grid size is too big so default to 1 + if (DUNGEON_MAX_SIZE_X / gridSizeX < 8) { + gridSizeX = 1; } - if (DUNGEON_MAX_SIZE_Y / y < 8) { - y = 1; + if (DUNGEON_MAX_SIZE_Y / gridSizeY < 8) { + gridSizeY = 1; } - gDungeon->forceMonsterHouse = 0; + gDungeon->forceMonsterHouse = FALSE; gDungeon->monsterHouseRoom = 0xFF; - gUnknown_202F1D0 = r7; - switch (r7 & 0xF) { - case 1: - y = DungeonRandInt(2) + 2; - sFloorSize = 1; - GenerateStandardFloor(4, y, floorProps); - r10 = TRUE; + sFloorLayout = layout; + switch (layout % NUM_FLOOR_LAYOUTS) { + case LAYOUT_SMALL: + gridSizeX = 4; + gridSizeY = DungeonRandInt(2) + 2; + sFloorSize = FLOOR_SIZE_SMALL; + GenerateStandardFloor(gridSizeX, gridSizeY, floorProps); + secondaryGen = TRUE; break; - case 11: - y = DungeonRandInt(2) + 2; - sFloorSize = 2; - GenerateStandardFloor(4, y, floorProps); - r10 = TRUE; + case LAYOUT_MEDIUM: + gridSizeX = 4; + gridSizeY = DungeonRandInt(2) + 2; + sFloorSize = FLOOR_SIZE_MEDIUM; + GenerateStandardFloor(gridSizeX, gridSizeY, floorProps); + secondaryGen = TRUE; break; - case 0: + case LAYOUT_LARGE: + case LAYOUT_LARGE_0x8: default: - GenerateStandardFloor(x, y, floorProps); - r10 = TRUE; + GenerateStandardFloor(gridSizeX, gridSizeY, floorProps); + secondaryGen = TRUE; break; - case 2: + case LAYOUT_ONE_ROOM_MONSTER_HOUSE: GenerateOneRoomMonsterHouseFloor(); - gDungeon->forceMonsterHouse = 1; + gDungeon->forceMonsterHouse = TRUE; break; - case 3: + case LAYOUT_OUTER_RING: GenerateOuterRingFloor(floorProps); - r10 = TRUE; + secondaryGen = TRUE; break; - case 4: + case LAYOUT_CROSSROADS: GenerateCrossroadsFloor(floorProps); - r10 = TRUE; + secondaryGen = TRUE; break; - case 5: + case LAYOUT_TWO_ROOMS_WITH_MONSTER_HOUSE: GenerateTwoRoomsWithMonsterHouseFloor(); - gDungeon->forceMonsterHouse = 1; + gDungeon->forceMonsterHouse = TRUE; break; - case 6: + case LAYOUT_LINE: GenerateLineFloor(floorProps); - r10 = TRUE; + secondaryGen = TRUE; break; - case 7: + case LAYOUT_CROSS: GenerateCrossFloor(floorProps); break; - case 9: + case LAYOUT_BEETLE: GenerateBeetleFloor(floorProps); break; - case 10: - GenerateOuterRoomsFloor(x, y, floorProps); - r10 = TRUE; + case LAYOUT_OUTER_ROOMS: + GenerateOuterRoomsFloor(gridSizeX, gridSizeY, floorProps); + secondaryGen = TRUE; break; } } ResetInnerBoundaryTileRows(); EnsureImpassableTilesAreWalls(); - if (gUnknown_202F1A9 == 0) { - s32 countSp = 0; - u8 spArray[64]; - s32 countRooms = 0; - for (k = 0; k < 64; k++) { - spArray[k] = 0; + // Nothing failed during generation. This variable is always set to FALSE, so the check always passes + if (!sInvalidGeneration) { + // We need to make sure there are at least 2 rooms with at least 20 total tiles + s32 numRooms = 0; + bool8 rooms[64]; + s32 roomTiles = 0; + s32 i; + + for (i = 0; i < 64; i++) { + rooms[i] = FALSE; } for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { const Tile *tile = GetTile(x, y); if ((tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_NORMAL && tile->room <= 240) { - countRooms++; + roomTiles++; if (tile->room < 64) { - spArray[tile->room] = 1; + rooms[tile->room] = TRUE; } } } } - countSp = 0; + numRooms = 0; // In order to match, 'y' had to be re-used as an iterator var for (y = 0; y < 64; y++) { - if (spArray[y]) { - countSp++; + if (rooms[y]) { + numRooms++; } } - if (countRooms >= 30 && countSp > 1) { - break; + if (roomTiles >= 30 && numRooms >= 2) { + break; // This layout is good! } } } - if (j == 10) { + // If we fail to generate a layout in 10 attempts, just abort and make a one-room Monster House + if (genAttempts == 10) { sKecleonShopMiddlePos.x = -1; sKecleonShopMiddlePos.y = -1; GenerateOneRoomMonsterHouseFloor(); - gDungeon->forceMonsterHouse = 1; + gDungeon->forceMonsterHouse = TRUE; } - sub_804E9DC(); - if (r10) { - GenerateSecondaryTerrainFormations(1, floorProps); + + // We will be guaranteed to have a good layout by this point + FinalizeJunctions(); + if (secondaryGen) { + GenerateSecondaryTerrainFormations(ROOM_FLAG_ALLOW_SECONDARY_TERRAIN, floorProps); } - r4 = (DungeonRandInt(100) < floorProps->connectedToTop); - SpawnNonEnemies(floorProps, r4); - SpawnEnemies(floorProps, r4); - ResolveInvalidSpawns(); - if (gDungeon->playerSpawn.x != -1 && gDungeon->playerSpawn.y != -1) - { - if (GetFloorType() == 1) - break; - if (gDungeon->stairsSpawn.x != -1 && gDungeon->stairsSpawn.y != -1 && StairsAlwaysReachable(gDungeon->stairsSpawn.x, gDungeon->stairsSpawn.y, 0)) + + isEmptyMonsterHouse = (DungeonRandInt(100) < floorProps->itemlessMonsterHouseChance); + SpawnNonEnemies(floorProps, isEmptyMonsterHouse); + SpawnEnemies(floorProps, isEmptyMonsterHouse); + + ResolveInvalidSpawns(); // Make sure multiple flags aren't set for one tile + if (gDungeon->playerSpawn.x != -1 && gDungeon->playerSpawn.y != -1) { + // This is for normal fixed rooms, we don't need to validate the stairs in this scenario + // Since it's fixed already + if (GetFloorType() == FLOOR_TYPE_FIXED) break; + if (gDungeon->stairsSpawn.x != -1 && gDungeon->stairsSpawn.y != -1 && StairsAlwaysReachable(gDungeon->stairsSpawn.x, gDungeon->stairsSpawn.y, FALSE)) + break; // We can reach the stairs, we're good! } + + // Something went bad with spawns, we'll need to retry on a new generation } - if (i == 10) { + // If we fail with spawns (or otherwise) 10 times, opt for a One-Room Monster House generation + if (spawnAttempts == 10) { sKecleonShopMiddlePos.x = -1; sKecleonShopMiddlePos.y = -1; + ResetFloor(); GenerateOneRoomMonsterHouseFloor(); gDungeon->forceMonsterHouse = TRUE; - sub_804E9DC(); + + FinalizeJunctions(); SpawnNonEnemies(floorProps, FALSE); SpawnEnemies(floorProps, FALSE); ResolveInvalidSpawns(); + // We don't care about validating because this is our bailout, so we're done! } if (sKecleonShopMiddlePos.x >= 0 && sKecleonShopMiddlePos.y >= 0) { sub_806C330(sKecleonShopMiddlePos.x, sKecleonShopMiddlePos.y, 380, 0); } - if (sKecleonShopPosition.unk0 >= 0) { + if (sKecleonShopPosition.minX >= 0) { sub_8051654(floorProps); gDungeon->unk3A0A = 1; } @@ -388,660 +437,12 @@ void sub_804AFAC(void) } sub_804B534(0, 0, DUNGEON_MAX_SIZE_X, DUNGEON_MAX_SIZE_Y); - if (gUnknown_202F1A8 != 0) { + if (gUnknown_202F1A8) { sub_804FC74(); } CloseFile(gDungeon->unk13568); } -#else -void NAKED sub_804AFAC(void) -{ - asm_unified(" push {r4-r7,lr}\n" -" mov r7, r10\n" -" mov r6, r9\n" -" mov r5, r8\n" -" push {r5-r7}\n" -" sub sp, 0x44\n" -" movs r0, 0\n" -" mov r10, r0\n" -" ldr r4, _0804B0E8\n" -" ldr r0, [r4]\n" -" ldr r1, _0804B0EC\n" -" adds r1, r0\n" -" mov r8, r1\n" -" ldr r0, _0804B0F0\n" -" ldr r1, _0804B0F4\n" -" bl OpenFileAndGetFileDataPtr\n" -" ldr r2, [r4]\n" -" ldr r3, _0804B0F8\n" -" adds r1, r2, r3\n" -" str r0, [r1]\n" -" ldr r0, _0804B0FC\n" -" mov r6, r10\n" -" strb r6, [r0]\n" -" ldr r0, _0804B100\n" -" strb r6, [r0]\n" -" ldr r0, _0804B104\n" -" strb r6, [r0]\n" -" ldr r5, _0804B108\n" -" movs r3, 0\n" -" ldr r1, _0804B10C\n" -" ldr r0, _0804B110\n" -" adds r2, r0\n" -" movs r6, 0\n" -" ldrsh r0, [r2, r6]\n" -" adds r0, r1\n" -" ldrb r0, [r0]\n" -" cmp r0, 0x2\n" -" bne _0804AFFC\n" -" movs r3, 0x1\n" -"_0804AFFC:\n" -" strb r3, [r5]\n" -" ldr r1, _0804B114\n" -" movs r0, 0xFF\n" -" strb r0, [r1]\n" -" ldr r0, _0804B118\n" -" mov r1, r10\n" -" strb r1, [r0]\n" -" ldr r1, _0804B11C\n" -" mov r2, r8\n" -" ldrb r0, [r2, 0x7]\n" -" strh r0, [r1]\n" -" ldr r1, _0804B120\n" -" ldrb r0, [r2, 0x8]\n" -" strh r0, [r1]\n" -" ldr r1, _0804B124\n" -" movs r0, 0x1\n" -" strb r0, [r1]\n" -" ldr r1, _0804B128\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" str r0, [r1]\n" -" str r0, [r1, 0x8]\n" -" str r0, [r1, 0x4]\n" -" str r0, [r1, 0xC]\n" -" bl ResetFloor\n" -" ldr r3, [r4]\n" -" mov r6, r8\n" -" ldrb r2, [r6, 0x6]\n" -" ldr r1, _0804B12C\n" -" adds r0, r3, r1\n" -" movs r1, 0\n" -" strh r2, [r0]\n" -" ldr r2, _0804B130\n" -" adds r0, r3, r2\n" -" strb r1, [r0]\n" -" ldr r0, [r4]\n" -" ldr r3, _0804B134\n" -" adds r0, r3\n" -" strb r1, [r0]\n" -" ldr r1, _0804B138\n" -" mov r6, r8\n" -" ldrb r0, [r6, 0xC]\n" -" str r0, [r1]\n" -" movs r0, 0\n" -" str r0, [sp, 0x40]\n" -"_0804B058:\n" -" ldr r0, _0804B0E8\n" -" ldr r2, [r0]\n" -" ldr r3, _0804B13C\n" -" adds r1, r2, r3\n" -" ldr r0, _0804B140\n" -" strh r0, [r1]\n" -" ldr r6, _0804B144\n" -" adds r1, r2, r6\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" strh r0, [r1]\n" -" ldr r0, _0804B148\n" -" adds r1, r2, r0\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" strh r0, [r1]\n" -" ldr r1, _0804B14C\n" -" adds r2, r1\n" -" strh r0, [r2]\n" -" movs r2, 0\n" -" mov r9, r2\n" -"_0804B082:\n" -" ldr r4, _0804B0E8\n" -" ldr r0, [r4]\n" -" ldr r3, _0804B150\n" -" adds r0, r3\n" -" movs r5, 0\n" -" movs r1, 0\n" -" mov r6, r9\n" -" strh r6, [r0]\n" -" mov r0, r9\n" -" cmp r0, 0\n" -" ble _0804B09C\n" -" ldr r0, _0804B138\n" -" str r1, [r0]\n" -"_0804B09C:\n" -" ldr r0, _0804B154\n" -" strb r5, [r0]\n" -" ldr r1, _0804B158\n" -" ldr r0, _0804B140\n" -" strh r0, [r1]\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" strh r0, [r1, 0x2]\n" -" bl ResetFloor\n" -" ldr r1, [r4]\n" -" ldr r3, _0804B13C\n" -" adds r2, r1, r3\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" strh r0, [r2]\n" -" ldr r6, _0804B144\n" -" adds r2, r1, r6\n" -" strh r0, [r2]\n" -" ldr r0, _0804B15C\n" -" adds r1, r0\n" -" strb r5, [r1]\n" -" ldr r0, [r4]\n" -" ldr r2, _0804B160\n" -" adds r1, r0, r2\n" -" movs r3, 0\n" -" ldrsh r0, [r1, r3]\n" -" cmp r0, 0\n" -" beq _0804B164\n" -" mov r1, r8\n" -" bl GenerateFixedFloor\n" -" lsls r0, 24\n" -" cmp r0, 0\n" -" beq _0804B0E4\n" -" b _0804B376\n" -"_0804B0E4:\n" -" b _0804B2F6\n" -" .align 2, 0\n" -"_0804B0E8: .4byte gDungeon\n" -"_0804B0EC: .4byte 0x0001c574\n" -"_0804B0F0: .4byte gUnknown_80F6DCC\n" -"_0804B0F4: .4byte gDungeonFileArchive\n" -"_0804B0F8: .4byte 0x00013568\n" -"_0804B0FC: .4byte sHasKecleonShop\n" -"_0804B100: .4byte sHasMonsterHouse\n" -"_0804B104: .4byte sHasMaze\n" -"_0804B108: .4byte gUnknown_202F1A8\n" -"_0804B10C: .4byte gDungeonWaterType\n" -"_0804B110: .4byte 0x00003a0e\n" -"_0804B114: .4byte sStairsRoomIndex\n" -"_0804B118: .4byte sFloorSize\n" -"_0804B11C: .4byte sKecleonShopChance\n" -"_0804B120: .4byte sMonsterHouseChance\n" -"_0804B124: .4byte sSecondSpawn\n" -"_0804B128: .4byte sKecleonShopPosition\n" -"_0804B12C: .4byte 0x00000664\n" -"_0804B130: .4byte 0x00003a09\n" -"_0804B134: .4byte 0x00003a0a\n" -"_0804B138: .4byte sSecondaryStructuresBudget\n" -"_0804B13C: .4byte 0x0000e218\n" -"_0804B140: .4byte 0x0000ffff\n" -"_0804B144: .4byte 0x0000e21a\n" -"_0804B148: .4byte 0x0000e21c\n" -"_0804B14C: .4byte 0x0000e21e\n" -"_0804B150: .4byte 0x00003a16\n" -"_0804B154: .4byte gUnknown_202F1A9\n" -"_0804B158: .4byte sKecleonShopMiddlePos\n" -"_0804B15C: .4byte 0x00003a08\n" -"_0804B160: .4byte 0x00003a14\n" -"_0804B164:\n" -" mov r0, r8\n" -" ldrb r7, [r0]\n" -" movs r6, 0x20\n" -"_0804B16A:\n" -" cmp r7, 0x8\n" -" beq _0804B17E\n" -" movs r0, 0x2\n" -" movs r1, 0x9\n" -" bl DungeonRandRange\n" -" adds r5, r0, 0\n" -" movs r0, 0x2\n" -" movs r1, 0x8\n" -" b _0804B18C\n" -"_0804B17E:\n" -" movs r0, 0x2\n" -" movs r1, 0x5\n" -" bl DungeonRandRange\n" -" adds r5, r0, 0\n" -" movs r0, 0x2\n" -" movs r1, 0x4\n" -"_0804B18C:\n" -" bl DungeonRandRange\n" -" adds r4, r0, 0\n" -" cmp r5, 0x6\n" -" bgt _0804B19A\n" -" cmp r4, 0x4\n" -" ble _0804B1A4\n" -"_0804B19A:\n" -" subs r6, 0x1\n" -" cmp r6, 0\n" -" bne _0804B16A\n" -" movs r5, 0x4\n" -" movs r4, 0x4\n" -"_0804B1A4:\n" -" movs r0, 0x38\n" -" adds r1, r5, 0\n" -" bl __divsi3\n" -" cmp r0, 0x7\n" -" bgt _0804B1B2\n" -" movs r5, 0x1\n" -"_0804B1B2:\n" -" movs r0, 0x20\n" -" adds r1, r4, 0\n" -" bl __divsi3\n" -" cmp r0, 0x7\n" -" bgt _0804B1C0\n" -" movs r4, 0x1\n" -"_0804B1C0:\n" -" ldr r2, _0804B1EC\n" -" ldr r0, [r2]\n" -" ldr r1, _0804B1F0\n" -" adds r0, r1\n" -" movs r1, 0\n" -" strb r1, [r0]\n" -" ldr r0, [r2]\n" -" ldr r2, _0804B1F4\n" -" adds r0, r2\n" -" movs r1, 0xFF\n" -" strb r1, [r0]\n" -" ldr r0, _0804B1F8\n" -" str r7, [r0]\n" -" movs r0, 0xF\n" -" ands r0, r7\n" -" cmp r0, 0xB\n" -" bhi _0804B274\n" -" lsls r0, 2\n" -" ldr r1, _0804B1FC\n" -" adds r0, r1\n" -" ldr r0, [r0]\n" -" mov pc, r0\n" -" .align 2, 0\n" -"_0804B1EC: .4byte gDungeon\n" -"_0804B1F0: .4byte 0x00003a08\n" -"_0804B1F4: .4byte 0x00003a0c\n" -"_0804B1F8: .4byte gUnknown_202F1D0\n" -"_0804B1FC: .4byte _0804B200\n" -" .align 2, 0\n" -"_0804B200:\n" -" .4byte _0804B274\n" -" .4byte _0804B230\n" -" .4byte _0804B280\n" -" .4byte _0804B298\n" -" .4byte _0804B2A4\n" -" .4byte _0804B2B0\n" -" .4byte _0804B2CC\n" -" .4byte _0804B2D8\n" -" .4byte _0804B274\n" -" .4byte _0804B2E0\n" -" .4byte _0804B2E8\n" -" .4byte _0804B250\n" -"_0804B230:\n" -" movs r0, 0x2\n" -" bl DungeonRandInt\n" -" adds r4, r0, 0x2\n" -" ldr r1, _0804B24C\n" -" movs r0, 0x1\n" -" strb r0, [r1]\n" -" movs r0, 0x4\n" -" adds r1, r4, 0\n" -" mov r2, r8\n" -" bl GenerateStandardFloor\n" -" b _0804B2AA\n" -" .align 2, 0\n" -"_0804B24C: .4byte sFloorSize\n" -"_0804B250:\n" -" movs r0, 0x2\n" -" bl DungeonRandInt\n" -" adds r4, r0, 0x2\n" -" ldr r1, _0804B270\n" -" movs r0, 0x2\n" -" strb r0, [r1]\n" -" movs r0, 0x4\n" -" adds r1, r4, 0\n" -" mov r2, r8\n" -" bl GenerateStandardFloor\n" -" movs r6, 0x1\n" -" mov r10, r6\n" -" b _0804B2F6\n" -" .align 2, 0\n" -"_0804B270: .4byte sFloorSize\n" -"_0804B274:\n" -" adds r0, r5, 0\n" -" adds r1, r4, 0\n" -" mov r2, r8\n" -" bl GenerateStandardFloor\n" -" b _0804B2D2\n" -"_0804B280:\n" -" bl GenerateOneRoomMonsterHouseFloor\n" -" ldr r0, _0804B290\n" -" ldr r0, [r0]\n" -" ldr r1, _0804B294\n" -" adds r0, r1\n" -" b _0804B2BC\n" -" .align 2, 0\n" -"_0804B290: .4byte gDungeon\n" -"_0804B294: .4byte 0x00003a08\n" -"_0804B298:\n" -" mov r0, r8\n" -" bl GenerateOuterRingFloor\n" -" movs r2, 0x1\n" -" mov r10, r2\n" -" b _0804B2F6\n" -"_0804B2A4:\n" -" mov r0, r8\n" -" bl GenerateCrossroadsFloor\n" -"_0804B2AA:\n" -" movs r3, 0x1\n" -" mov r10, r3\n" -" b _0804B2F6\n" -"_0804B2B0:\n" -" bl GenerateTwoRoomsWithMonsterHouseFloor\n" -" ldr r0, _0804B2C4\n" -" ldr r0, [r0]\n" -" ldr r6, _0804B2C8\n" -" adds r0, r6\n" -"_0804B2BC:\n" -" movs r1, 0x1\n" -" strb r1, [r0]\n" -" b _0804B2F6\n" -" .align 2, 0\n" -"_0804B2C4: .4byte gDungeon\n" -"_0804B2C8: .4byte 0x00003a08\n" -"_0804B2CC:\n" -" mov r0, r8\n" -" bl GenerateLineFloor\n" -"_0804B2D2:\n" -" movs r0, 0x1\n" -" mov r10, r0\n" -" b _0804B2F6\n" -"_0804B2D8:\n" -" mov r0, r8\n" -" bl GenerateCrossFloor\n" -" b _0804B2F6\n" -"_0804B2E0:\n" -" mov r0, r8\n" -" bl GenerateBeetleFloor\n" -" b _0804B2F6\n" -"_0804B2E8:\n" -" adds r0, r5, 0\n" -" adds r1, r4, 0\n" -" mov r2, r8\n" -" bl GenerateOuterRoomsFloor\n" -" movs r1, 0x1\n" -" mov r10, r1\n" -"_0804B2F6:\n" -" bl ResetInnerBoundaryTileRows\n" -" bl EnsureImpassableTilesAreWalls\n" -" ldr r0, _0804B4B4\n" -" ldrb r0, [r0]\n" -" cmp r0, 0\n" -" bne _0804B36A\n" -" movs r7, 0\n" -" movs r1, 0\n" -" mov r0, sp\n" -" adds r0, 0x3F\n" -"_0804B30E:\n" -" strb r1, [r0]\n" -" subs r0, 0x1\n" -" cmp r0, sp\n" -" bge _0804B30E\n" -" movs r5, 0\n" -"_0804B318:\n" -" movs r4, 0\n" -" adds r6, r5, 0x1\n" -"_0804B31C:\n" -" adds r0, r5, 0\n" -" adds r1, r4, 0\n" -" bl GetTile\n" -" adds r1, r0, 0\n" -" ldrh r0, [r1]\n" -" movs r2, 0x3\n" -" ands r2, r0\n" -" cmp r2, 0x1\n" -" bne _0804B340\n" -" ldrb r0, [r1, 0x9]\n" -" cmp r0, 0xF0\n" -" bhi _0804B340\n" -" adds r7, 0x1\n" -" cmp r0, 0x3F\n" -" bhi _0804B340\n" -" add r0, sp\n" -" strb r2, [r0]\n" -"_0804B340:\n" -" adds r4, 0x1\n" -" cmp r4, 0x1F\n" -" ble _0804B31C\n" -" adds r5, r6, 0\n" -" cmp r5, 0x37\n" -" ble _0804B318\n" -" movs r1, 0\n" -" movs r4, 0\n" -"_0804B350:\n" -" mov r2, sp\n" -" adds r0, r2, r4\n" -" ldrb r0, [r0]\n" -" cmp r0, 0\n" -" beq _0804B35C\n" -" adds r1, 0x1\n" -"_0804B35C:\n" -" adds r4, 0x1\n" -" cmp r4, 0x3F\n" -" ble _0804B350\n" -" cmp r7, 0x1D\n" -" ble _0804B36A\n" -" cmp r1, 0x1\n" -" bgt _0804B376\n" -"_0804B36A:\n" -" movs r3, 0x1\n" -" add r9, r3\n" -" mov r6, r9\n" -" cmp r6, 0x9\n" -" bgt _0804B376\n" -" b _0804B082\n" -"_0804B376:\n" -" mov r0, r9\n" -" cmp r0, 0xA\n" -" bne _0804B398\n" -" ldr r1, _0804B4B8\n" -" ldr r0, _0804B4BC\n" -" strh r0, [r1]\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" strh r0, [r1, 0x2]\n" -" bl GenerateOneRoomMonsterHouseFloor\n" -" ldr r0, _0804B4C0\n" -" ldr r0, [r0]\n" -" ldr r1, _0804B4C4\n" -" adds r0, r1\n" -" movs r1, 0x1\n" -" strb r1, [r0]\n" -"_0804B398:\n" -" bl sub_804E9DC\n" -" mov r2, r10\n" -" cmp r2, 0\n" -" beq _0804B3AA\n" -" movs r0, 0x1\n" -" mov r1, r8\n" -" bl GenerateSecondaryTerrainFormations\n" -"_0804B3AA:\n" -" movs r0, 0x64\n" -" bl DungeonRandInt\n" -" movs r4, 0\n" -" mov r3, r8\n" -" ldrb r3, [r3, 0x19]\n" -" cmp r0, r3\n" -" bge _0804B3BC\n" -" movs r4, 0x1\n" -"_0804B3BC:\n" -" mov r0, r8\n" -" adds r1, r4, 0\n" -" bl SpawnNonEnemies\n" -" mov r0, r8\n" -" adds r1, r4, 0\n" -" bl SpawnEnemies\n" -" bl ResolveInvalidSpawns\n" -" ldr r5, _0804B4C0\n" -" ldr r1, [r5]\n" -" ldr r6, _0804B4C8\n" -" adds r0, r1, r6\n" -" movs r2, 0\n" -" ldrsh r0, [r0, r2]\n" -" movs r4, 0x1\n" -" negs r4, r4\n" -" cmp r0, r4\n" -" beq _0804B42A\n" -" ldr r3, _0804B4CC\n" -" adds r0, r1, r3\n" -" movs r6, 0\n" -" ldrsh r0, [r0, r6]\n" -" cmp r0, r4\n" -" beq _0804B42A\n" -" bl GetFloorType\n" -" lsls r0, 24\n" -" lsrs r0, 24\n" -" cmp r0, 0x1\n" -" beq _0804B436\n" -" ldr r1, [r5]\n" -" ldr r0, _0804B4D0\n" -" adds r2, r1, r0\n" -" movs r3, 0\n" -" ldrsh r0, [r2, r3]\n" -" cmp r0, r4\n" -" beq _0804B42A\n" -" ldr r6, _0804B4D4\n" -" adds r1, r6\n" -" movs r3, 0\n" -" ldrsh r0, [r1, r3]\n" -" cmp r0, r4\n" -" beq _0804B42A\n" -" movs r6, 0\n" -" ldrsh r0, [r2, r6]\n" -" movs r2, 0\n" -" ldrsh r1, [r1, r2]\n" -" movs r2, 0\n" -" bl StairsAlwaysReachable\n" -" lsls r0, 24\n" -" cmp r0, 0\n" -" bne _0804B436\n" -"_0804B42A:\n" -" ldr r3, [sp, 0x40]\n" -" adds r3, 0x1\n" -" str r3, [sp, 0x40]\n" -" cmp r3, 0x9\n" -" bgt _0804B436\n" -" b _0804B058\n" -"_0804B436:\n" -" ldr r6, [sp, 0x40]\n" -" cmp r6, 0xA\n" -" bne _0804B474\n" -" ldr r1, _0804B4B8\n" -" ldr r0, _0804B4BC\n" -" strh r0, [r1]\n" -" movs r0, 0x1\n" -" negs r0, r0\n" -" strh r0, [r1, 0x2]\n" -" bl ResetFloor\n" -" bl GenerateOneRoomMonsterHouseFloor\n" -" ldr r0, _0804B4C0\n" -" ldr r0, [r0]\n" -" ldr r1, _0804B4C4\n" -" adds r0, r1\n" -" movs r1, 0x1\n" -" strb r1, [r0]\n" -" bl sub_804E9DC\n" -" mov r0, r8\n" -" movs r1, 0\n" -" bl SpawnNonEnemies\n" -" mov r0, r8\n" -" movs r1, 0\n" -" bl SpawnEnemies\n" -" bl ResolveInvalidSpawns\n" -"_0804B474:\n" -" ldr r1, _0804B4B8\n" -" movs r2, 0\n" -" ldrsh r0, [r1, r2]\n" -" cmp r0, 0\n" -" blt _0804B498\n" -" movs r3, 0x2\n" -" ldrsh r0, [r1, r3]\n" -" cmp r0, 0\n" -" blt _0804B498\n" -" movs r6, 0\n" -" ldrsh r0, [r1, r6]\n" -" movs r2, 0x2\n" -" ldrsh r1, [r1, r2]\n" -" movs r2, 0xBE\n" -" lsls r2, 1\n" -" movs r3, 0\n" -" bl sub_806C330\n" -"_0804B498:\n" -" ldr r0, _0804B4D8\n" -" ldr r0, [r0]\n" -" cmp r0, 0\n" -" blt _0804B4E0\n" -" mov r0, r8\n" -" bl sub_8051654\n" -" ldr r0, _0804B4C0\n" -" ldr r0, [r0]\n" -" ldr r3, _0804B4DC\n" -" adds r0, r3\n" -" movs r1, 0x1\n" -" b _0804B4EA\n" -" .align 2, 0\n" -"_0804B4B4: .4byte gUnknown_202F1A9\n" -"_0804B4B8: .4byte sKecleonShopMiddlePos\n" -"_0804B4BC: .4byte 0x0000ffff\n" -"_0804B4C0: .4byte gDungeon\n" -"_0804B4C4: .4byte 0x00003a08\n" -"_0804B4C8: .4byte 0x0000e218\n" -"_0804B4CC: .4byte 0x0000e21a\n" -"_0804B4D0: .4byte 0x0000e21c\n" -"_0804B4D4: .4byte 0x0000e21e\n" -"_0804B4D8: .4byte sKecleonShopPosition\n" -"_0804B4DC: .4byte 0x00003a0a\n" -"_0804B4E0:\n" -" ldr r0, _0804B524\n" -" ldr r0, [r0]\n" -" ldr r6, _0804B528\n" -" adds r0, r6\n" -" movs r1, 0\n" -"_0804B4EA:\n" -" strb r1, [r0]\n" -" movs r0, 0\n" -" movs r1, 0\n" -" movs r2, 0x38\n" -" movs r3, 0x20\n" -" bl sub_804B534\n" -" ldr r0, _0804B52C\n" -" ldrb r0, [r0]\n" -" cmp r0, 0\n" -" beq _0804B504\n" -" bl sub_804FC74\n" -"_0804B504:\n" -" ldr r0, _0804B524\n" -" ldr r0, [r0]\n" -" ldr r1, _0804B530\n" -" adds r0, r1\n" -" ldr r0, [r0]\n" -" bl CloseFile\n" -" add sp, 0x44\n" -" pop {r3-r5}\n" -" mov r8, r3\n" -" mov r9, r4\n" -" mov r10, r5\n" -" pop {r4-r7}\n" -" pop {r0}\n" -" bx r0\n" -" .align 2, 0\n" -"_0804B524: .4byte gDungeon\n" -"_0804B528: .4byte 0x00003a0a\n" -"_0804B52C: .4byte gUnknown_202F1A8\n" -"_0804B530: .4byte 0x00013568\n"); -} -#endif // NONMATCHING void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) { @@ -1647,18 +1048,18 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *fl GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } -bool8 GenerateFixedFloor(s32 fixedRoomId, FloorProperties *floorProps) +bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps) { - s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->x; - s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomId]->y; + s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->x; + s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->y; s32 gridSizeX, gridSizeY; if (fixedRoomSizeX == 0 || fixedRoomSizeY == 0) { GenerateOneRoomMonsterHouseFloor(); return FALSE; } - else if (fixedRoomId < 50) { - sub_8051288(fixedRoomId); + else if (fixedRoomNumber < 50) { + sub_8051288(fixedRoomNumber); return TRUE; } else { @@ -1668,12 +1069,12 @@ bool8 GenerateFixedFloor(s32 fixedRoomId, FloorProperties *floorProps) gridSizeY = DUNGEON_MAX_SIZE_Y / (fixedRoomSizeY + 4); if (gridSizeY <= 1) gridSizeY = 1; - sub_804C790(gridSizeX, gridSizeY, fixedRoomSizeX, fixedRoomSizeY, fixedRoomId, floorProps); + sub_804C790(gridSizeX, gridSizeY, fixedRoomSizeX, fixedRoomSizeY, fixedRoomNumber, floorProps); return FALSE; } } -static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomId, FloorProperties *floorProps) +static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomNumber, FloorProperties *floorProps) { s32 tries; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; @@ -1704,7 +1105,7 @@ static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fi CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); } - sub_8051438(&grid[cursorX][cursorY], fixedRoomId); + sub_8051438(&grid[cursorX][cursorY], fixedRoomNumber); } /* @@ -3528,7 +2929,34 @@ void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomInd } } -void sub_804E9DC(void) +/* + * FinalizeJunctions - Finalizes junction tiles by setting the junction flag and verifying the tiles are open terrain + * + * Due to the nature of how this function iterates left-to-right / top-to-bottom, by identifying junctions as any + * open, non-hallway tile (roomIndex !== 0xFF) adjacent to an open, hallway tile (roomIndex == 0xFF), the function + * runs into issues handling hallway anchors (roomIndex == 0xFE). The room index of hallway anchors is set to 0xFF using + * the same loop, which means a hallway anchor may or may not be considered a junction depending on how the connected + * hallways are oriented. + * + * For example, in the configuration below, the "o" tile would be marked as a junction because the neighboring hallway tile + * to its left comes earlier in iteration, while "o" still has the room index 0xFE, with the algorithm mistaking it for a + * room tile. + * + * X X X X X + * - - - o X + * X X X | X + * X X X | X + * + * Alternatively, in the configuration below, the "o" tile would not be marked as a junction because it comes earlier in + * iteration than any of its neighboring hallway tiles, so its room index is set to 0xFF before it can be marked as a junction. + * This configuration is actually the only one where a hallway anchor will not be marked as a junction. + * + * X X X X X + * X o - - - + * X | X X X + * X | X X X + */ +void FinalizeJunctions(void) { s32 x, y; @@ -3537,17 +2965,21 @@ void sub_804E9DC(void) if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) continue; + // Not in a room if (GetTile(x, y)->room == CORRIDOR_ROOM) { + // Tile to the left is in a room (or anchor), mark junction if (x > 0) { Tile *tile = GetTileMut(x - 1, y); if (tile->room != CORRIDOR_ROOM) { tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + // If there's any water/lava on the junction tile, remove it if (GetTerrainType(tile) == TERRAIN_TYPE_SECONDARY) { SetTerrainType(tile, TERRAIN_TYPE_NORMAL); } } } + // Tile above is in a room if (y > 0) { Tile *tile = GetTileMut(x, y - 1); if (tile->room != CORRIDOR_ROOM) { @@ -3559,6 +2991,7 @@ void sub_804E9DC(void) } } } + // Tile below is in a room if (y < DUNGEON_MAX_SIZE_Y - 1) { Tile *tile = GetTileMut(x, y + 1); if (tile->room != CORRIDOR_ROOM) { @@ -3569,6 +3002,7 @@ void sub_804E9DC(void) } } } + //Tile to the right is in a room if (x < DUNGEON_MAX_SIZE_X - 1) { Tile *tile = GetTileMut(x + 1, y); if (tile->room != CORRIDOR_ROOM) { @@ -3580,6 +3014,7 @@ void sub_804E9DC(void) } } } + // Hallway Anchor else if (GetTile(x, y)->room == ROOM_0xFE) { GetTileMut(x, y)->room = CORRIDOR_ROOM; } @@ -4974,8 +4409,7 @@ void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) } else { // Negative means exact value. - // Bug - abs is missing, also it should be s8, not u8 - numEnemies = enemyDensity; + numEnemies = abs(enemyDensity); } count = 0; @@ -6430,16 +5864,16 @@ bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) return sub_8051A74(tile, a1, x, y, a5); } -void sub_8051288(s32 fixedRoomId) +void sub_8051288(s32 fixedRoomNumber) { s32 x, y; Dungeon *dungeon = gDungeon; - s32 fixedRoomSizeX = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->x; - s32 fixedRoomSizeY = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->y; + s32 fixedRoomSizeX = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomNumber]->x; + s32 fixedRoomSizeY = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomNumber]->y; dungeon->unkE260.unk0 = fixedRoomSizeX; dungeon->unkE260.unk2 = fixedRoomSizeY; - gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk3; + gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomNumber]->unk3; gUnknown_202F1E1 = 0; for (y = 5; y < fixedRoomSizeY + 5; y++) { @@ -6457,7 +5891,7 @@ void sub_8051288(s32 fixedRoomId) if (x <= 4 || x >= fixedRoomSizeX + 5 || y <= 4 || y >= fixedRoomSizeY + 5) { Tile *tile = GetTileMut(x, y); tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; - if (gUnknown_202F1A8 != 0) { + if (gUnknown_202F1A8) { SetTerrainType(tile, TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); } else { @@ -6467,7 +5901,7 @@ void sub_8051288(s32 fixedRoomId) } } - if (fixedRoomId == 4) { + if (fixedRoomNumber == 4) { for (y = 5; y < 17; y++) { for (x = 2; x < 5; x++) { Tile *tile = GetTileMut(x, y); @@ -6488,18 +5922,18 @@ void sub_8051288(s32 fixedRoomId) } } - sub_804E9DC(); + FinalizeJunctions(); } -void sub_8051438(struct GridCell *gridCell, s32 fixedRoomId) +void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) { s32 x, y; Dungeon *dungeon = gDungeon; - gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk3; + gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomNumber]->unk3; gUnknown_202F1E1 = 0; - if (((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomId]->unk2 & 1) { + if (((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomNumber]->unk2 & 1) { s32 yIndex; dungeon->unkE250.minX = gridCell->start.x; diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index 16c0dc787..e1df58dd4 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -414,7 +414,7 @@ static void WriteDungeonFloor(DataSerializer *seri) WriteS16(seri, gDungeon->tileset); WriteS16(seri,gDungeon->unk3A10); WriteS16(seri, gDungeon->unk3A12); - WriteS16(seri, gDungeon->fixedRoomId); + WriteS16(seri, gDungeon->fixedRoomNumber); WriteS16(seri, gDungeon->unk3A16); for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { @@ -776,7 +776,7 @@ static void ReadDungeonFloor(DataSerializer *seri) gDungeon->tileset = ReadS16(seri); gDungeon->unk3A10 = ReadS16(seri); gDungeon->unk3A12 = ReadS16(seri); - gDungeon->fixedRoomId = ReadS16(seri); + gDungeon->fixedRoomNumber = ReadS16(seri); gDungeon->unk3A16 = ReadS16(seri); for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { diff --git a/sym_ewram.txt b/sym_ewram.txt index 6a701c8dd..65a583a91 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -274,7 +274,7 @@ gUnknown_202EE76: /* 202EE76 (sub_804513C - sub_8082A08) */ .space 0x10 .include "src/dungeon_map_access.o" - .include "src/dungeon_generation.o" + .include "src/dungeon_generation.o" .include "src/dungeon_message.o" .include "src/dungeon_move.o" .include "src/code_805D8C8_1.o" From 0843612de40c38a6ec7f55f16412c1a7d3370c84 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 18 Nov 2024 21:13:57 +0100 Subject: [PATCH 25/30] start sub_8051A74 --- asm/code_804FD30.s | 160 ------------------------- include/structs/str_806B7F8.h | 19 +++ include/structs/str_dungeon.h | 1 + src/code_80718D8.c | 13 +-- src/code_8072B78.c | 13 +-- src/dungeon_generation.c | 212 ++++++++++++++++++++++++++++++++++ src/trap.c | 13 +-- 7 files changed, 235 insertions(+), 196 deletions(-) create mode 100644 include/structs/str_806B7F8.h diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index d3ee800d0..227cb1211 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -6,166 +6,6 @@ .text - thumb_func_start sub_805193C -sub_805193C: - push {r4-r6,lr} - sub sp, 0x8 - adds r6, r3, 0 - ldr r4, [sp, 0x18] - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 16 - lsls r2, 16 - lsrs r1, 16 - orrs r1, r2 - str r1, [sp, 0x4] - adds r0, r5, 0 - bl sub_805210C - lsls r0, 24 - cmp r0, 0 - beq _0805196A - mov r0, sp - movs r1, 0x76 - movs r2, 0 - bl xxx_init_itemslot_8090A8C - b _08051974 -_0805196A: - mov r0, sp - adds r1, r5, 0 - movs r2, 0 - bl xxx_init_itemslot_8090A8C -_08051974: - mov r0, sp - ldrb r0, [r0] - orrs r4, r0 - mov r0, sp - strb r4, [r0] - cmp r6, 0 - beq _08051984 - strb r6, [r0, 0x1] -_08051984: - add r0, sp, 0x4 - mov r1, sp - movs r2, 0x1 - bl sub_80460F8 - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_805193C - - thumb_func_start sub_8051998 -sub_8051998: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x14 - mov r8, r1 - mov r9, r2 - lsls r0, 16 - asrs r0, 16 - adds r1, r0, 0 - lsls r3, 24 - lsrs r6, r3, 24 - adds r7, r6, 0 - ldr r0, _080519E4 - cmp r1, r0 - bne _080519E8 - mov r1, sp - movs r5, 0 - movs r4, 0 - movs r0, 0x3C - strh r0, [r1] - bl sub_803DA20 - mov r1, sp - strh r0, [r1, 0x8] - mov r0, sp - strb r6, [r0, 0x2] - str r4, [sp, 0x4] - strb r5, [r0, 0x10] - mov r1, r8 - strh r1, [r0, 0xC] - mov r1, r9 - strh r1, [r0, 0xE] - movs r1, 0x1 - bl sub_806B7F8 - b _08051A14 - .align 2, 0 -_080519E4: .4byte 0x000001a5 -_080519E8: - cmp r1, 0 - beq _08051A14 - mov r0, sp - movs r5, 0 - movs r4, 0 - strh r1, [r0] - adds r0, r1, 0 - bl sub_803DA20 - mov r1, sp - strh r0, [r1, 0x8] - mov r0, sp - strb r7, [r0, 0x2] - str r4, [sp, 0x4] - strb r5, [r0, 0x10] - mov r1, r8 - strh r1, [r0, 0xC] - mov r1, r9 - strh r1, [r0, 0xE] - movs r1, 0x1 - bl sub_806B7F8 -_08051A14: - add sp, 0x14 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8051998 - - thumb_func_start sub_8051A24 -sub_8051A24: - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - adds r6, r0, 0 - adds r4, r1, 0 - adds r5, r2, 0 - lsls r6, 24 - lsrs r6, 24 - lsls r3, 24 - lsrs r3, 24 - mov r8, r3 - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileMut - adds r7, r0, 0 - lsls r4, 16 - lsls r5, 16 - lsrs r4, 16 - orrs r4, r5 - str r4, [sp] - adds r0, r6, 0 - mov r1, sp - movs r2, 0 - bl sub_8045684 - cmp r0, 0 - beq _08051A66 - str r0, [r7, 0x14] - adds r0, 0x20 - mov r1, r8 - strb r1, [r0] -_08051A66: - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8051A24 - thumb_func_start sub_8051A74 sub_8051A74: push {r4-r7,lr} diff --git a/include/structs/str_806B7F8.h b/include/structs/str_806B7F8.h new file mode 100644 index 000000000..f3f804755 --- /dev/null +++ b/include/structs/str_806B7F8.h @@ -0,0 +1,19 @@ +#ifndef GUARD_STR_806B7F8_H +#define GUARD_STR_806B7F8_H + +#include "structs/dungeon_entity.h" + +struct unkStruct_806B7F8 +{ + s16 species; + u8 unk2; + u32 unk4; + u16 level; + u8 fillA[2]; + DungeonPos pos; + u8 unk10; +}; + +Entity* sub_806B7F8(struct unkStruct_806B7F8 *, bool8); + +#endif diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index c8e6473ad..80fe9eb77 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -290,6 +290,7 @@ typedef struct unkDungeon644 /* 0x42 */ s16 unk42; /* 0x44 */ s16 unk44; /* 0x46 */ u8 unk46; + /* 0x47 */ u8 unk47; /* 0x48 */ s32 unk48; /* 0x4C */ s32 unk4C; /* 0x50 */ s32 unk50; diff --git a/src/code_80718D8.c b/src/code_80718D8.c index 44d891bd3..d6e8b0c7a 100644 --- a/src/code_80718D8.c +++ b/src/code_80718D8.c @@ -15,17 +15,7 @@ #include "dungeon.h" #include "pokemon_3.h" #include "status_checks_1.h" - -struct unkStruct_806B7F8 -{ - s16 species; - u8 unk2; - u32 unk4; - u16 level; - u8 fillA[2]; - DungeonPos pos; - u8 unk10; -}; +#include "structs/str_806B7F8.h" EWRAM_DATA s32 gUnknown_202F31C[2] = {0, 0}; EWRAM_DATA s32 gUnknown_202F324[2] = {0, 0}; @@ -60,7 +50,6 @@ bool8 sub_80723D0(Entity *, Entity *, u8, u8); void sub_807218C(Entity *); void sub_806A2BC(Entity *, u32); void sub_806A3D4(u8 *, s32, s32, s32); -extern Entity* sub_806B7F8(struct unkStruct_806B7F8 *, bool8); extern void sub_8042920(struct Entity *r0); extern s16 sub_803D970(u32); extern s32 sub_803DA20(s32 param_1); diff --git a/src/code_8072B78.c b/src/code_8072B78.c index cee32ad69..45acc4a27 100644 --- a/src/code_8072B78.c +++ b/src/code_8072B78.c @@ -13,21 +13,10 @@ #include "structs/dungeon_entity.h" #include "structs/map.h" #include "structs/str_pokemon.h" +#include "structs/str_806B7F8.h" extern u8 *gUnknown_80FE2EC[]; -struct unkStruct_806B7F8 -{ - u16 species; - u8 unk2; - u32 unk4; - u16 level; - u8 fillA[0xC - 0xA]; - DungeonPos pos; - u8 unk10; -}; - -extern Entity* sub_806B7F8(struct unkStruct_806B7F8 *, bool8); extern void sub_806BFC0(EntityInfo *, u32); void sub_8069E0C(Entity *pokemon); void sub_8042A44(Entity *r0); diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 240c9fae8..84019d8b0 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -4,9 +4,15 @@ #include "tile_types.h" #include "dungeon_map_access.h" #include "dungeon_random.h" +#include "items.h" +#include "pokemon.h" +#include "code_80450F8.h" #include "constants/direction.h" +#include "constants/item.h" +#include "constants/monster.h" #include "structs/str_dungeon.h" #include "structs/map.h" +#include "structs/str_806B7F8.h" extern const u8 gUnknown_80F6DCC[]; extern struct FileArchive gDungeonFileArchive; @@ -6106,3 +6112,209 @@ void ResetInnerBoundaryTileRows(void) } } } + +bool8 sub_805210C(u8 itemId); + +extern void sub_80460F8(DungeonPos *, Item *, u32); +extern s32 sub_803DA20(s16 species); + +void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) +{ + Item item; + DungeonPos pos = {x, y}; + + if (sub_805210C(itemId)) { + xxx_init_itemslot_8090A8C(&item, ITEM_LINK_CABLE, 0); + } + else { + xxx_init_itemslot_8090A8C(&item, itemId, 0); + } + + item.flags |= itemFlags; + if (quantity != 0) { + item.quantity = quantity; + } + + sub_80460F8(&pos, &item, 1); +} + +// s16 species memes strike again. Will the fix ever be discovered? +void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_) +{ + struct unkStruct_806B7F8 unkStruct; + s32 species = SpeciesId(species_); + u8 unk2 = unk2_; + + if (species_ == MONSTER_DECOY) { + unkStruct.species = MONSTER_POLIWAG; + unkStruct.level = sub_803DA20(MONSTER_POLIWAG); + unkStruct.unk2 = unk2; + unkStruct.unk4 = 0; + unkStruct.unk10 = 0; + unkStruct.pos.x = x; + unkStruct.pos.y = y; + sub_806B7F8(&unkStruct, TRUE); + } + else if (species != MONSTER_NONE) { + unkStruct.species = species; + unkStruct.level = sub_803DA20(species); + unkStruct.unk2 = unk2; + unkStruct.unk4 = 0; + unkStruct.unk10 = 0; + unkStruct.pos.x = x; + unkStruct.pos.y = y; + sub_806B7F8(&unkStruct, TRUE); + } +} + +void sub_8051A24(u8 trapId, s32 x, s32 y, bool8 isVisible) +{ + DungeonPos pos; + Entity *trapEntity; + Tile *tile = GetTileMut(x, y); + + pos.x = x; + pos.y = y; + trapEntity = sub_8045684(trapId, &pos, 0); + if (trapEntity != NULL) { + tile->object = trapEntity; + trapEntity->isVisible = isVisible; + } +} + +struct UnkStruct_80F6D20 +{ + u8 unk0; + s16 unk2; + u32 unk4; + s16 unk8; + u8 unkA; + u8 unkB; + u8 fillC; + u8 unkD; + u8 unkE; +}; + +extern const struct UnkStruct_80F6D20 gUnknown_80F6D20[]; + +extern void sub_8049840(void); + +bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) +{ + if (a1 > 0xF) { + SetTerrainNormal(tile); + } + + switch (a1) { + case 69: + gDungeon->unk644.unk40 = x; + gDungeon->unk644.unk42 = y; + sub_8051A24(0xB, x, y, FALSE); + // fall through + case 0: + SetTerrainNormal(tile); + tile->room = 0; + return FALSE; + case 1: + SetTerrainWall(tile); + tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE); + tile->room = CORRIDOR_ROOM; + return FALSE; + case 4: + SetTerrainNormal(tile); + tile->room = 0; + gDungeon->playerSpawn.x = x; + gDungeon->playerSpawn.x = y; + tile->room = 0; + return FALSE; + case 5: + SetTerrainNormal(tile); + tile->room = 0; + return FALSE; + case 6: + SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL); + tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE); + tile->room = CORRIDOR_ROOM; + return FALSE; + case 7: + gUnknown_202F1A8 = 1; + sub_8049840(); + SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL); + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + tile->room = CORRIDOR_ROOM; + return FALSE; + case 8: + case 67: + SetTerrainNormal(tile); + tile->spawnOrVisibilityFlags |= SPAWN_FLAG_STAIRS; + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + tile->room = 0; + gDungeon->stairsSpawn.x = x; + gDungeon->stairsSpawn.y = y; + return FALSE; + case 68: + tile->terrainType |= TERRAIN_TYPE_UNK_x800; + SetTerrainNormal(tile); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + tile->room = 0; + return FALSE; + case 9: + SetTerrainNormal(tile); + tile->room = CORRIDOR_ROOM; + return FALSE; + case 11: + SetTerrainNormal(tile); + tile->terrainType |= TERRAIN_TYPE_UNK_x800; + tile->room = 0; + return FALSE; + case 12: + SetTerrainNormal(tile); + tile->terrainType |= TERRAIN_TYPE_UNK_x1000; + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + tile->terrainType |= TERRAIN_TYPE_UNK_x800; + tile->room = 0; + return FALSE; + case 2: + case 13: + case 14: + SetTerrainWall(tile); + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + tile->room = CORRIDOR_ROOM; + return FALSE; + default: + if (a1 > 16 && a1 < 190) { + if (gUnknown_80F6D20[a1].unk0 != 0) { + if (a5) { + sub_805193C(gUnknown_80F6D20[a1].unk0, x, y, gUnknown_80F6D20[a1].unk2, gUnknown_80F6D20[a1].unk4); + } + else { + gDungeon->unk644.unk47 = gUnknown_80F6D20[a1].unk0; + } + } + else { + if (gUnknown_80F6D20[a1].unk4 != 0) { + gDungeon->unkE220[gUnknown_80F6D20[a1].unk4 - 1].x = x; + gDungeon->unkE220[gUnknown_80F6D20[a1].unk4 - 1].y = y; + } + } + + if (gUnknown_80F6D20[a1].unk8 != 0) { + sub_8051998(gUnknown_80F6D20[a1].unk8, x, y, gUnknown_80F6D20[a1].unkA); + } + + if (gUnknown_80F6D20[a1].unkB != 20 && a5) { + sub_8051A24(gUnknown_80F6D20[a1].unkB, x, y, gUnknown_80F6D20[a1].unkD); + } + + if (gUnknown_80F6D20[a1].unkD != 0) { + SetTerrainSecondary(tile); + } + } + break; + case 3: + case 15: + return FALSE; + } + + return FALSE; +} diff --git a/src/trap.c b/src/trap.c index d0e339ace..94483397e 100644 --- a/src/trap.c +++ b/src/trap.c @@ -24,6 +24,7 @@ #include "status.h" #include "structs/map.h" #include "structs/str_dungeon.h" +#include "structs/str_806B7F8.h" extern u8 *gTrapNames[]; extern u8 *gUnknown_80FC5FC[]; @@ -57,18 +58,6 @@ extern u32 gUnknown_8106A4C; extern u32 gUnknown_8106A50; extern s16 gUnknown_80F4F8A; -struct unkStruct_806B7F8 -{ - s16 species; - u8 unk2; - u32 unk4; - u16 level; - u8 fillA[2]; - DungeonPos pos; - u8 unk10; -}; -extern Entity* sub_806B7F8(struct unkStruct_806B7F8 *, bool8); - void sub_806A9B4(Entity *, u32); s16 sub_803D970(u32); From 4a5fd910aad2d0b3fa5ce7f76b2fc5851932fa8a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 19 Nov 2024 12:39:41 +0100 Subject: [PATCH 26/30] dungeon generation is finished --- asm/code_804FD30.s | 887 ----------------------------------- asm/code_807E5AC.s | 4 +- include/code_80450F8.h | 4 +- include/dungeon_generation.h | 6 + include/pokemon.h | 5 + ld_script.txt | 1 - src/code_80450F8.c | 2 +- src/dungeon_generation.c | 408 ++++++++++------ src/dungeon_serializer.c | 2 +- src/trap.c | 2 +- 10 files changed, 286 insertions(+), 1035 deletions(-) delete mode 100644 asm/code_804FD30.s diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s deleted file mode 100644 index 227cb1211..000000000 --- a/asm/code_804FD30.s +++ /dev/null @@ -1,887 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - - thumb_func_start sub_8051A74 -sub_8051A74: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - adds r4, r0, 0 - adds r6, r2, 0 - adds r7, r3, 0 - ldr r0, [sp, 0x20] - lsls r1, 24 - lsrs r1, 24 - mov r8, r1 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - cmp r1, 0xF - bls _08051AA2 - ldrh r0, [r4] - ldr r1, _08051AB4 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r4] -_08051AA2: - mov r0, r8 - cmp r0, 0x45 - bls _08051AAA - b _08051D68 -_08051AAA: - lsls r0, 2 - ldr r1, _08051AB8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_08051AB4: .4byte 0x0000fffc -_08051AB8: .4byte _08051ABC - .align 2, 0 -_08051ABC: - .4byte _08051BF0 - .4byte _08051C0C - .4byte _08051D50 - .4byte _08051E1A - .4byte _08051C20 - .4byte _08051C54 - .4byte _08051C64 - .4byte _08051C74 - .4byte _08051C94 - .4byte _08051D00 - .4byte _08051C7E - .4byte _08051D10 - .4byte _08051D24 - .4byte _08051D50 - .4byte _08051D50 - .4byte _08051E1A - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051D68 - .4byte _08051C94 - .4byte _08051CD4 - .4byte _08051BD4 -_08051BD4: - ldr r0, _08051BFC - ldr r0, [r0] - ldr r2, _08051C00 - adds r1, r0, r2 - strh r6, [r1] - ldr r3, _08051C04 - adds r0, r3 - strh r7, [r0] - movs r0, 0xB - adds r1, r6, 0 - adds r2, r7, 0 - movs r3, 0 - bl sub_8051A24 -_08051BF0: - ldrh r1, [r4] - ldr r0, _08051C08 - ands r0, r1 - movs r1, 0x1 - movs r2, 0 - b _08051D42 - .align 2, 0 -_08051BFC: .4byte gDungeon -_08051C00: .4byte 0x00000684 -_08051C04: .4byte 0x00000686 -_08051C08: .4byte 0x0000fffc -_08051C0C: - ldrh r1, [r4] - ldr r0, _08051C18 - ands r0, r1 - ldr r1, _08051C1C - ands r0, r1 - b _08051D5A - .align 2, 0 -_08051C18: .4byte 0x0000fffc -_08051C1C: .4byte 0x0000feff -_08051C20: - ldrh r1, [r4] - ldr r0, _08051C44 - ands r0, r1 - movs r1, 0x1 - movs r2, 0 - orrs r0, r1 - strh r0, [r4] - ldr r0, _08051C48 - ldr r0, [r0] - ldr r3, _08051C4C - adds r1, r0, r3 - strh r6, [r1] - ldr r1, _08051C50 - adds r0, r1 - strh r7, [r0] - strb r2, [r4, 0x9] - b _08051E1A - .align 2, 0 -_08051C44: .4byte 0x0000fffc -_08051C48: .4byte gDungeon -_08051C4C: .4byte 0x0000e218 -_08051C50: .4byte 0x0000e21a -_08051C54: - ldrh r1, [r4] - ldr r0, _08051C60 - ands r0, r1 - movs r2, 0 - movs r1, 0x2 - b _08051D42 - .align 2, 0 -_08051C60: .4byte 0x0000fffc -_08051C64: - ldrh r1, [r4] - ldr r0, _08051C70 - ands r0, r1 - movs r1, 0x3 - b _08051D58 - .align 2, 0 -_08051C70: .4byte 0x0000fffc -_08051C74: - ldr r1, _08051C8C - movs r0, 0x1 - strb r0, [r1] - bl sub_8049840 -_08051C7E: - ldrh r1, [r4] - ldr r0, _08051C90 - ands r0, r1 - movs r1, 0x3 - orrs r0, r1 - b _08051D56 - .align 2, 0 -_08051C8C: .4byte gUnknown_202F1A8 -_08051C90: .4byte 0x0000fffc -_08051C94: - ldrh r1, [r4] - ldr r0, _08051CC0 - ands r0, r1 - movs r1, 0x1 - orrs r0, r1 - strh r0, [r4] - ldrh r0, [r4, 0x4] - movs r2, 0 - orrs r0, r1 - ldr r1, _08051CC4 - ands r0, r1 - strh r0, [r4, 0x4] - strb r2, [r4, 0x9] - ldr r0, _08051CC8 - ldr r0, [r0] - ldr r2, _08051CCC - adds r1, r0, r2 - strh r6, [r1] - ldr r3, _08051CD0 - adds r0, r3 - strh r7, [r0] - b _08051E1A - .align 2, 0 -_08051CC0: .4byte 0x0000fffc -_08051CC4: .4byte 0x0000fffd -_08051CC8: .4byte gDungeon -_08051CCC: .4byte 0x0000e21c -_08051CD0: .4byte 0x0000e21e -_08051CD4: - ldrh r1, [r4] - movs r2, 0x80 - lsls r2, 4 - adds r0, r2, 0 - orrs r0, r1 - ldr r1, _08051CF8 - ands r0, r1 - movs r1, 0x1 - movs r2, 0 - orrs r0, r1 - strh r0, [r4] - ldrh r1, [r4, 0x4] - ldr r0, _08051CFC - ands r0, r1 - strh r0, [r4, 0x4] - strb r2, [r4, 0x9] - b _08051E1A - .align 2, 0 -_08051CF8: .4byte 0x0000fffc -_08051CFC: .4byte 0x0000fffd -_08051D00: - ldrh r1, [r4] - ldr r0, _08051D0C - ands r0, r1 - movs r1, 0x1 - b _08051D58 - .align 2, 0 -_08051D0C: .4byte 0x0000fffc -_08051D10: - ldrh r1, [r4] - ldr r0, _08051D20 - ands r0, r1 - movs r1, 0x1 - movs r2, 0 - orrs r0, r1 - b _08051D3C - .align 2, 0 -_08051D20: .4byte 0x0000fffc -_08051D24: - ldrh r1, [r4] - ldr r0, _08051D4C - ands r0, r1 - movs r1, 0x1 - orrs r0, r1 - movs r2, 0x80 - lsls r2, 5 - adds r1, r2, 0 - orrs r0, r1 - movs r1, 0x10 - orrs r0, r1 - movs r2, 0 -_08051D3C: - movs r3, 0x80 - lsls r3, 4 - adds r1, r3, 0 -_08051D42: - orrs r0, r1 - strh r0, [r4] - strb r2, [r4, 0x9] - b _08051E1A - .align 2, 0 -_08051D4C: .4byte 0x0000fffc -_08051D50: - ldrh r1, [r4] - ldr r0, _08051D64 - ands r0, r1 -_08051D56: - movs r1, 0x10 -_08051D58: - orrs r0, r1 -_08051D5A: - strh r0, [r4] - movs r0, 0xFF - strb r0, [r4, 0x9] - b _08051E1A - .align 2, 0 -_08051D64: .4byte 0x0000fffc -_08051D68: - mov r0, r8 - subs r0, 0x10 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xCB - bhi _08051E1A - mov r1, r8 - lsls r0, r1, 4 - ldr r1, _08051DA0 - adds r5, r0, r1 - ldrb r0, [r5, 0xC] - strb r0, [r4, 0x9] - ldrb r1, [r5] - cmp r1, 0 - beq _08051DB8 - mov r2, r9 - cmp r2, 0 - beq _08051DA4 - ldrb r0, [r5] - movs r1, 0x2 - ldrsh r3, [r5, r1] - ldr r1, [r5, 0x4] - str r1, [sp] - adds r1, r6, 0 - adds r2, r7, 0 - bl sub_805193C - b _08051DDC - .align 2, 0 -_08051DA0: .4byte gUnknown_80F6D20 -_08051DA4: - ldr r0, _08051DB0 - ldr r0, [r0] - ldr r2, _08051DB4 - adds r0, r2 - strb r1, [r0] - b _08051DDC - .align 2, 0 -_08051DB0: .4byte gDungeon -_08051DB4: .4byte 0x0000068b -_08051DB8: - ldr r2, [r5, 0x4] - cmp r2, 0 - beq _08051DDC - ldr r0, _08051E2C - ldr r1, [r0] - subs r0, r2, 0x1 - lsls r0, 2 - adds r0, r1, r0 - ldr r3, _08051E30 - adds r0, r3 - strh r6, [r0] - ldr r0, [r5, 0x4] - subs r0, 0x1 - lsls r0, 2 - adds r1, r0 - ldr r0, _08051E34 - adds r1, r0 - strh r7, [r1] -_08051DDC: - movs r1, 0x8 - ldrsh r0, [r5, r1] - cmp r0, 0 - beq _08051DF2 - ldrb r3, [r5, 0xA] - mov r1, r8 - str r1, [sp] - adds r1, r6, 0 - adds r2, r7, 0 - bl sub_8051998 -_08051DF2: - ldrb r0, [r5, 0xB] - cmp r0, 0x14 - beq _08051E08 - mov r2, r9 - cmp r2, 0 - beq _08051E08 - ldrb r3, [r5, 0xD] - adds r1, r6, 0 - adds r2, r7, 0 - bl sub_8051A24 -_08051E08: - ldrb r0, [r5, 0xE] - cmp r0, 0 - beq _08051E1A - ldrh r0, [r4] - ldr r1, _08051E38 - ands r1, r0 - movs r0, 0x2 - orrs r1, r0 - strh r1, [r4] -_08051E1A: - movs r0, 0 - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_08051E2C: .4byte gDungeon -_08051E30: .4byte 0x0000e220 -_08051E34: .4byte 0x0000e222 -_08051E38: .4byte 0x0000fffc - thumb_func_end sub_8051A74 - - thumb_func_start sub_8051E3C -sub_8051E3C: - push {r4-r6,lr} - sub sp, 0x4 - movs r5, 0 -_08051E42: - movs r4, 0 - adds r6, r5, 0x1 -_08051E46: - adds r0, r4, 0 - adds r1, r5, 0 - bl GetTileMut - adds r2, r0, 0 - ldrb r0, [r2, 0xE] - cmp r0, 0xF - bls _08051E66 - adds r1, r0, 0 - movs r0, 0 - str r0, [sp] - adds r0, r2, 0 - adds r2, r4, 0 - adds r3, r5, 0 - bl sub_8051A74 -_08051E66: - adds r4, 0x1 - cmp r4, 0x37 - ble _08051E46 - adds r5, r6, 0 - cmp r5, 0x1F - ble _08051E42 - add sp, 0x4 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8051E3C - - thumb_func_start sub_8051E7C -sub_8051E7C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - mov r9, r0 - movs r1, 0x4 - ldrsh r0, [r0, r1] - mov r2, r9 - movs r3, 0x6 - ldrsh r1, [r2, r3] - subs r1, 0x1 - bl GetTileMut - str r0, [sp, 0x8] - ldrh r1, [r0] - movs r0, 0x80 - lsls r0, 5 - ands r0, r1 - cmp r0, 0 - bne _08051EB8 - ldr r0, _08051EB4 - ldr r1, [r0] - mov r0, r9 - bl LogMessageByIdWithPopupCheckUser - b _080520F6 - .align 2, 0 -_08051EB4: .4byte gUnknown_80FDDF0 -_08051EB8: - ldr r0, _08051EF0 - ldr r0, [r0] - ldr r1, _08051EF4 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0 - beq _08051EC8 - b _080520EC -_08051EC8: - mov r2, r9 - ldrh r1, [r2, 0x6] - subs r1, 0x1 - lsls r1, 16 - ldrh r0, [r2, 0x4] - orrs r0, r1 - str r0, [sp, 0x4] - mov r0, r9 - bl GetEntityRoom - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0xC] - mov r3, r9 - movs r1, 0x6 - ldrsh r0, [r3, r1] - adds r6, r0, 0 - subs r6, 0x15 - b _08051FE0 - .align 2, 0 -_08051EF0: .4byte gDungeon -_08051EF4: .4byte 0x00003a09 -_08051EF8: - mov r2, r9 - movs r3, 0x4 - ldrsh r0, [r2, r3] - adds r5, r0, 0 - subs r5, 0x14 - adds r0, 0x14 - adds r1, r6, 0x1 - str r1, [sp, 0x10] - cmp r5, r0 - bgt _08051FD8 - ldr r2, _080520C0 - mov r10, r2 -_08051F10: - mov r0, r10 - ldr r3, [r0] - ldr r1, _080520C4 - adds r0, r3, r1 - ldr r1, [r0] - subs r2, r5, r1 - mov r8, r2 - ldr r2, _080520C8 - adds r0, r3, r2 - ldr r2, [r0] - subs r7, r6, r2 - mov r0, r8 - cmp r0, 0 - blt _08051FCA - cmp r7, 0 - blt _08051FCA - cmp r0, 0x7 - bgt _08051FCA - cmp r7, 0x7 - bgt _08051FCA - adds r0, r1, 0x1 - cmp r5, r0 - blt _08051FCA - adds r0, r2, 0x1 - cmp r6, r0 - blt _08051FCA - ldr r1, _080520CC - adds r0, r3, r1 - ldr r0, [r0] - subs r0, 0x1 - cmp r5, r0 - bge _08051FCA - ldr r2, _080520D0 - adds r0, r3, r2 - ldr r0, [r0] - subs r0, 0x1 - cmp r6, r0 - bge _08051FCA - adds r0, r5, 0 - adds r1, r6, 0 - bl GetTileMut - adds r4, r0, 0 - ldrh r0, [r4] - movs r3, 0x80 - lsls r3, 1 - adds r1, r3, 0 - ands r0, r1 - cmp r0, 0 - beq _08051F9A - mov r0, r10 - ldr r2, [r0] - lsls r1, r7, 1 - adds r1, r7 - lsls r1, 3 - mov r3, r8 - lsls r0, r3, 1 - add r0, r8 - lsls r0, 6 - adds r1, r0 - adds r2, r1 - ldr r1, _080520D4 - adds r0, r2, r1 - ldrh r0, [r0] - strh r0, [r4] - ldr r3, _080520D8 - adds r2, r3 - ldrh r0, [r2] - strh r0, [r4, 0x4] -_08051F9A: - mov r1, r10 - ldr r0, [r1] - mov r2, r8 - lsls r1, r2, 3 - adds r1, r7, r1 - ldr r3, _080520DC - adds r0, r3 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x1 - str r0, [sp] - adds r0, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl sub_8051A74 - ldrh r1, [r4, 0x4] - movs r0, 0x3 - orrs r0, r1 - strh r0, [r4, 0x4] - ldr r0, [sp, 0xC] - cmp r0, 0xFF - beq _08051FCA - strb r0, [r4, 0x9] -_08051FCA: - adds r5, 0x1 - mov r2, r9 - movs r3, 0x4 - ldrsh r0, [r2, r3] - adds r0, 0x14 - cmp r5, r0 - ble _08051F10 -_08051FD8: - ldr r6, [sp, 0x10] - mov r1, r9 - movs r2, 0x6 - ldrsh r0, [r1, r2] -_08051FE0: - adds r0, 0x13 - cmp r6, r0 - ble _08051EF8 - mov r3, r9 - movs r1, 0x6 - ldrsh r0, [r3, r1] - adds r6, r0, 0 - subs r6, 0x15 - adds r0, 0x13 - ldr r7, _080520C0 - cmp r6, r0 - bgt _0805207A -_08051FF8: - mov r2, r9 - movs r3, 0x4 - ldrsh r0, [r2, r3] - adds r5, r0, 0 - subs r5, 0x14 - adds r0, 0x14 - adds r1, r6, 0x1 - str r1, [sp, 0x10] - cmp r5, r0 - bgt _0805206C - ldr r7, _080520C0 -_0805200E: - ldr r0, _080520C0 - ldr r4, [r0] - ldr r2, _080520C4 - adds r0, r4, r2 - ldr r2, [r0] - subs r1, r5, r2 - ldr r3, _080520C8 - adds r0, r4, r3 - ldr r3, [r0] - subs r0, r6, r3 - cmp r1, 0 - blt _0805205E - cmp r0, 0 - blt _0805205E - cmp r1, 0x7 - bgt _0805205E - cmp r0, 0x7 - bgt _0805205E - adds r0, r2, 0x1 - cmp r5, r0 - blt _0805205E - adds r0, r3, 0x1 - cmp r6, r0 - blt _0805205E - ldr r1, _080520CC - adds r0, r4, r1 - ldr r0, [r0] - subs r0, 0x1 - cmp r5, r0 - bge _0805205E - ldr r2, _080520D0 - adds r0, r4, r2 - ldr r0, [r0] - subs r0, 0x1 - cmp r6, r0 - bge _0805205E - adds r0, r5, 0 - adds r1, r6, 0 - bl sub_80498A8 -_0805205E: - adds r5, 0x1 - mov r3, r9 - movs r1, 0x4 - ldrsh r0, [r3, r1] - adds r0, 0x14 - cmp r5, r0 - ble _0805200E -_0805206C: - ldr r6, [sp, 0x10] - mov r2, r9 - movs r3, 0x6 - ldrsh r0, [r2, r3] - adds r0, 0x13 - cmp r6, r0 - ble _08051FF8 -_0805207A: - ldr r0, [r7] - ldr r1, _080520E0 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0] - ldr r2, [sp, 0x8] - ldrh r1, [r2] - ldr r0, _080520E4 - ands r0, r1 - strh r0, [r2] - mov r3, r9 - movs r1, 0x4 - ldrsh r0, [r3, r1] - movs r2, 0x6 - ldrsh r1, [r3, r2] - subs r1, 0x1 - bl sub_80498A8 - bl sub_8049B8C - bl sub_8049ED4 - add r0, sp, 0x4 - bl sub_80429FC - ldr r0, _080520E8 - ldr r1, [r0] - mov r0, r9 - bl LogMessageByIdWithPopupCheckUser - movs r0, 0x14 - movs r1, 0x3C - bl sub_803E708 - b _080520F6 - .align 2, 0 -_080520C0: .4byte gDungeon -_080520C4: .4byte 0x0000e250 -_080520C8: .4byte 0x0000e254 -_080520CC: .4byte 0x0000e258 -_080520D0: .4byte 0x0000e25c -_080520D4: .4byte 0x0000e27c -_080520D8: .4byte 0x0000e280 -_080520DC: .4byte 0x0000e87c -_080520E0: .4byte 0x00003a09 -_080520E4: .4byte 0x0000efef -_080520E8: .4byte gUnknown_80FDDD0 -_080520EC: - ldr r0, _08052108 - ldr r1, [r0] - mov r0, r9 - bl LogMessageByIdWithPopupCheckUser -_080520F6: - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08052108: .4byte gUnknown_80FDDF0 - thumb_func_end sub_8051E7C - - thumb_func_start sub_805210C -sub_805210C: - push {r4-r7,lr} - lsls r0, 24 - lsrs r5, r0, 24 - movs r3, 0 - ldr r7, _080521B4 - movs r4, 0x1 - ldr r2, [r7] -_0805211A: - ldrb r1, [r2] - adds r0, r4, 0 - ands r0, r1 - cmp r0, 0 - beq _0805212A - ldrb r0, [r2, 0x2] - cmp r0, r5 - beq _080521C8 -_0805212A: - adds r2, 0x4 - adds r3, 0x1 - cmp r3, 0x13 - ble _0805211A - movs r3, 0 - ldr r0, _080521B8 - ldr r4, [r0] - movs r6, 0x1 -_0805213A: - movs r0, 0x64 - adds r2, r3, 0 - muls r2, r0 - adds r0, r2, r4 - ldr r1, _080521BC - adds r0, r1 - ldrb r1, [r0] - adds r0, r6, 0 - ands r0, r1 - cmp r0, 0 - beq _0805216C - adds r0, r2, r4 - ldr r1, _080521C0 - adds r0, r1 - ldrb r1, [r0] - adds r0, r6, 0 - ands r0, r1 - adds r1, r2, r4 - cmp r0, 0 - beq _0805216C - ldr r2, _080521C4 - adds r0, r1, r2 - ldrb r0, [r0] - cmp r0, r5 - beq _080521C8 -_0805216C: - adds r3, 0x1 - cmp r3, 0x3 - ble _0805213A - movs r3, 0 - ldr r0, _080521B8 - ldr r4, [r0] -_08052178: - movs r0, 0x58 - muls r0, r3 - adds r2, r0, r4 - ldrb r1, [r2] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08052196 - adds r0, r2, 0 - adds r0, 0x28 - ldrb r0, [r0] - cmp r0, 0 - beq _08052196 - cmp r0, r5 - beq _080521C8 -_08052196: - adds r3, 0x1 - movs r0, 0xCE - lsls r0, 1 - cmp r3, r0 - ble _08052178 - ldr r0, [r7] - lsls r1, r5, 1 - adds r0, 0x50 - adds r0, r1 - ldrh r0, [r0] - cmp r0, 0 - bne _080521C8 - movs r0, 0 - b _080521CA - .align 2, 0 -_080521B4: .4byte gTeamInventoryRef -_080521B8: .4byte gRecruitedPokemonRef -_080521BC: .4byte 0x00008df8 -_080521C0: .4byte 0x00008e38 -_080521C4: .4byte 0x00008e3a -_080521C8: - movs r0, 0x1 -_080521CA: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_805210C - - .align 2,0 diff --git a/asm/code_807E5AC.s b/asm/code_807E5AC.s index eaf80cb03..084893b9e 100644 --- a/asm/code_807E5AC.s +++ b/asm/code_807E5AC.s @@ -2497,7 +2497,7 @@ _0807FA56: movs r0, 0x11 mov r1, sp movs r2, 0x2 - bl sub_8045684 + bl SpawnTrap cmp r0, 0 beq _0807FA88 str r0, [r4, 0x14] @@ -2508,7 +2508,7 @@ _0807FA56: _0807FA72: mov r1, sp movs r2, 0 - bl sub_8045684 + bl SpawnTrap cmp r0, 0 beq _0807FA88 str r0, [r4, 0x14] diff --git a/include/code_80450F8.h b/include/code_80450F8.h index f86f4a608..e3bfc4be2 100644 --- a/include/code_80450F8.h +++ b/include/code_80450F8.h @@ -3,8 +3,8 @@ #include "structs/dungeon_entity.h" -Entity *sub_8045684(u8 trapID, DungeonPos *pos, u8 c); +Entity *SpawnTrap(u8 trapID, DungeonPos *pos, u8 c); Entity *sub_8045708(DungeonPos *pos); void sub_80457DC(Entity* ent); -#endif // GUARD_CODE_80227B8_H \ No newline at end of file +#endif // GUARD_CODE_80227B8_H diff --git a/include/dungeon_generation.h b/include/dungeon_generation.h index 10a187d2b..9e37dd96a 100644 --- a/include/dungeon_generation.h +++ b/include/dungeon_generation.h @@ -53,5 +53,11 @@ enum SecondaryStructureType { void GenerateFloor(void); bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); +void sub_804EB30(void); +void sub_8051E3C(void); + +#include "structs/dungeon_entity.h" + +void sub_8051E7C(Entity *pokemon); #endif diff --git a/include/pokemon.h b/include/pokemon.h index 4989129cd..27abf917a 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -105,6 +105,11 @@ static inline bool8 PokemonFlag1(PokemonStruct1 *mon) return (mon->unk0 >> (FLAG_UNK_1 - 1)) & 1; } +static inline bool8 PokemonFlag1Struct2(PokemonStruct2 *mon) +{ + return (mon->unk0 >> (FLAG_UNK_1 - 1)) & 1; +} + static inline bool8 PokemonFlag2(PokemonStruct1 *mon) { return (mon->unk0 >> (FLAG_ON_TEAM - 1)) & 1; diff --git a/ld_script.txt b/ld_script.txt index b2e85654e..79bfe76e5 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -227,7 +227,6 @@ SECTIONS { src/dungeon_map_access.o(.text); src/tile_types.o(.text); src/dungeon_generation.o(.text); - asm/code_804FD30.o(.text); src/dungeon_message.o(.text); src/dungeon_move.o(.text); src/move_actions.o(.text); diff --git a/src/code_80450F8.c b/src/code_80450F8.c index 38f2308b9..4ef646b6b 100644 --- a/src/code_80450F8.c +++ b/src/code_80450F8.c @@ -524,7 +524,7 @@ Entity *sub_804550C(s16 a) ); } -Entity *sub_8045684(u8 trapID, DungeonPos *pos, u8 c) +Entity *SpawnTrap(u8 trapID, DungeonPos *pos, u8 c) { Entity *entity; s32 i; diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 84019d8b0..bdb438a9c 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -3,10 +3,13 @@ #include "file_system.h" #include "tile_types.h" #include "dungeon_map_access.h" +#include "dungeon_message.h" #include "dungeon_random.h" +#include "dungeon_util.h" #include "items.h" #include "pokemon.h" #include "code_80450F8.h" +#include "code_803E668.h" #include "constants/direction.h" #include "constants/item.h" #include "constants/monster.h" @@ -17,15 +20,15 @@ extern const u8 gUnknown_80F6DCC[]; extern struct FileArchive gDungeonFileArchive; -extern void ResetFloor(void); -extern void ResetFloor(void); -extern void GenerateOneRoomMonsterHouseFloor(void); -extern void ResolveInvalidSpawns(void); -extern void GenerateTwoRoomsWithMonsterHouseFloor(void); +extern void sub_80460F8(DungeonPos *, Item *, u32); +extern s32 sub_803DA20(s16 species); +extern void sub_8049840(void); +extern void sub_80429FC(DungeonPos *r0); +extern void sub_80498A8(s32, s32); +extern void sub_8049B8C(void); extern u8 GetFloorType(); extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); -extern const DungeonPos gAdjacentTileOffsets[]; extern const bool8 gUnknown_80F6DD5[][NUM_DIRECTIONS]; enum CardinalDirection @@ -71,48 +74,50 @@ struct GridCell #define GRID_CELL_LEN 15 +static void ResetFloor(void); static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fixedRoomSizeY, s32 fixedRoomNumber, FloorProperties *floorProps); static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 fixedRoomSizeX, s32 fixedRoomSizeY); -void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber); -void sub_8051288(s32 fixedRoomNumber); -void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); -void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); -void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); -void GenerateSecondaryStructure(struct GridCell *gridCell); -void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); -void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber); -void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); -void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); -void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY); +static void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber); +static void sub_8051288(s32 fixedRoomNumber); +static void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); +static void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +static void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +static void GenerateSecondaryStructure(struct GridCell *gridCell); +static void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); +static void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber); +static void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); +static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); +static void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY); static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps); -void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps); -void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); -void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain); -void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex); -void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); -void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); -void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); +static void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps); +static void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +static void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain); +static void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex); +static void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +static void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); +static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); -void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s32 turnX, s32 turnY); -void EnsureImpassableTilesAreWalls(void); -void sub_804FC74(void); -void sub_804EB30(void); -void FinalizeJunctions(void); -void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); -bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps); -void GenerateStandardFloor(s32 a0, s32 a1, FloorProperties *a2); -void GenerateOuterRingFloor(FloorProperties *a0); -void GenerateCrossroadsFloor(FloorProperties *a0); -void GenerateLineFloor(FloorProperties *a0); -void GenerateCrossFloor(FloorProperties *a0); -void GenerateBeetleFloor(FloorProperties *a0); -void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps); -void sub_8051654(FloorProperties *floorProps); -void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps); -void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); -void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); -bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); -void ResetInnerBoundaryTileRows(void); +static void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s32 turnX, s32 turnY); +static void EnsureImpassableTilesAreWalls(void); +static void sub_804FC74(void); +static void FinalizeJunctions(void); +static void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); +static bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps); +static void GenerateStandardFloor(s32 a0, s32 a1, FloorProperties *a2); +static void GenerateOuterRingFloor(FloorProperties *a0); +static void GenerateCrossroadsFloor(FloorProperties *a0); +static void GenerateLineFloor(FloorProperties *a0); +static void GenerateCrossFloor(FloorProperties *a0); +static void GenerateBeetleFloor(FloorProperties *a0); +static void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps); +static void sub_8051654(FloorProperties *floorProps); +static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps); +static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); +static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); +static void ResetInnerBoundaryTileRows(void); +static void GenerateOneRoomMonsterHouseFloor(void); +static void ResolveInvalidSpawns(void); +static void GenerateTwoRoomsWithMonsterHouseFloor(void); EWRAM_DATA bool8 gUnknown_202F1A8 = FALSE; static EWRAM_DATA bool8 sInvalidGeneration = FALSE; @@ -450,7 +455,7 @@ void GenerateFloor(void) CloseFile(gDungeon->unk13568); } -void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) +static void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) { s32 x, y; for (x = xStart; x < maxX; x++) { @@ -490,7 +495,7 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) * 6. Create additional "extra hallways" with random walks outside of existing rooms * 7. Finalize extra room details with imperfections (unused in vanilla?), and structures with secondary terrain */ -void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps) +static void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -519,7 +524,7 @@ void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorP } // GenerateOuterRingFloor - Generates on a 6x4 grid, with the outer border of grid cells being hallways and the inner 4x2 grid being rooms. -void GenerateOuterRingFloor(FloorProperties *floorProps) +static void GenerateOuterRingFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -668,7 +673,7 @@ void GenerateOuterRingFloor(FloorProperties *floorProps) * GenerateCrossroadsFloor - Generates a floor layout with hallways on the inside and rooms on the outside, with empty corners. * Also nicknamed "Ladder Layout" by some. */ -void GenerateCrossroadsFloor(FloorProperties *floorProps) +static void GenerateCrossroadsFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -799,7 +804,7 @@ void GenerateCrossroadsFloor(FloorProperties *floorProps) } // GenerateLineFloor - Generates a floor layout with 5 grid cells in a horizontal line. -void GenerateLineFloor(FloorProperties *floorProps) +static void GenerateLineFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -837,7 +842,7 @@ void GenerateLineFloor(FloorProperties *floorProps) } // GenerateCrossFloor - Generates a floor layout with 5 rooms arranged in a "plus" or "cross" configuration. -void GenerateCrossFloor(FloorProperties *floorProps) +static void GenerateCrossFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -893,7 +898,7 @@ void GenerateCrossFloor(FloorProperties *floorProps) // GenerateBeetleFloor - Generates a floor layout in a "beetle" shape, with a // 3x3 grid of rooms, a merged center column, and hallways along each row -void GenerateBeetleFloor(FloorProperties *floorProps) +static void GenerateBeetleFloor(FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -976,7 +981,7 @@ static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct Grid // GenerateOuterRoomsFloor - Generates a floor layout with a ring of rooms and nothing on the interior. // This layout is bugged and will not properly connect rooms for gridSizeX < 3. -void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps) +static void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1054,7 +1059,7 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *fl GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); } -bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps) +static bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps) { s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->x; s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->y; @@ -1118,7 +1123,7 @@ static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fi * GenerateOneRoomMonsterHouseFloor - Generates a floor layout with just one large room which is a Monster House. * This generator is used as a fallback if the event generation fails too many times. */ -void GenerateOneRoomMonsterHouseFloor(void) +static void GenerateOneRoomMonsterHouseFloor(void) { s32 x, y; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; @@ -1144,7 +1149,7 @@ void GenerateOneRoomMonsterHouseFloor(void) } // GenerateTwoRoomsWithMonsterHouseFloor - Generates a floor layout with two rooms (left and right), with one being a Monster House. -void GenerateTwoRoomsWithMonsterHouseFloor(void) +static void GenerateTwoRoomsWithMonsterHouseFloor(void) { struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN]; @@ -1228,7 +1233,7 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void) * * Repeat 4-8 until a check fails. */ -void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways) +static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways) { s32 i, j; @@ -1426,7 +1431,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s } // GetGridPositions - Determines the starting positions of grid cells based on the given floor grid dimensions -void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY) +static void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY) { s32 i, sum; @@ -1449,7 +1454,7 @@ void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY) * The dungeon grid is an array of grid cells stored in column-major order * (to give contiguous storage to cells with the same x value), with a fixed column size of 15. */ -void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) +static void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) { s32 x, y; @@ -1502,7 +1507,7 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gri */ #define ROOM_BITS_COUNT 256 // Despite max rooms being 32, randomRoomBits can hold up to 256 possible rooms -void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber) +static void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber) { bool8 randomRoomBits[ROOM_BITS_COUNT]; s32 i, nShuffles; @@ -1602,7 +1607,7 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz * * If the room is an anchor, a single tile is placed with a hallway indicator for later. */ -void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags) +static void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags) { s32 roomNumber = 0; s32 x, y; @@ -1748,7 +1753,7 @@ void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s * * If a room doesn't meet the conditions for the secondary structure chosen, it will be left unchanged. */ -void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) +static void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) { s32 x, y; @@ -1799,7 +1804,7 @@ static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][ * */ -void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps) +static void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps) { s32 i; s32 x = cursorX; @@ -2031,7 +2036,7 @@ void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN * Merged rooms take up the full tile space occupied between the two rooms. * */ -void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging) +static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging) { s32 x, y; @@ -2407,7 +2412,7 @@ void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN * We pick a random corner, derive our direction from the movement being used, then seek up to 10 tiles for one to replace. * We avoid getting too close to hallways and ensure our cardinal neighbor tiles match what we expect for open terrain. */ -void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) +static void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) { s32 x, y; @@ -2620,7 +2625,7 @@ void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN * * The vertical flag specifies whether the hallway is being generated horizontally or vertically */ -void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 turnX_, s32 turnY_) +static void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 turnX_, s32 turnY_) { s32 startX = x; s32 startY = y; @@ -2780,7 +2785,7 @@ void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 turnX_, * * If no eligible room is found, the room will be removed and filled back in. */ -void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY) +static void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY) { s32 x, y; @@ -2927,7 +2932,7 @@ void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 * * Otherwise, the tile will be a wall. */ -void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomIndex) +static void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomIndex) { SetTerrainWall(tile); if (useSecondaryTerrain && tile->room == roomIndex) { @@ -2962,7 +2967,7 @@ void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomInd * X | X X X * X | X X X */ -void FinalizeJunctions(void) +static void FinalizeJunctions(void) { s32 x, y; @@ -3066,7 +3071,7 @@ void sub_804EB30(void) * The kecleon shop will occupy the whole room interior, with a one tile margin from the room walls. * Kecleon shop tiles restrict monster and stair spawns. */ -void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) +static void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) { s16 listX[GRID_CELL_LEN]; s16 listY[GRID_CELL_LEN]; @@ -3224,7 +3229,7 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 * A Monster House will be generated in a random room that's valid, connected, not merged, not a maze room, and * is not a few unknown conditions. */ -void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) +static void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) { // To spawn a monster house on this floor: // - It must meet the probability chance @@ -3351,7 +3356,7 @@ void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s3 * Candidate maze rooms have to be valid, connected, have odd dimensions, and not have any other features. * If any candidates are found, the game will select one of these rooms and call GenerateMaze. */ -void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) +static void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) { bool8 values[256]; s32 i; @@ -3459,7 +3464,7 @@ void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gr * surrounded by striples of obstacles (maze walls). * */ -void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) +static void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) { s32 curX, curY; u8 roomIndex; @@ -3550,7 +3555,7 @@ void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) * If an open tile is found, an obstacle is placed between the two tiles, and (x0, y0) moves to the new open tile. * This process continues until no valid open tile can be found. */ -void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex) +static void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex) { while (1) { s32 direction = DungeonRandInt(NUM_CARDINAL_DIRECTIONS); @@ -3630,7 +3635,7 @@ void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bo } } -void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag) +static void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag) { SetTerrainSecondary(tile); tile->terrainType |= additionalFlag; @@ -3639,7 +3644,7 @@ void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag) /* * SetSpawnFlag5 - Sets unknown spawn flag 0x5 on all tiles in a room */ -void SetSpawnFlag5(struct GridCell *gridCell) +static void SetSpawnFlag5(struct GridCell *gridCell) { s32 x, y; @@ -3653,7 +3658,7 @@ void SetSpawnFlag5(struct GridCell *gridCell) /* * IsNextToHallway - Checks if a tile DungeonPos is either in a hallway or next to one. */ -bool8 IsNextToHallway(s32 x, s32 y) +static bool8 IsNextToHallway(s32 x, s32 y) { s32 offsetX, offsetY; s32 posX, posY; @@ -3683,7 +3688,7 @@ bool8 IsNextToHallway(s32 x, s32 y) } // See GenerateSecondaryStructures for more information. -void GenerateSecondaryStructure(struct GridCell *gridCell) +static void GenerateSecondaryStructure(struct GridCell *gridCell) { switch (DungeonRandInt(6)) { // Generate a "split room" with two sides separated by a line of water/lava @@ -3888,7 +3893,7 @@ void GenerateSecondaryStructure(struct GridCell *gridCell) * * A tile marked for an item also must not have a trap there */ -void ResolveInvalidSpawns(void) +static void ResolveInvalidSpawns(void) { s32 x, y; @@ -3919,7 +3924,7 @@ void ResolveInvalidSpawns(void) } // Converts Secondary terrain to both secondary and normal. Possibly to note that it's a water tile? -void sub_804FC74(void) +static void sub_804FC74(void) { s32 x, y; @@ -3935,7 +3940,7 @@ void sub_804FC74(void) /* * EnsureImpassableTilesAreWalls - Force all tiles with the impassable flag to be set as walls. */ -void EnsureImpassableTilesAreWalls(void) +static void EnsureImpassableTilesAreWalls(void) { s32 x, y; @@ -3948,7 +3953,7 @@ void EnsureImpassableTilesAreWalls(void) } } -void ResetTile(Tile *tile) +static void ResetTile(Tile *tile) { tile->terrainType = 0; tile->spawnOrVisibilityFlags = 0; @@ -3977,7 +3982,7 @@ static inline bool8 PosIsOutOfBounds(s32 x, s32 y) return FALSE; } -void ResetFloor(void) +static void ResetFloor(void) { s32 x, y; @@ -4028,7 +4033,7 @@ struct PositionU8 /* * ShuffleSpawnPositions - Randomly shuffle an array of spawn positions */ -void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count) +static void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count) { s32 i; // Do twice as many swaps as there are items in the array @@ -4058,7 +4063,7 @@ void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count) */ extern const s16 gUnknown_80F4DA0; extern const s16 gUnknown_80F4DA4; -void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) +static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) { struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; s32 count; @@ -4394,7 +4399,7 @@ void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) /* * SpawnEnemies - Spawns all enemies, including those in forced monster houses */ -void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) +static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) { struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; s32 count; @@ -4590,7 +4595,7 @@ extern const s32 gUnknown_80F6DF8[8]; // https://decomp.me/scratch/sA4YH - Blue // https://decomp.me/scratch/SNyV8 - Sky #ifdef NONMATCHING -void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) +static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) { s32 densityN; s32 x, y; @@ -4848,7 +4853,7 @@ void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) } #else -NAKED void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) +NAKED static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) { asm_unified("\n" " push {r4-r7,lr}\n" @@ -5841,7 +5846,7 @@ static EWRAM_DATA u8 gUnknown_202F1E0 = 0; static EWRAM_DATA u8 gUnknown_202F1E1 = 0; static UNUSED EWRAM_DATA s32 sUnusedEwram = 0; -u8 sub_80511F0(void) +static u8 sub_80511F0(void) { if (gUnknown_202F1E1 != 0) { gUnknown_202F1E1--; @@ -5861,16 +5866,17 @@ u8 sub_80511F0(void) return gUnknown_202F1E0; } -bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5); +static bool8 PlaceFixedRoomTile(Tile *tile, u8 a1, s32 x, s32 y, u8 a5); +static bool8 sub_805210C(u8 itemId); -bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) +static bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) { tile->terrainType |= TERRAIN_TYPE_UNBREAKABLE; tile->unkE = 0; - return sub_8051A74(tile, a1, x, y, a5); + return PlaceFixedRoomTile(tile, a1, x, y, a5); } -void sub_8051288(s32 fixedRoomNumber) +static void sub_8051288(s32 fixedRoomNumber) { s32 x, y; Dungeon *dungeon = gDungeon; @@ -5931,7 +5937,7 @@ void sub_8051288(s32 fixedRoomNumber) FinalizeJunctions(); } -void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) +static void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) { s32 x, y; Dungeon *dungeon = gDungeon; @@ -5987,7 +5993,7 @@ void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) extern const s16 gUnknown_80F57D4[][3][3]; -void sub_8051654(FloorProperties *floorProps) +static void sub_8051654(FloorProperties *floorProps) { s32 i, n; s32 x, y; @@ -6094,7 +6100,7 @@ void sub_8051654(FloorProperties *floorProps) * * This is needed because during generation these soft border walls may have been altered or breached. */ -void ResetInnerBoundaryTileRows(void) +static void ResetInnerBoundaryTileRows(void) { s32 x; @@ -6113,12 +6119,7 @@ void ResetInnerBoundaryTileRows(void) } } -bool8 sub_805210C(u8 itemId); - -extern void sub_80460F8(DungeonPos *, Item *, u32); -extern s32 sub_803DA20(s16 species); - -void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) +static void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) { Item item; DungeonPos pos = {x, y}; @@ -6139,7 +6140,7 @@ void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) } // s16 species memes strike again. Will the fix ever be discovered? -void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_) +static void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_, u32 UNUSED unused) { struct unkStruct_806B7F8 unkStruct; s32 species = SpeciesId(species_); @@ -6167,7 +6168,7 @@ void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_) } } -void sub_8051A24(u8 trapId, s32 x, s32 y, bool8 isVisible) +static void SpawnEnemyTrapAtPos(u8 trapId, s32 x, s32 y, bool8 isVisible) { DungeonPos pos; Entity *trapEntity; @@ -6175,7 +6176,7 @@ void sub_8051A24(u8 trapId, s32 x, s32 y, bool8 isVisible) pos.x = x; pos.y = y; - trapEntity = sub_8045684(trapId, &pos, 0); + trapEntity = SpawnTrap(trapId, &pos, 0); if (trapEntity != NULL) { tile->object = trapEntity; trapEntity->isVisible = isVisible; @@ -6190,59 +6191,58 @@ struct UnkStruct_80F6D20 s16 unk8; u8 unkA; u8 unkB; - u8 fillC; + u8 unkC; u8 unkD; u8 unkE; }; extern const struct UnkStruct_80F6D20 gUnknown_80F6D20[]; -extern void sub_8049840(void); - -bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) +// Used to spawn a single tile when generating a fixed room. The tile might contain an item or a monster. +static bool8 PlaceFixedRoomTile(Tile *tile, u8 fixedRoomActionId, s32 x, s32 y, bool8 a5) { - if (a1 > 0xF) { + if (fixedRoomActionId > 0xF) { SetTerrainNormal(tile); } - switch (a1) { + switch (fixedRoomActionId) { case 69: gDungeon->unk644.unk40 = x; gDungeon->unk644.unk42 = y; - sub_8051A24(0xB, x, y, FALSE); + SpawnEnemyTrapAtPos(TRAP_SEAL_TRAP, x, y, FALSE); // fall through case 0: SetTerrainNormal(tile); tile->room = 0; - return FALSE; + break; case 1: SetTerrainWall(tile); tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE); tile->room = CORRIDOR_ROOM; - return FALSE; + break; case 4: SetTerrainNormal(tile); - tile->room = 0; gDungeon->playerSpawn.x = x; - gDungeon->playerSpawn.x = y; + gDungeon->playerSpawn.y = y; tile->room = 0; - return FALSE; + break; case 5: - SetTerrainNormal(tile); + SetTerrainSecondary(tile); tile->room = 0; - return FALSE; + break; case 6: SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL); - tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE); tile->room = CORRIDOR_ROOM; - return FALSE; + break; case 7: gUnknown_202F1A8 = 1; sub_8049840(); + // fall through + case 10: SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL); tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; tile->room = CORRIDOR_ROOM; - return FALSE; + break; case 8: case 67: SetTerrainNormal(tile); @@ -6251,70 +6251,198 @@ bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) tile->room = 0; gDungeon->stairsSpawn.x = x; gDungeon->stairsSpawn.y = y; - return FALSE; + break; case 68: tile->terrainType |= TERRAIN_TYPE_UNK_x800; SetTerrainNormal(tile); tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); tile->room = 0; - return FALSE; + break; case 9: SetTerrainNormal(tile); tile->room = CORRIDOR_ROOM; - return FALSE; + break; case 11: SetTerrainNormal(tile); tile->terrainType |= TERRAIN_TYPE_UNK_x800; tile->room = 0; - return FALSE; + break; case 12: SetTerrainNormal(tile); tile->terrainType |= TERRAIN_TYPE_UNK_x1000; tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; tile->terrainType |= TERRAIN_TYPE_UNK_x800; tile->room = 0; - return FALSE; + break; case 2: case 13: case 14: SetTerrainWall(tile); tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; tile->room = CORRIDOR_ROOM; - return FALSE; + break; default: - if (a1 > 16 && a1 < 190) { - if (gUnknown_80F6D20[a1].unk0 != 0) { + if (fixedRoomActionId > 15 && fixedRoomActionId < 220) { + const struct UnkStruct_80F6D20 *ptr = &gUnknown_80F6D20[fixedRoomActionId]; + tile->room = ptr->unkC; + if (ptr->unk0 != 0) { if (a5) { - sub_805193C(gUnknown_80F6D20[a1].unk0, x, y, gUnknown_80F6D20[a1].unk2, gUnknown_80F6D20[a1].unk4); + sub_805193C(ptr->unk0, x, y, ptr->unk2, ptr->unk4); } else { - gDungeon->unk644.unk47 = gUnknown_80F6D20[a1].unk0; + gDungeon->unk644.unk47 = ptr->unk0; } } else { - if (gUnknown_80F6D20[a1].unk4 != 0) { - gDungeon->unkE220[gUnknown_80F6D20[a1].unk4 - 1].x = x; - gDungeon->unkE220[gUnknown_80F6D20[a1].unk4 - 1].y = y; + if (ptr->unk4 != 0) { + gDungeon->unkE220[ptr->unk4 - 1].x = x; + gDungeon->unkE220[ptr->unk4 - 1].y = y; } } - if (gUnknown_80F6D20[a1].unk8 != 0) { - sub_8051998(gUnknown_80F6D20[a1].unk8, x, y, gUnknown_80F6D20[a1].unkA); + if (ptr->unk8 != 0) { + sub_8051998(ptr->unk8, x, y, ptr->unkA, fixedRoomActionId); } - if (gUnknown_80F6D20[a1].unkB != 20 && a5) { - sub_8051A24(gUnknown_80F6D20[a1].unkB, x, y, gUnknown_80F6D20[a1].unkD); + if (ptr->unkB != 20 && a5) { + SpawnEnemyTrapAtPos(ptr->unkB, x, y, ptr->unkD); } - if (gUnknown_80F6D20[a1].unkD != 0) { + if (ptr->unkE != 0) { SetTerrainSecondary(tile); } } break; case 3: case 15: - return FALSE; + break; } return FALSE; } + +void sub_8051E3C(void) +{ + s32 x, y; + + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { + Tile *tile = GetTileMut(x, y); + if (tile->unkE > 0xF) { + PlaceFixedRoomTile(tile, tile->unkE, x, y, FALSE); + } + } + } +} + +extern const u8 *const gUnknown_80FDDF0; +extern const u8 *const gUnknown_80FDDD0; + +void sub_8051E7C(Entity *pokemon) +{ + Tile *tile = GetTileMut(pokemon->pos.x, pokemon->pos.y - 1); + + if (!(tile->terrainType & TERRAIN_TYPE_UNK_x1000)) { + LogMessageByIdWithPopupCheckUser(pokemon, gUnknown_80FDDF0); // It can't be used here! + } + else if (!gDungeon->unk3A09) { + s32 x, y; + DungeonPos pos = {pokemon->pos.x, pokemon->pos.y - 1}; + u32 roomId = GetEntityRoom(pokemon); + + for (y = pokemon->pos.y - 21; y <= pokemon->pos.y + 19; y++) { + for (x = pokemon->pos.x -20; x <= pokemon->pos.x + 20; x++) { + Tile *loopTile; + s32 xDiff = x - gDungeon->unkE250.minX; + s32 yDiff = y - gDungeon->unkE250.minY; + + if (xDiff < 0 || yDiff < 0) + continue; + if (xDiff >= 8 || yDiff >= 8) + continue; + if (x < gDungeon->unkE250.minX + 1 || y < gDungeon->unkE250.minY + 1) + continue; + if (x >= gDungeon->unkE250.maxX - 1 || y >= gDungeon->unkE250.maxY - 1) + continue; + + loopTile = GetTileMut(x, y); + if (loopTile->terrainType & TERRAIN_TYPE_UNBREAKABLE) { + loopTile->terrainType = gDungeon->unkE27C[xDiff][yDiff].terrainType; + loopTile->spawnOrVisibilityFlags = gDungeon->unkE27C[xDiff][yDiff].spawnOrVisibilityFlags; + } + + PlaceFixedRoomTile(loopTile, gDungeon->unkE87C[xDiff][yDiff], x, y, TRUE); + loopTile->spawnOrVisibilityFlags |= 3; + if (roomId != CORRIDOR_ROOM) { + loopTile->room = roomId; + } + } + } + + for (y = pokemon->pos.y - 21; y <= pokemon->pos.y + 19; y++) { + for (x = pokemon->pos.x -20; x <= pokemon->pos.x + 20; x++) { + s32 xDiff = x - gDungeon->unkE250.minX; + s32 yDiff = y - gDungeon->unkE250.minY; + + if (xDiff < 0 || yDiff < 0) + continue; + if (xDiff >= 8 || yDiff >= 8) + continue; + if (x < gDungeon->unkE250.minX + 1 || y < gDungeon->unkE250.minY + 1) + continue; + if (x >= gDungeon->unkE250.maxX - 1 || y >= gDungeon->unkE250.maxY - 1) + continue; + + sub_80498A8(x, y); + } + } + + gDungeon->unk3A09 = TRUE; + tile->terrainType &= ~(TERRAIN_TYPE_IMPASSABLE_WALL | TERRAIN_TYPE_UNK_x1000); + sub_80498A8(pokemon->pos.x, pokemon->pos.y - 1); + sub_8049B8C(); + sub_8049ED4(); + sub_80429FC(&pos); + LogMessageByIdWithPopupCheckUser(pokemon, gUnknown_80FDDD0); // The closed corridor was opened! + sub_803E708(0x14, 0x3C); + } + else { + LogMessageByIdWithPopupCheckUser(pokemon, gUnknown_80FDDF0); // It can't be used here! + } +} + +static inline bool8 MonHasItem(PokemonStruct1 *mon) +{ + return (mon->heldItem.id != 0); +} + +static bool8 sub_805210C(u8 itemId) +{ + s32 i; + + for (i = 0; i < INVENTORY_SIZE; i++) { + if (ItemExists(&gTeamInventoryRef->teamItems[i])) { + if (gTeamInventoryRef->teamItems[i].id == itemId) + return TRUE; + } + } + + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + if (PokemonFlag1Struct2(&gRecruitedPokemonRef->pokemon2[i]) && ItemExists(&gRecruitedPokemonRef->pokemon2[i].itemSlot)) { + if (gRecruitedPokemonRef->pokemon2[i].itemSlot.id == itemId) + return TRUE; + } + } + + for (i = 0; i < NUM_MONSTERS; i++) { + if (PokemonFlag1(&gRecruitedPokemonRef->pokemon[i])) { + if (MonHasItem(&gRecruitedPokemonRef->pokemon[i]) && gRecruitedPokemonRef->pokemon[i].heldItem.id == itemId) + return TRUE; + } + } + + if (gTeamInventoryRef->teamStorage[itemId] != 0) + return TRUE; + + return FALSE; +} diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index e1df58dd4..daec78076 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -911,7 +911,7 @@ static void ReadDungeonTraps(DataSerializer *seri) if (trapID != 0xFF) { tile = GetTileMut(pos.x, pos.y); - entity = sub_8045684(trapID, &pos, unk1); + entity = SpawnTrap(trapID, &pos, unk1); if (entity) { tile->object = entity; entity->isVisible = isVisible; diff --git a/src/trap.c b/src/trap.c index 94483397e..9dd484d6a 100644 --- a/src/trap.c +++ b/src/trap.c @@ -138,7 +138,7 @@ bool8 LayTrap(DungeonPos *pos, u8 trapID, u8 param_3) tile->object->isVisible = TRUE; } else { - entity = sub_8045684(trapID,pos,param_3); + entity = SpawnTrap(trapID,pos,param_3); if (entity == NULL) _0807FD6E: return FALSE; From bf27d821fd1731dbde508886688e0e6fd42f83b7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 20 Nov 2024 09:10:13 +0100 Subject: [PATCH 27/30] tabs --- src/dungeon_generation.c | 2240 +++++++++++++++++++------------------- 1 file changed, 1120 insertions(+), 1120 deletions(-) diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index bdb438a9c..7f8698f12 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -409,7 +409,7 @@ void GenerateFloor(void) ResolveInvalidSpawns(); // Make sure multiple flags aren't set for one tile if (gDungeon->playerSpawn.x != -1 && gDungeon->playerSpawn.y != -1) { // This is for normal fixed rooms, we don't need to validate the stairs in this scenario - // Since it's fixed already + // Since it's fixed already if (GetFloorType() == FLOOR_TYPE_FIXED) break; if (gDungeon->stairsSpawn.x != -1 && gDungeon->stairsSpawn.y != -1 && StairsAlwaysReachable(gDungeon->stairsSpawn.x, gDungeon->stairsSpawn.y, FALSE)) @@ -567,7 +567,7 @@ static void GenerateOuterRingFloor(FloorProperties *floorProps) // Mark the inner tiles as rooms for (x = 1; x < gridSizeX - 1; x++) { for (y = 1; y < gridSizeY - 1; y++) { - grid[x][y].isRoom = innerIsRoom; + grid[x][y].isRoom = innerIsRoom; } } @@ -575,52 +575,52 @@ static void GenerateOuterRingFloor(FloorProperties *floorProps) for (y = 0; y < gridSizeY; y++) { for (x = 0; x < gridSizeX; x++) { - if (grid[x][y].isRoom) { - // Room - s32 curX, curY; + if (grid[x][y].isRoom) { + // Room + s32 curX, curY; s32 minX = listX[x] + 2; s32 minY = listY[y] + 2; - s32 rangeX = listX[x + 1] - listX[x] - 3; - s32 rangeY = listY[y + 1] - listY[y] - 3; + s32 rangeX = listX[x + 1] - listX[x] - 3; + s32 rangeY = listY[y + 1] - listY[y] - 3; - s32 roomSizeX = DungeonRandRange(5, rangeX); - s32 roomSizeY = DungeonRandRange(4, rangeY); - s32 startX = DungeonRandInt(rangeX - roomSizeX) + minX; - s32 startY = DungeonRandInt(rangeY - roomSizeY) + minY; - s32 endX = startX + roomSizeX; - s32 endY = startY + roomSizeY; + s32 roomSizeX = DungeonRandRange(5, rangeX); + s32 roomSizeY = DungeonRandRange(4, rangeY); + s32 startX = DungeonRandInt(rangeX - roomSizeX) + minX; + s32 startY = DungeonRandInt(rangeY - roomSizeY) + minY; + s32 endX = startX + roomSizeX; + s32 endY = startY + roomSizeY; - grid[x][y].start.x = startX; - grid[x][y].end.x = endX; - grid[x][y].start.y = startY; - grid[x][y].end.y = startY + roomSizeY; - for (curX = startX; curX < endX; curX++) { - for (curY = startY; curY < endY; curY++) { - SetTerrainNormal(GetTileMut(curX, curY)); + grid[x][y].start.x = startX; + grid[x][y].end.x = endX; + grid[x][y].start.y = startY; + grid[x][y].end.y = startY + roomSizeY; + for (curX = startX; curX < endX; curX++) { + for (curY = startY; curY < endY; curY++) { + SetTerrainNormal(GetTileMut(curX, curY)); GetTileMut(curX, curY)->room = currRoomIndex; - } - } + } + } - currRoomIndex++; - } - else - { - // Hallway Anchor - s32 minX = listX[x] + 1; + currRoomIndex++; + } + else + { + // Hallway Anchor + s32 minX = listX[x] + 1; s32 minY = listY[y] + 1; s32 rangeX = listX[x + 1] - listX[x] - 3; s32 rangeY = listY[y + 1] - listY[y] - 3; - s32 startX = DungeonRandRange(minX, minX + rangeX); - s32 startY = DungeonRandRange(minY, minY + rangeY); + s32 startX = DungeonRandRange(minX, minX + rangeX); + s32 startY = DungeonRandRange(minY, minY + rangeY); - grid[x][y].start.x = startX; - grid[x][y].end.x = startX + 1; - grid[x][y].start.y = startY; - grid[x][y].end.y = startY + 1; + grid[x][y].start.x = startX; + grid[x][y].end.x = startX + 1; + grid[x][y].start.y = startY; + grid[x][y].end.y = startY + 1; - SetTerrainNormal(GetTileMut(startX, startY)); - GetTileMut(startX, startY)->room = CORRIDOR_ROOM; - } + SetTerrainNormal(GetTileMut(startX, startY)); + GetTileMut(startX, startY)->room = CORRIDOR_ROOM; + } } } @@ -715,7 +715,7 @@ static void GenerateCrossroadsFloor(FloorProperties *floorProps) // Mark the inner cells as hallways for (x = 1; x < gridSizeX - 1; x++) { for (y = 1; y < gridSizeY - 1; y++) { - grid[x][y].isRoom = innerIsRoom; + grid[x][y].isRoom = innerIsRoom; } } @@ -728,54 +728,54 @@ static void GenerateCrossroadsFloor(FloorProperties *floorProps) currRoomIndex = 0; for (y = 0; y < gridSizeY; y++) { for (x = 0; x < gridSizeX; x++) { - if (grid[x][y].isInvalid) + if (grid[x][y].isInvalid) continue; - if (grid[x][y].isRoom) { - // Room + if (grid[x][y].isRoom) { + // Room s32 curX, curY; s32 minX = listX[x] + 2; s32 minY = listY[y] + 2; - s32 rangeX = listX[x + 1] - listX[x] - 3; - s32 rangeY = listY[y + 1] - listY[y] - 3; + s32 rangeX = listX[x + 1] - listX[x] - 3; + s32 rangeY = listY[y + 1] - listY[y] - 3; - s32 roomSizeX = DungeonRandRange(5, rangeX); - s32 roomSizeY = DungeonRandRange(4, rangeY); - s32 startX = DungeonRandInt(rangeX - roomSizeX) + minX; - s32 startY = DungeonRandInt(rangeY - roomSizeY) + minY; - s32 endX = startX + roomSizeX; - s32 endY = startY + roomSizeY; + s32 roomSizeX = DungeonRandRange(5, rangeX); + s32 roomSizeY = DungeonRandRange(4, rangeY); + s32 startX = DungeonRandInt(rangeX - roomSizeX) + minX; + s32 startY = DungeonRandInt(rangeY - roomSizeY) + minY; + s32 endX = startX + roomSizeX; + s32 endY = startY + roomSizeY; - grid[x][y].start.x = startX; + grid[x][y].start.x = startX; grid[x][y].end.x = endX; - grid[x][y].start.y = startY; - grid[x][y].end.y = endY; - for (curX = startX; curX < endX; curX++) { - for (curY = startY; curY < endY; curY++) { + grid[x][y].start.y = startY; + grid[x][y].end.y = endY; + for (curX = startX; curX < endX; curX++) { + for (curY = startY; curY < endY; curY++) { SetTerrainNormal(GetTileMut(curX, curY)); GetTileMut(curX, curY)->room = currRoomIndex; - } - } + } + } - currRoomIndex += 1; - } - else { - // Hallway Anchor + currRoomIndex += 1; + } + else { + // Hallway Anchor s32 minX = listX[x] + 1; s32 minY = listY[y] + 1; s32 rangeX = listX[x + 1] - listX[x] - 3; s32 rangeY = listY[y + 1] - listY[y] - 3; - s32 startX = DungeonRandRange(minX, minX + rangeX); - s32 startY = DungeonRandRange(minY, minY + rangeY); + s32 startX = DungeonRandRange(minX, minX + rangeX); + s32 startY = DungeonRandRange(minY, minY + rangeY); - grid[x][y].start.x = startX; + grid[x][y].start.x = startX; grid[x][y].end.x = startX + 1; - grid[x][y].start.y = startY; - grid[x][y].end.y = startY + 1; + grid[x][y].start.y = startY; + grid[x][y].end.y = startY + 1; - SetTerrainNormal(GetTileMut(startX, startY)); - GetTileMut(startX, startY)->room = CORRIDOR_ROOM; - } + SetTerrainNormal(GetTileMut(startX, startY)); + GetTileMut(startX, startY)->room = CORRIDOR_ROOM; + } } } @@ -1267,27 +1267,27 @@ static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_ // If invalid, rotate counter-clockwise until one works for (j = 0; j < 3; j++) { - if (direction == DIRECTION_SOUTH && y >= gridSizeY - 1) { - direction = DIRECTION_EAST; - } + if (direction == DIRECTION_SOUTH && y >= gridSizeY - 1) { + direction = DIRECTION_EAST; + } - if (direction == DIRECTION_EAST && x >= gridSizeX - 1) { - direction = DIRECTION_NORTH; - } + if (direction == DIRECTION_EAST && x >= gridSizeX - 1) { + direction = DIRECTION_NORTH; + } - if (direction == DIRECTION_NORTH && y <= 0) { - direction = DIRECTION_WEST; - } + if (direction == DIRECTION_NORTH && y <= 0) { + direction = DIRECTION_WEST; + } - if (direction == DIRECTION_WEST && x <= 0) { - direction = DIRECTION_SOUTH; - } + if (direction == DIRECTION_WEST && x <= 0) { + direction = DIRECTION_SOUTH; + } } roomId = GetTile(currX, currY)->room; // Walk in the random direction until out of the room while (1) { - if (roomId != GetTile(currX, currY)->room) + if (roomId != GetTile(currX, currY)->room) break; // gAdjacentTileOffsets gives us the proper (x,y) offset to move one tile in the given direction. currX += gAdjacentTileOffsets[direction].x; @@ -1296,7 +1296,7 @@ static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_ // Keep walking until an obstacle is encountered while (1) { - if (GetTerrainType(GetTile(currX, currY)) != TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX, currY)) != TERRAIN_TYPE_NORMAL) break; currX += gAdjacentTileOffsets[direction].x; @@ -1310,14 +1310,14 @@ static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_ // Check that the current tile is at least 2 away from the map border invalid = FALSE; for (xLoop = currX - 2; xLoop <= currX + 2; xLoop++) { - for (yLoop = currY - 2; yLoop <= currY + 2; yLoop++) { - if (xLoop < 0 || xLoop >= DUNGEON_MAX_SIZE_X || yLoop < 0 || yLoop >= DUNGEON_MAX_SIZE_Y) { - invalid = TRUE; - break; - } - } + for (yLoop = currY - 2; yLoop <= currY + 2; yLoop++) { + if (xLoop < 0 || xLoop >= DUNGEON_MAX_SIZE_X || yLoop < 0 || yLoop >= DUNGEON_MAX_SIZE_Y) { + invalid = TRUE; + break; + } + } - if (invalid) break; + if (invalid) break; } if (invalid) continue; @@ -1339,93 +1339,93 @@ static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_ while (TRUE) { s32 checkX, checkY, checkX2, checkY2; bool8 willNotMakeSquare; - // Check for stopping conditions: - // - Out of bounds or on the 1-tile border of impassable walls - // - Reached an open tile - // - Reached an impassable wall - // - Would result in carving out a 2x2 square (not a hallway at that point) + // Check for stopping conditions: + // - Out of bounds or on the 1-tile border of impassable walls + // - Reached an open tile + // - Reached an impassable wall + // - Would result in carving out a 2x2 square (not a hallway at that point) - if (currX <= 1 || currY <= 1 || currX >= DUNGEON_MAX_SIZE_X - 1 || currY >= DUNGEON_MAX_SIZE_Y - 1) + if (currX <= 1 || currY <= 1 || currX >= DUNGEON_MAX_SIZE_X - 1 || currY >= DUNGEON_MAX_SIZE_Y - 1) break; - if (GetTerrainType(GetTile(currX, currY)) == TERRAIN_TYPE_NORMAL) + if (GetTerrainType(GetTile(currX, currY)) == TERRAIN_TYPE_NORMAL) break; - if (GetTile(currX, currY)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) + if (GetTile(currX, currY)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) break; willNotMakeSquare = TRUE; - // Check Bottom to Right - if ((GetTerrainType(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && + // Check Bottom to Right + if ((GetTerrainType(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && (GetTerrainType(GetTile(currX + 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrainType(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) - { - willNotMakeSquare = FALSE; - } - - // Check Top to Right - if ((GetTerrainType(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && - (GetTerrainType(GetTile(currX + 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrainType(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) + (GetTerrainType(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) { - willNotMakeSquare = FALSE; - } + willNotMakeSquare = FALSE; + } - // Check Bottom to Left - if ((GetTerrainType(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && - (GetTerrainType(GetTile(currX - 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrainType(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) + // Check Top to Right + if ((GetTerrainType(GetTile(currX + 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX + 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) { - willNotMakeSquare = FALSE; - } + willNotMakeSquare = FALSE; + } - // Check Top to Left - if ((GetTerrainType(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && - (GetTerrainType(GetTile(currX - 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && - (GetTerrainType(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) - { - willNotMakeSquare = FALSE; - } + // Check Bottom to Left + if ((GetTerrainType(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX - 1, currY + 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX, currY + 1)) == TERRAIN_TYPE_NORMAL)) + { + willNotMakeSquare = FALSE; + } - // If TRUE, make the tile open, it will not produce a 2x2 opening - // If FALSE, it will abort from neighbor checks so we don't break here - if (willNotMakeSquare) { + // Check Top to Left + if ((GetTerrainType(GetTile(currX - 1, currY)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX - 1, currY - 1)) == TERRAIN_TYPE_NORMAL) && + (GetTerrainType(GetTile(currX, currY - 1)) == TERRAIN_TYPE_NORMAL)) + { + willNotMakeSquare = FALSE; + } + + // If TRUE, make the tile open, it will not produce a 2x2 opening + // If FALSE, it will abort from neighbor checks so we don't break here + if (willNotMakeSquare) { SetTerrainNormal(GetTileMut(currX, currY)); - } + } - // Make sure the direction 90 degrees counterclockwise isn't an open tile - checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; - checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; - if (GetTerrainType(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) + // Make sure the direction 90 degrees counterclockwise isn't an open tile + checkX = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].x; + checkY = gAdjacentTileOffsets[(direction + 2) & DIRECTION_MASK_CARDINAL].y; + if (GetTerrainType(GetTile(currX + checkX, currY + checkY)) == TERRAIN_TYPE_NORMAL) break; - // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile - checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; - checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; - if (GetTerrainType(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) + // Do the same for 90 degrees clockwise (or 270 counterclockwise) and make sure it's not an open tile + checkX2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].x; + checkY2 = gAdjacentTileOffsets[(direction - 2) & DIRECTION_MASK_CARDINAL].y; + if (GetTerrainType(GetTile(currX + checkX2, currY + checkY2)) == TERRAIN_TYPE_NORMAL) break; - j--; - if (j == 0) { - j = DungeonRandInt(3) + 3; + j--; + if (j == 0) { + j = DungeonRandInt(3) + 3; - // Turn left or right with an equal chance - if (DungeonRandInt(100) < 50) { - direction += 2; - } + // Turn left or right with an equal chance + if (DungeonRandInt(100) < 50) { + direction += 2; + } else { - direction -= 2; - } + direction -= 2; + } - // If we'd step into an invalid grid cell, stop - // (We don't always utilize the entire floor space) - direction &= DIRECTION_MASK_CARDINAL; - if (currX >= 32 && sFloorSize == FLOOR_SIZE_SMALL && direction == DIRECTION_EAST) break; - if (currX >= 48 && sFloorSize == FLOOR_SIZE_MEDIUM && direction == DIRECTION_EAST) break; - } + // If we'd step into an invalid grid cell, stop + // (We don't always utilize the entire floor space) + direction &= DIRECTION_MASK_CARDINAL; + if (currX >= 32 && sFloorSize == FLOOR_SIZE_SMALL && direction == DIRECTION_EAST) break; + if (currX >= 48 && sFloorSize == FLOOR_SIZE_MEDIUM && direction == DIRECTION_EAST) break; + } - // Move in the current direction - currX += gAdjacentTileOffsets[direction].x; - currY += gAdjacentTileOffsets[direction].y; + // Move in the current direction + currX += gAdjacentTileOffsets[direction].x; + currY += gAdjacentTileOffsets[direction].y; } } } @@ -1548,29 +1548,29 @@ static void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 sNumRooms = 0; for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { - if (grid[x][y].isInvalid) + if (grid[x][y].isInvalid) continue; - // There are too many rooms, remove - if (sNumRooms >= MAX_ROOM_COUNT) { - grid[x][y].isRoom = FALSE; - } + // There are too many rooms, remove + if (sNumRooms >= MAX_ROOM_COUNT) { + grid[x][y].isRoom = FALSE; + } - // Using the randomly shuffled bits, create or remove the room - if (randomRoomBits[i]) { - grid[x][y].isRoom = TRUE; - sNumRooms++; + // Using the randomly shuffled bits, create or remove the room + if (randomRoomBits[i]) { + grid[x][y].isRoom = TRUE; + sNumRooms++; - // Don't make a room at (x_mid, 1) - if (gridSizeX % 2 != 0 && x == (gridSizeX - 1) / 2 && y == 1 ) { - grid[x][y].isRoom = FALSE; - } - } - else { - grid[x][y].isRoom = FALSE; - } + // Don't make a room at (x_mid, 1) + if (gridSizeX % 2 != 0 && x == (gridSizeX - 1) / 2 && y == 1 ) { + grid[x][y].isRoom = FALSE; + } + } + else { + grid[x][y].isRoom = FALSE; + } - i++; + i++; } } @@ -1581,17 +1581,17 @@ static void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 for (attempts = 0; attempts < 200; attempts++) { bool8 enoughRooms = FALSE; for (x = 0; x < gridSizeX; x++) { - for (y = 0; y < gridSizeY; y++) { - if (grid[x][y].isInvalid) + for (y = 0; y < gridSizeY; y++) { + if (grid[x][y].isInvalid) continue; - if (DungeonRandInt(100) < 60) { - grid[x][y].isRoom = TRUE; - enoughRooms = TRUE; + if (DungeonRandInt(100) < 60) { + grid[x][y].isRoom = TRUE; + enoughRooms = TRUE; // This goto is needed to match, it's used to break from two nested loops. goto LOOP_BREAK; - } - } + } + } } LOOP_BREAK: if (enoughRooms) @@ -1616,12 +1616,12 @@ static void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_ for (x = 0; x < gridSizeX; x++) { s32 minX = listX[x] + 2; s32 minY = listY[y] + 2; - s32 rangeX = listX[x + 1] - listX[x] - 4; - s32 rangeY = listY[y + 1] - listY[y] - 3; + s32 rangeX = listX[x + 1] - listX[x] - 4; + s32 rangeY = listY[y + 1] - listY[y] - 3; - if (grid[x][y].isInvalid) continue; + if (grid[x][y].isInvalid) continue; - if (grid[x][y].isRoom) { + if (grid[x][y].isRoom) { // This cell is a room! s32 roomSizeX, roomSizeY; s32 startX, endX; @@ -1632,75 +1632,75 @@ static void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_ roomSizeX = DungeonRandRange(5, rangeX); roomSizeY = DungeonRandRange(4, rangeY); - // Force small rooms to have odd-numbered dimensions (?) - if ((roomSizeX | 1) < rangeX) { - roomSizeX |= 1; - } + // Force small rooms to have odd-numbered dimensions (?) + if ((roomSizeX | 1) < rangeX) { + roomSizeX |= 1; + } - if ((roomSizeY | 1) < rangeY) { - roomSizeY |= 1; - } + if ((roomSizeY | 1) < rangeY) { + roomSizeY |= 1; + } - // Aspect ratio 2/3 < x/y < 3/2 - if (roomSizeX > (roomSizeY * 3) / 2) { - roomSizeX = (roomSizeY * 3) / 2; - } + // Aspect ratio 2/3 < x/y < 3/2 + if (roomSizeX > (roomSizeY * 3) / 2) { + roomSizeX = (roomSizeY * 3) / 2; + } - if (roomSizeY > (roomSizeX * 3) / 2) { - roomSizeY = (roomSizeX * 3) / 2; - } + if (roomSizeY > (roomSizeX * 3) / 2) { + roomSizeY = (roomSizeX * 3) / 2; + } startX = DungeonRandInt(rangeX - roomSizeX) + minX; startY = DungeonRandInt(rangeY - roomSizeY) + minY; endX = startX + roomSizeX; endY = startY + roomSizeY; - // Create the room! - grid[x][y].start.x = startX; + // Create the room! + grid[x][y].start.x = startX; grid[x][y].end.x = endX; - grid[x][y].start.y = startY; - grid[x][y].end.y = endY; + grid[x][y].start.y = startY; + grid[x][y].end.y = endY; - for (roomX = startX; roomX < endX; roomX++) { - for (roomY = startY; roomY < endY; roomY++) { + for (roomX = startX; roomX < endX; roomX++) { + for (roomY = startY; roomY < endY; roomY++) { SetTerrainNormal(GetTileMut(roomX, roomY)); GetTileMut(roomX, roomY)->room = roomNumber; - } - } + } + } flagImperfect = TRUE; - // Randomly flag the room for a secondary structure + // Randomly flag the room for a secondary structure flagSecondary = DungeonRandInt(100) < GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE; - if (sSecondaryStructuresBudget == 0) { - flagSecondary = FALSE; - } + if (sSecondaryStructuresBudget == 0) { + flagSecondary = FALSE; + } - // Flag for imperfections if needed + // Flag for imperfections if needed if (!(roomFlags & ROOM_FLAG_ALLOW_IMPERFECTIONS)) { flagImperfect = FALSE; } - if (flagImperfect && flagSecondary) { - // If a room gets both, pick one at random - if (DungeonRandInt(100) < 50) { - flagImperfect = FALSE; - } - else { - flagSecondary = FALSE; - } - } + if (flagImperfect && flagSecondary) { + // If a room gets both, pick one at random + if (DungeonRandInt(100) < 50) { + flagImperfect = FALSE; + } + else { + flagSecondary = FALSE; + } + } - if (flagImperfect) { - grid[x][y].flagImperfect = TRUE; - } + if (flagImperfect) { + grid[x][y].flagImperfect = TRUE; + } - if (flagSecondary) { - grid[x][y].flagSecondaryStructure = TRUE; - } + if (flagSecondary) { + grid[x][y].flagSecondaryStructure = TRUE; + } - roomNumber++; - } - else { + roomNumber++; + } + else { // This cell is not a room, create a 1x1 hallway anchor s32 pt_x, pt_y; s32 unk_x1 = 2; @@ -1708,34 +1708,34 @@ static void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_ s32 unk_y1 = 2; s32 unk_y2 = 4; - if (x == 0) { - unk_x1 = 1; - } - if (y == 0) { - unk_y1 = 1; - } + if (x == 0) { + unk_x1 = 1; + } + if (y == 0) { + unk_y1 = 1; + } if (x == gridSizeX - 1) { - unk_x2 = 2; - } - if (y == gridSizeY - 1) { - unk_y2 = 2; - } + unk_x2 = 2; + } + if (y == gridSizeY - 1) { + unk_y2 = 2; + } pt_x = DungeonRandRange(minX + unk_x1, minX + rangeX - unk_x2); pt_y = DungeonRandRange(minY + unk_y1, minY + rangeY - unk_y2); - grid[x][y].start.x = pt_x; + grid[x][y].start.x = pt_x; grid[x][y].end.x = pt_x + 1; - grid[x][y].start.y = pt_y; - grid[x][y].end.y = pt_y + 1; + grid[x][y].start.y = pt_y; + grid[x][y].end.y = pt_y + 1; - // Flag the tile as open to serve as a hallway anchor - SetTerrainNormal(GetTileMut(pt_x, pt_y)); + // Flag the tile as open to serve as a hallway anchor + SetTerrainNormal(GetTileMut(pt_x, pt_y)); - // Set the room index to 0xFE for anchor - GetTileMut(pt_x, pt_y)->room = ROOM_0xFE; - } + // Set the room index to 0xFE for anchor + GetTileMut(pt_x, pt_y)->room = ROOM_0xFE; + } } } } @@ -1760,16 +1760,16 @@ static void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID for (y = 0; y < gridSizeY; y++) { for (x = 0; x < gridSizeX; x++) { // To have a secondary structure a room must be: - // - valid - // - not a monster house, merged, or have imperfections - // - be a room - // - be flagged for a secondary structure - if (!grid[x][y].isInvalid && - !grid[x][y].isMonsterHouse && - !grid[x][y].isMerged && - grid[x][y].isRoom && + // - valid + // - not a monster house, merged, or have imperfections + // - be a room + // - be flagged for a secondary structure + if (!grid[x][y].isInvalid && + !grid[x][y].isMonsterHouse && + !grid[x][y].isMerged && + grid[x][y].isRoom && !grid[x][y].flagImperfect && - grid[x][y].flagSecondaryStructure) + grid[x][y].flagSecondaryStructure) { GenerateSecondaryStructure(&grid[x][y]); } @@ -1826,42 +1826,42 @@ static void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_C s32 newDirection = DungeonRandInt(NUM_CARDINAL_DIRECTIONS); if (test < NUM_CARDINAL_DIRECTIONS) { - // Shuffle to a new cardinalDirection - cardinalDirection = newDirection; + // Shuffle to a new cardinalDirection + cardinalDirection = newDirection; } // Make sure our cardinalDirection isn't going into a border // If so, rotate counterclockwise while (1) { bool8 notOk = FALSE; - switch (cardinalDirection & CARDINAL_DIRECTION_MASK) { - case CARDINAL_DIR_RIGHT: - if (x < gridSizeX - 1) + switch (cardinalDirection & CARDINAL_DIRECTION_MASK) { + case CARDINAL_DIR_RIGHT: + if (x < gridSizeX - 1) notOk = TRUE; else cardinalDirection++; - break; - case CARDINAL_DIR_UP: - if (y > 0) + break; + case CARDINAL_DIR_UP: + if (y > 0) notOk = TRUE; else cardinalDirection++; - break; - case CARDINAL_DIR_LEFT: - if (x > 0) + break; + case CARDINAL_DIR_LEFT: + if (x > 0) notOk = TRUE; else cardinalDirection++; - break; - case CARDINAL_DIR_DOWN: - if (y < gridSizeY - 1) + break; + case CARDINAL_DIR_DOWN: + if (y < gridSizeY - 1) notOk = TRUE; else cardinalDirection++; - break; - } + break; + } - if (notOk) + if (notOk) break; } @@ -2043,38 +2043,38 @@ static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_C // Validate and copy grid connections over to a work array for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { - if (grid[x][y].isInvalid) { + if (grid[x][y].isInvalid) { // For invalid cells, assign no connections - grid[x][y].shouldConnectToTop = FALSE; - grid[x][y].shouldConnectToBottom = FALSE; - grid[x][y].shouldConnectToLeft = FALSE; - grid[x][y].shouldConnectToRight = FALSE; - } - else { - // For valid cells, remove cell connections beyond the grid bounds - if (x <= 0) { - grid[x][y].connectedToLeft = FALSE; - } + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y].shouldConnectToLeft = FALSE; + grid[x][y].shouldConnectToRight = FALSE; + } + else { + // For valid cells, remove cell connections beyond the grid bounds + if (x <= 0) { + grid[x][y].connectedToLeft = FALSE; + } - if (y <= 0) { - grid[x][y].connectedToTop = FALSE; - } + if (y <= 0) { + grid[x][y].connectedToTop = FALSE; + } - if (x >= gridSizeX - 1) { - grid[x][y].connectedToRight = FALSE; - } + if (x >= gridSizeX - 1) { + grid[x][y].connectedToRight = FALSE; + } - if (y >= gridSizeY - 1) { - grid[x][y].connectedToBottom = FALSE; - } + if (y >= gridSizeY - 1) { + grid[x][y].connectedToBottom = FALSE; + } - // Assign the connections - grid[x][y].shouldConnectToTop = grid[x][y].connectedToTop; - grid[x][y].shouldConnectToBottom = grid[x][y].connectedToBottom; - grid[x][y].shouldConnectToLeft = grid[x][y].connectedToLeft; - grid[x][y].shouldConnectToRight = grid[x][y].connectedToRight; - } + // Assign the connections + grid[x][y].shouldConnectToTop = grid[x][y].connectedToTop; + grid[x][y].shouldConnectToBottom = grid[x][y].connectedToBottom; + grid[x][y].shouldConnectToLeft = grid[x][y].connectedToLeft; + grid[x][y].shouldConnectToRight = grid[x][y].connectedToRight; + } } } @@ -2082,121 +2082,121 @@ static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_C for (y = 0; y < gridSizeY; y++) { s32 pt_x, pt_y, pt2_x, pt2_y; - if (grid[x][y].isInvalid) + if (grid[x][y].isInvalid) continue; - if (grid[x][y].isRoom) { - // Room, pick a random point in the interior of the room - pt_x = DungeonRandRange(grid[x][y].start.x + 1, grid[x][y].end.x - 1); - pt_y = DungeonRandRange(grid[x][y].start.y + 1, grid[x][y].end.y - 1); - } - else { + if (grid[x][y].isRoom) { + // Room, pick a random point in the interior of the room + pt_x = DungeonRandRange(grid[x][y].start.x + 1, grid[x][y].end.x - 1); + pt_y = DungeonRandRange(grid[x][y].start.y + 1, grid[x][y].end.y - 1); + } + else { // Hallway anchor, point is the 1x1 we've placed - pt_x = grid[x][y].start.x; - pt_y = grid[x][y].start.y; - } + pt_x = grid[x][y].start.x; + pt_y = grid[x][y].start.y; + } - if (grid[x][y].shouldConnectToTop) { - // Connect to the cell above - if (!grid[x][y - 1].isInvalid) { - if (grid[x][y - 1].isRoom) { - // Room, pick a random interior x coordinate - pt2_x = DungeonRandRange(grid[x][y - 1].start.x + 1, grid[x][y - 1].end.x - 1); - } - else { - // Anchor, use the central x coordinate - pt2_x = grid[x][y - 1].start.x; - } - - // Create the hallway - CreateHallway(pt_x, grid[x][y].start.y, pt2_x, grid[x][y - 1].end.y - 1, TRUE, listX[x], listY[y]); - } - - // Mark the connection and unassign it so we don't try to draw - // a second connection from the other way - - grid[x][y].shouldConnectToTop = FALSE; - grid[x][y - 1].shouldConnectToBottom = FALSE; - grid[x][y].isConnected = TRUE; - grid[x][y - 1].isConnected = TRUE; - } - - if (grid[x][y].shouldConnectToBottom) { - // Connect to the cell below - if (!grid[x][y + 1].isInvalid) { - if (grid[x][y + 1].isRoom) { + if (grid[x][y].shouldConnectToTop) { + // Connect to the cell above + if (!grid[x][y - 1].isInvalid) { + if (grid[x][y - 1].isRoom) { // Room, pick a random interior x coordinate - pt2_x = DungeonRandRange(grid[x][y + 1].start.x + 1, grid[x][y + 1].end.x - 1); - } - else { - // Anchor, use the central x coordinate - pt2_x = grid[x][y + 1].start.x; - } + pt2_x = DungeonRandRange(grid[x][y - 1].start.x + 1, grid[x][y - 1].end.x - 1); + } + else { + // Anchor, use the central x coordinate + pt2_x = grid[x][y - 1].start.x; + } - // Create the hallway - CreateHallway(pt_x, grid[x][y].end.y - 1, pt2_x, grid[x][y + 1].start.y, TRUE, listX[x], listY[y + 1] - 1); - } + // Create the hallway + CreateHallway(pt_x, grid[x][y].start.y, pt2_x, grid[x][y - 1].end.y - 1, TRUE, listX[x], listY[y]); + } - // Mark the connection and unassign it so we don't try to draw - // a second connection from the other way + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way - grid[x][y].shouldConnectToBottom = FALSE; - grid[x][y + 1].shouldConnectToTop = FALSE; - grid[x][y].isConnected = TRUE; - grid[x][y + 1].isConnected = TRUE; - } + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y - 1].shouldConnectToBottom = FALSE; + grid[x][y].isConnected = TRUE; + grid[x][y - 1].isConnected = TRUE; + } - if (grid[x][y].shouldConnectToLeft) { - // Connect to the cell on the left - if (!grid[x - 1][y].isInvalid) { - if (grid[x - 1][y].isRoom) { + if (grid[x][y].shouldConnectToBottom) { + // Connect to the cell below + if (!grid[x][y + 1].isInvalid) { + if (grid[x][y + 1].isRoom) { + // Room, pick a random interior x coordinate + pt2_x = DungeonRandRange(grid[x][y + 1].start.x + 1, grid[x][y + 1].end.x - 1); + } + else { + // Anchor, use the central x coordinate + pt2_x = grid[x][y + 1].start.x; + } + + // Create the hallway + CreateHallway(pt_x, grid[x][y].end.y - 1, pt2_x, grid[x][y + 1].start.y, TRUE, listX[x], listY[y + 1] - 1); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y + 1].shouldConnectToTop = FALSE; + grid[x][y].isConnected = TRUE; + grid[x][y + 1].isConnected = TRUE; + } + + if (grid[x][y].shouldConnectToLeft) { + // Connect to the cell on the left + if (!grid[x - 1][y].isInvalid) { + if (grid[x - 1][y].isRoom) { // Room, pick a random interior y coordinate - pt2_y = DungeonRandRange(grid[x - 1][y].start.y + 1, grid[x - 1][y].end.y - 1); - } - else { - // Anchor, use the central y coordinate - pt2_y = grid[x - 1][y].start.y; - } + pt2_y = DungeonRandRange(grid[x - 1][y].start.y + 1, grid[x - 1][y].end.y - 1); + } + else { + // Anchor, use the central y coordinate + pt2_y = grid[x - 1][y].start.y; + } - // Create the hallway - // Using (grid[x-1][y].start.x - 1) is a bug, it should be (grid[x-1][y].end.x - 1) - // But CreateHallway has safety checks making the end result the same anyways. - CreateHallway(grid[x][y].start.x, pt_y, grid[x - 1][y].start.x - 1, pt2_y, FALSE, listX[x], listY[y]); - } + // Create the hallway + // Using (grid[x-1][y].start.x - 1) is a bug, it should be (grid[x-1][y].end.x - 1) + // But CreateHallway has safety checks making the end result the same anyways. + CreateHallway(grid[x][y].start.x, pt_y, grid[x - 1][y].start.x - 1, pt2_y, FALSE, listX[x], listY[y]); + } - // Mark the connection and unassign it so we don't try to draw - // a second connection from the other way + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way - grid[x][y].shouldConnectToLeft = FALSE; - grid[x - 1][y].shouldConnectToRight = FALSE; - grid[x][y].isConnected = TRUE; - grid[x - 1][y].isConnected = TRUE; - } + grid[x][y].shouldConnectToLeft = FALSE; + grid[x - 1][y].shouldConnectToRight = FALSE; + grid[x][y].isConnected = TRUE; + grid[x - 1][y].isConnected = TRUE; + } - if (grid[x][y].shouldConnectToRight) { - // Connect to the cell on the right - if (!grid[x + 1][y].isInvalid) { - if (grid[x + 1][y].isRoom) { + if (grid[x][y].shouldConnectToRight) { + // Connect to the cell on the right + if (!grid[x + 1][y].isInvalid) { + if (grid[x + 1][y].isRoom) { // Room, pick a random interior y coordinate - pt2_y = DungeonRandRange(grid[x + 1][y].start.y + 1, grid[x + 1][y].end.y - 1); - } - else { - // Anchor, use the central y coordinate - pt2_y = grid[x + 1][y].start.y; - } + pt2_y = DungeonRandRange(grid[x + 1][y].start.y + 1, grid[x + 1][y].end.y - 1); + } + else { + // Anchor, use the central y coordinate + pt2_y = grid[x + 1][y].start.y; + } - // Create the hallway - CreateHallway(grid[x][y].end.x - 1, pt_y, grid[x + 1][y].start.x, pt2_y, FALSE, listX[x + 1] - 1, listY[y]); - } + // Create the hallway + CreateHallway(grid[x][y].end.x - 1, pt_y, grid[x + 1][y].start.x, pt2_y, FALSE, listX[x + 1] - 1, listY[y]); + } - // Mark the connection and unassign it so we don't try to draw - // a second connection from the other way + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way - grid[x][y].shouldConnectToRight = FALSE; - grid[x + 1][y].shouldConnectToLeft = FALSE; - grid[x][y].isConnected = TRUE; - grid[x + 1][y].isConnected = TRUE; - } + grid[x][y].shouldConnectToRight = FALSE; + grid[x + 1][y].shouldConnectToLeft = FALSE; + grid[x][y].isConnected = TRUE; + grid[x + 1][y].isConnected = TRUE; + } } } @@ -2208,26 +2208,26 @@ static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_C // If we do, we can try to merge some! for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { - s32 chance = DungeonRandInt(100); + s32 chance = DungeonRandInt(100); - // Conditions for merging a room: - // - rolls for merge chance - // - valid - // - connected to another room - // - not already merged - // - not have a secondary structure - // - is a room, not an anchor - if (chance < GENERATION_CONSTANT_MERGE_ROOMS_CHANCE && - !grid[x][y].isInvalid && - grid[x][y].isConnected && - !grid[x][y].isMerged && - !grid[x][y].hasSecondaryStructure && - grid[x][y].isRoom) + // Conditions for merging a room: + // - rolls for merge chance + // - valid + // - connected to another room + // - not already merged + // - not have a secondary structure + // - is a room, not an anchor + if (chance < GENERATION_CONSTANT_MERGE_ROOMS_CHANCE && + !grid[x][y].isInvalid && + grid[x][y].isConnected && + !grid[x][y].isMerged && + !grid[x][y].hasSecondaryStructure && + grid[x][y].isRoom) { - s32 chanceTwo = DungeonRandInt(4); + s32 chanceTwo = DungeonRandInt(4); - // Verify the same for the target room - switch (chanceTwo) { + // Verify the same for the target room + switch (chanceTwo) { case 0: if (x > 0 && grid[x - 1][y].isConnected && @@ -2392,8 +2392,8 @@ static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_C grid[x][y + 1].hasBeenMerged = TRUE; } break; - } - } + } + } } } } @@ -2419,55 +2419,55 @@ static void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_C for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { s32 counter, length; - // To have imperfections a room must: - // - be valid - // - not have been merged - // - be a room - // - be connected - // - not have a secondary structure - // - not be a maze room - // - be flagged to be made imperfect - if (grid[x][y].isInvalid) + // To have imperfections a room must: + // - be valid + // - not have been merged + // - be a room + // - be connected + // - not have a secondary structure + // - not be a maze room + // - be flagged to be made imperfect + if (grid[x][y].isInvalid) continue; if (grid[x][y].hasBeenMerged) continue; - if (grid[x][y].isMerged) + if (grid[x][y].isMerged) continue; - if (!grid[x][y].isConnected) + if (!grid[x][y].isConnected) continue; - if (!grid[x][y].isRoom) + if (!grid[x][y].isRoom) continue; - if (grid[x][y].hasSecondaryStructure) + if (grid[x][y].hasSecondaryStructure) continue; - if (grid[x][y].isMazeRoom) + if (grid[x][y].isMazeRoom) continue; - if (!grid[x][y].flagImperfect) + if (!grid[x][y].flagImperfect) continue; - // Roll for imperfections - // By default, is a 40% chance that the room will still have imperfections - if (DungeonRandInt(100) < GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE) + // Roll for imperfections + // By default, is a 40% chance that the room will still have imperfections + if (DungeonRandInt(100) < GENERATION_CONSTANT_NO_IMPERFECTIONS_CHANCE) continue; - length = grid[x][y].end.x - grid[x][y].start.x + (grid[x][y].end.y - grid[x][y].start.y); - length /= 4; - if (length == 0) + length = grid[x][y].end.x - grid[x][y].start.x + (grid[x][y].end.y - grid[x][y].start.y); + length /= 4; + if (length == 0) length = 1; - // Shrink the room from its corners either in the x or y direction - // Repeat the number of times equal to the average room length - for (counter = 0; counter < length; counter++) { + // Shrink the room from its corners either in the x or y direction + // Repeat the number of times equal to the average room length + for (counter = 0; counter < length; counter++) { s32 i, v; - for (i = 0; i < 2; i++) { - // Start from one of four corners - // i == 0 => fill in walls counterclockwise - // i == 1 => fill in walls clockwise - s32 pt_x, pt_y; - s32 moveX, moveY; - s32 startingCorner = DungeonRandInt(4); + for (i = 0; i < 2; i++) { + // Start from one of four corners + // i == 0 => fill in walls counterclockwise + // i == 1 => fill in walls clockwise + s32 pt_x, pt_y; + s32 moveX, moveY; + s32 startingCorner = DungeonRandInt(4); - switch (startingCorner) { - // Top-left corner + switch (startingCorner) { + // Top-left corner case 0: default: pt_x = grid[x][y].start.x; @@ -2522,34 +2522,34 @@ static void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_C moveY = 0; } break; - } + } - // Search up to 10 tiles for a new tile to replace - // from the selected starting corner and direction - for (v = 0; v < 10; v++) { - // Make sure we're still in bounds + // Search up to 10 tiles for a new tile to replace + // from the selected starting corner and direction + for (v = 0; v < 10; v++) { + // Make sure we're still in bounds if (pt_x < grid[x][y].start.x || pt_x >= grid[x][y].end.x) break; if (pt_y < grid[x][y].start.y || pt_y >= grid[x][y].end.y) break; - if (GetTerrainType(GetTile(pt_x, pt_y)) == TERRAIN_TYPE_NORMAL) { - // Make sure there aren't any hallways within 2 spaces from the current tile - // If there are, skip filling it in + if (GetTerrainType(GetTile(pt_x, pt_y)) == TERRAIN_TYPE_NORMAL) { + // Make sure there aren't any hallways within 2 spaces from the current tile + // If there are, skip filling it in - s32 direction = DIRECTION_SOUTH; - while (direction < NUM_DIRECTIONS) { + s32 direction = DIRECTION_SOUTH; + while (direction < NUM_DIRECTIONS) { s32 offsetX, offsetY; - s32 nextX = pt_x + gAdjacentTileOffsets[direction].x; - s32 nextY = pt_y + gAdjacentTileOffsets[direction].y; + s32 nextX = pt_x + gAdjacentTileOffsets[direction].x; + s32 nextY = pt_y + gAdjacentTileOffsets[direction].y; - bool8 found = FALSE; - for (offsetY = -1; offsetY <= 1; offsetY++) { + bool8 found = FALSE; + for (offsetY = -1; offsetY <= 1; offsetY++) { for (offsetX = -1; offsetX <= 1; offsetX++) { - // Search for open terrain which is not a part of a room (a hallway) - const Tile *tile = GetTile(nextX + offsetX, nextY + offsetY); + // Search for open terrain which is not a part of a room (a hallway) + const Tile *tile = GetTile(nextX + offsetX, nextY + offsetY); - if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) continue; if (tile->room == CORRIDOR_ROOM) { found = TRUE; @@ -2557,55 +2557,55 @@ static void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_C if (found) break; - } + } - if (found) + if (found) break; - } + } - if (found) + if (found) break; - direction++; - } + direction++; + } - // If direction == NUM_DIRECTIONS, we didn't find any hallways and are good to proceed - if (direction == NUM_DIRECTIONS) { - // Check that our cardinal neighbors' terrain types match what we expect for generating new tiles in this direction - // For example, if we're generating from the top-left corner, we should only expect tiles - // below us or to our right to have open terrain. If another tile does, we should stop - // because the resulting room may look strange otherwise + // If direction == NUM_DIRECTIONS, we didn't find any hallways and are good to proceed + if (direction == NUM_DIRECTIONS) { + // Check that our cardinal neighbors' terrain types match what we expect for generating new tiles in this direction + // For example, if we're generating from the top-left corner, we should only expect tiles + // below us or to our right to have open terrain. If another tile does, we should stop + // because the resulting room may look strange otherwise - direction = DIRECTION_SOUTH; - while (direction < NUM_DIRECTIONS) { - s32 nextX = gAdjacentTileOffsets[direction].x; - s32 nextY = gAdjacentTileOffsets[direction].y; - bool8 isOpen = (GetTerrainType(GetTile(pt_x + nextX, pt_y + nextY)) == TERRAIN_TYPE_NORMAL); + direction = DIRECTION_SOUTH; + while (direction < NUM_DIRECTIONS) { + s32 nextX = gAdjacentTileOffsets[direction].x; + s32 nextY = gAdjacentTileOffsets[direction].y; + bool8 isOpen = (GetTerrainType(GetTile(pt_x + nextX, pt_y + nextY)) == TERRAIN_TYPE_NORMAL); - if (gUnknown_80F6DD5[startingCorner][direction] != isOpen) + if (gUnknown_80F6DD5[startingCorner][direction] != isOpen) break; - // Advance by 2 to only check cardinal directions - direction += 2; - } + // Advance by 2 to only check cardinal directions + direction += 2; + } - // If direction == NUM_DIRECTIONS, the neighbors match what we expect - if (direction == NUM_DIRECTIONS) { - // Fill in the current open floor tile with a wall - SetTerrainWall(GetTileMut(pt_x, pt_y)); - } - } + // If direction == NUM_DIRECTIONS, the neighbors match what we expect + if (direction == NUM_DIRECTIONS) { + // Fill in the current open floor tile with a wall + SetTerrainWall(GetTileMut(pt_x, pt_y)); + } + } - break; - } - else { - // The terrain is filled or already a wall, move to the next tile - pt_x += moveX; - pt_y += moveY; - } - } - } - } + break; + } + else { + // The terrain is filled or already a wall, move to the next tile + pt_x += moveX; + pt_y += moveY; + } + } + } + } } } } @@ -2639,69 +2639,69 @@ static void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 counter = 0; // Create the vertical line between the starting point and the grid cell boundary while (y != turnY) { - if (counter++ >= DUNGEON_MAX_SIZE_X) + if (counter++ >= DUNGEON_MAX_SIZE_X) return; // Sanity check! - if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { - SetTerrainNormal(GetTileMut(x, y)); - } - else { - // If we find open floor, stop here - // The hall has connected up to an existing hall - if (x != startX || y != startY) + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileMut(x, y)); + } + else { + // If we find open floor, stop here + // The hall has connected up to an existing hall + if (x != startX || y != startY) return; - } + } - if (y < turnY) { - y++; - } - else { - y--; - } + if (y < turnY) { + y++; + } + else { + y--; + } } counter = 0; // Create the horizontal line to connect the horizontal lines at two different x values while (x != endX) { - if (counter++ >= DUNGEON_MAX_SIZE_X) + if (counter++ >= DUNGEON_MAX_SIZE_X) return; // Sanity check! - if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { - SetTerrainNormal(GetTileMut(x, y)); - } - else { - if (x != startX || y != startY) + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileMut(x, y)); + } + else { + if (x != startX || y != startY) return; - } + } - if (x < endX) { - x++; - } - else { - x--; - } + if (x < endX) { + x++; + } + else { + x--; + } } counter = 0; // Create the vertical line between the end point and the grid cell while (y != endY) { - if (counter++ >= DUNGEON_MAX_SIZE_X) + if (counter++ >= DUNGEON_MAX_SIZE_X) return; - if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { - SetTerrainNormal(GetTileMut(x, y)); - } - else { - if (x != startX || y != startY) + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileMut(x, y)); + } + else { + if (x != startX || y != startY) return; - } + } - if (y < endY) { - y++; - } - else { - y--; - } + if (y < endY) { + y++; + } + else { + y--; + } } } else { @@ -2710,69 +2710,69 @@ static void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 counter = 0; // Create the horizontal line between the starting point and the grid cell boundary while (x != turnX) { - if (counter++ >= DUNGEON_MAX_SIZE_X) + if (counter++ >= DUNGEON_MAX_SIZE_X) return; // Sanity check! - if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { - SetTerrainNormal(GetTileMut(x, y)); - } - else { - // If we find open floor, stop here - // The hall has connected up to an existing hall - if (x != startX || y != startY) + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileMut(x, y)); + } + else { + // If we find open floor, stop here + // The hall has connected up to an existing hall + if (x != startX || y != startY) return; - } + } - if (x < turnX) { - x++; - } - else { - x--; - } + if (x < turnX) { + x++; + } + else { + x--; + } } counter = 0; // Create the vertical line to connect the horizontal lines at two different y values while (y != endY) { - if (counter++ >= DUNGEON_MAX_SIZE_X) + if (counter++ >= DUNGEON_MAX_SIZE_X) return; - if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { - SetTerrainNormal(GetTileMut(x, y)); - } - else { - if (x != startX || y != startY) + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileMut(x, y)); + } + else { + if (x != startX || y != startY) return; - } + } - if (y < endY) { - y++; - } - else { - y--; - } + if (y < endY) { + y++; + } + else { + y--; + } } counter = 0; // Create the horizontal line between the end point and the grid cell while (x != endX) { - if (counter++ >= DUNGEON_MAX_SIZE_X) + if (counter++ >= DUNGEON_MAX_SIZE_X) return; - if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { - SetTerrainNormal(GetTileMut(x, y)); - } - else { - if (x != startX || y != startY) + if (GetTerrainType(GetTile(x, y)) != TERRAIN_TYPE_NORMAL) { + SetTerrainNormal(GetTileMut(x, y)); + } + else { + if (x != startX || y != startY) return; - } + } if (x < endX) { - x++; - } - else { - x--; - } + x++; + } + else { + x--; + } } } } @@ -2791,110 +2791,110 @@ static void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LE for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { - // If any of these is TRUE, this cell is fine and we don't need to worry about it - if (grid[x][y].isInvalid) + // If any of these is TRUE, this cell is fine and we don't need to worry about it + if (grid[x][y].isInvalid) continue; if (grid[x][y].hasBeenMerged) continue; if (grid[x][y].isConnected) continue; - if (grid[x][y].isRoom && !grid[x][y].hasSecondaryStructure) { - // Unconnected room - s32 pt_x, pt_y; - s32 rnd_x = DungeonRandRange(grid[x][y].start.x + 1, grid[x][y].end.x - 1); - s32 rnd_y = DungeonRandRange(grid[x][y].start.y + 1, grid[x][y].end.y - 1); + if (grid[x][y].isRoom && !grid[x][y].hasSecondaryStructure) { + // Unconnected room + s32 pt_x, pt_y; + s32 rnd_x = DungeonRandRange(grid[x][y].start.x + 1, grid[x][y].end.x - 1); + s32 rnd_y = DungeonRandRange(grid[x][y].start.y + 1, grid[x][y].end.y - 1); - if (y > 0 && !grid[x][y - 1].isInvalid && !grid[x][y - 1].isMerged && grid[x][y - 1].isConnected) { - // Attempt to connect to the grid cell above if it's connected - if (grid[x][y - 1].isRoom) { + if (y > 0 && !grid[x][y - 1].isInvalid && !grid[x][y - 1].isMerged && grid[x][y - 1].isConnected) { + // Attempt to connect to the grid cell above if it's connected + if (grid[x][y - 1].isRoom) { // Room, take random interior x coordinate - pt_x = DungeonRandRange(grid[x][y - 1].start.x + 1, grid[x][y - 1].end.x - 1); - pt_y = DungeonRandRange(grid[x][y - 1].start.y + 1, grid[x][y - 1].end.y - 1); // Unused - } - else { - // Anchor, take center x - pt_x = grid[x][y - 1].start.x; - pt_y = grid[x][y - 1].start.y; // Unused - } + pt_x = DungeonRandRange(grid[x][y - 1].start.x + 1, grid[x][y - 1].end.x - 1); + pt_y = DungeonRandRange(grid[x][y - 1].start.y + 1, grid[x][y - 1].end.y - 1); // Unused + } + else { + // Anchor, take center x + pt_x = grid[x][y - 1].start.x; + pt_y = grid[x][y - 1].start.y; // Unused + } - CreateHallway(rnd_x, grid[x][y].start.y, pt_x, grid[x][y - 1].end.y - 1, TRUE, listX[x], listY[y]); + CreateHallway(rnd_x, grid[x][y].start.y, pt_x, grid[x][y - 1].end.y - 1, TRUE, listX[x], listY[y]); - grid[x][y].isConnected = TRUE; - grid[x][y].connectedToTop = TRUE; - grid[x][y - 1].connectedToBottom = TRUE; - } - else if (y < gridSizeY - 1 && !grid[x][y + 1].isInvalid && !grid[x][y + 1].isMerged && grid[x][y + 1].isConnected) { - // Attempt to connect to the grid cell below if it's connected - if (grid[x][y + 1].isRoom) { - // Room, take random interior x coordinate + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToTop = TRUE; + grid[x][y - 1].connectedToBottom = TRUE; + } + else if (y < gridSizeY - 1 && !grid[x][y + 1].isInvalid && !grid[x][y + 1].isMerged && grid[x][y + 1].isConnected) { + // Attempt to connect to the grid cell below if it's connected + if (grid[x][y + 1].isRoom) { + // Room, take random interior x coordinate pt_x = DungeonRandRange(grid[x][y + 1].start.x + 1, grid[x][y + 1].end.x - 1); - pt_y = DungeonRandRange(grid[x][y + 1].start.y + 1, grid[x][y + 1].end.y - 1); // Unused - } - else { - // Anchor, take center x - pt_x = grid[x][y + 1].start.x; - pt_y = grid[x][y + 1].start.y; // Unused - } + pt_y = DungeonRandRange(grid[x][y + 1].start.y + 1, grid[x][y + 1].end.y - 1); // Unused + } + else { + // Anchor, take center x + pt_x = grid[x][y + 1].start.x; + pt_y = grid[x][y + 1].start.y; // Unused + } - CreateHallway(rnd_x, grid[x][y].end.y - 1, pt_x, grid[x][y + 1].start.y, TRUE, listX[x], listY[y + 1] - 1); + CreateHallway(rnd_x, grid[x][y].end.y - 1, pt_x, grid[x][y + 1].start.y, TRUE, listX[x], listY[y + 1] - 1); - grid[x][y].isConnected = TRUE; - grid[x][y].connectedToBottom = TRUE; - grid[x][y + 1].connectedToTop = TRUE; - } - else if (x > 0 && !grid[x - 1][y].isInvalid && !grid[x - 1][y].isMerged && grid[x - 1][y].isConnected) { - // Attempt to connect to the grid cell left if it's connected - if (grid[x - 1][y].isRoom) { + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToBottom = TRUE; + grid[x][y + 1].connectedToTop = TRUE; + } + else if (x > 0 && !grid[x - 1][y].isInvalid && !grid[x - 1][y].isMerged && grid[x - 1][y].isConnected) { + // Attempt to connect to the grid cell left if it's connected + if (grid[x - 1][y].isRoom) { // Room, take random interior y coordinate - pt_x = DungeonRandRange(grid[x - 1][y].start.x + 1, grid[x - 1][y].end.x - 1); //Unused - pt_y = DungeonRandRange(grid[x - 1][y].start.y + 1, grid[x - 1][y].end.y - 1); - } - else { - // Anchor, take center y - pt_x = grid[x - 1][y].start.x; // Unused - pt_y = grid[x - 1][y].start.y; - } + pt_x = DungeonRandRange(grid[x - 1][y].start.x + 1, grid[x - 1][y].end.x - 1); //Unused + pt_y = DungeonRandRange(grid[x - 1][y].start.y + 1, grid[x - 1][y].end.y - 1); + } + else { + // Anchor, take center y + pt_x = grid[x - 1][y].start.x; // Unused + pt_y = grid[x - 1][y].start.y; + } - // Typo? Would expect grid[x - 1][y].end.x - 1 for 3rd parameter - CreateHallway(grid[x][y].start.x, rnd_y, grid[x - 1][y].start.x - 1, pt_y, FALSE, listX[x], listY[y]); + // Typo? Would expect grid[x - 1][y].end.x - 1 for 3rd parameter + CreateHallway(grid[x][y].start.x, rnd_y, grid[x - 1][y].start.x - 1, pt_y, FALSE, listX[x], listY[y]); - grid[x][y].isConnected = TRUE; - grid[x][y].connectedToLeft = TRUE; - grid[x - 1][y].connectedToRight = TRUE; - } - else if (x < gridSizeX - 1 && !grid[x + 1][y].isInvalid && !grid[x + 1][y].isMerged && grid[x + 1][y].isConnected) { - // Attempt to connect to the grid cell right if it's connected - if (grid[x + 1][y].isRoom) { + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToLeft = TRUE; + grid[x - 1][y].connectedToRight = TRUE; + } + else if (x < gridSizeX - 1 && !grid[x + 1][y].isInvalid && !grid[x + 1][y].isMerged && grid[x + 1][y].isConnected) { + // Attempt to connect to the grid cell right if it's connected + if (grid[x + 1][y].isRoom) { // Room, take random interior y coordinate - pt_x = DungeonRandRange(grid[x + 1][y].start.x + 1, grid[x + 1][y].end.x - 1); // Unused - pt_y = DungeonRandRange(grid[x + 1][y].start.y + 1, grid[x + 1][y].end.y - 1); - } + pt_x = DungeonRandRange(grid[x + 1][y].start.x + 1, grid[x + 1][y].end.x - 1); // Unused + pt_y = DungeonRandRange(grid[x + 1][y].start.y + 1, grid[x + 1][y].end.y - 1); + } else { - // Anchor, take center y - pt_x = grid[x + 1][y].start.x; // Unused - pt_y = grid[x + 1][y].start.y; - } + // Anchor, take center y + pt_x = grid[x + 1][y].start.x; // Unused + pt_y = grid[x + 1][y].start.y; + } - CreateHallway(grid[x][y].end.x - 1, rnd_y, grid[x + 1][y].start.x, pt_y, FALSE, listX[x + 1] - 1, listY[y]); + CreateHallway(grid[x][y].end.x - 1, rnd_y, grid[x + 1][y].start.x, pt_y, FALSE, listX[x + 1] - 1, listY[y]); - grid[x][y].isConnected = TRUE; - grid[x][y].connectedToRight = TRUE; - grid[x + 1][y].connectedToLeft = TRUE; - } - } - else { - // Unconnected anchor, don't bother trying. + grid[x][y].isConnected = TRUE; + grid[x][y].connectedToRight = TRUE; + grid[x + 1][y].connectedToLeft = TRUE; + } + } + else { + // Unconnected anchor, don't bother trying. - // Just fill it in with wall tiles + // Just fill it in with wall tiles Tile *tile = GetTileMut(grid[x][y].start.x, grid[x][y].start.y); SetTerrainWall(tile); - // Also remove any spawn flags - tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); - tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); - tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); - } + // Also remove any spawn flags + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); + } } } @@ -2903,24 +2903,24 @@ static void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LE for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { s32 curX, curY; - if (grid[x][y].isInvalid || grid[x][y].hasBeenMerged || grid[x][y].isConnected || grid[x][y].unk15) + if (grid[x][y].isInvalid || grid[x][y].hasBeenMerged || grid[x][y].isConnected || grid[x][y].unk15) continue; - for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { - for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { - Tile *tile = GetTileMut(curX, curY); + for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { + for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { + Tile *tile = GetTileMut(curX, curY); // Set it to wall terrain - SetTerrainWall(tile); + SetTerrainWall(tile); - // Remove any spawn flags - tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + // Remove any spawn flags + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); - // Set room index to 0xFF (not a room) - tile->room = CORRIDOR_ROOM; - } - } + // Set room index to 0xFF (not a room) + tile->room = CORRIDOR_ROOM; + } + } } } } @@ -3120,18 +3120,18 @@ static void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LE s32 curX, curY; y = listY[j]; - if (y >= gridSizeY) + if (y >= gridSizeY) continue; - // We've identified a random in-bounds grid cell - // To support a kecleon shop it must be: - // - valid - // - not a merged room - // - connected - // - a room - // - have no other special features (mazes/secondary structures) - // - have dimensions of at least 5x4 - if (grid[x][y].isInvalid) + // We've identified a random in-bounds grid cell + // To support a kecleon shop it must be: + // - valid + // - not a merged room + // - connected + // - a room + // - have no other special features (mazes/secondary structures) + // - have dimensions of at least 5x4 + if (grid[x][y].isInvalid) continue; if (grid[x][y].hasBeenMerged) continue; @@ -3148,74 +3148,74 @@ static void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LE if (grid[x][y].flagSecondaryStructure) continue; - if (abs(grid[x][y].end.x - grid[x][y].start.x) < 5 || abs(grid[x][y].end.y - grid[x][y].start.y) < 4) + if (abs(grid[x][y].end.x - grid[x][y].start.x) < 5 || abs(grid[x][y].end.y - grid[x][y].start.y) < 4) continue; - // This room can be a kecleon shop - sHasKecleonShop = TRUE; - grid[x][y].isKecleonShop = TRUE; + // This room can be a kecleon shop + sHasKecleonShop = TRUE; + grid[x][y].isKecleonShop = TRUE; - // Make the shop span the whole room - sKecleonShopPosition.minX = grid[x][y].start.x + 1; + // Make the shop span the whole room + sKecleonShopPosition.minX = grid[x][y].start.x + 1; sKecleonShopPosition.maxX = grid[x][y].end.x - 1; sKecleonShopPosition.minY = grid[x][y].start.y + 1; - sKecleonShopPosition.maxY = grid[x][y].end.y - 1; + sKecleonShopPosition.maxY = grid[x][y].end.y - 1; - if (sKecleonShopPosition.maxY - sKecleonShopPosition.minY < 3) { - // This should never happen? - sKecleonShopPosition.maxY++; - } + if (sKecleonShopPosition.maxY - sKecleonShopPosition.minY < 3) { + // This should never happen? + sKecleonShopPosition.maxY++; + } - // Set to values that guarantee they'll be replaced later - dungeon->kecleonShopPos.minX = DEFAULT_MAX_POSITION; - dungeon->kecleonShopPos.minY = DEFAULT_MAX_POSITION; - dungeon->kecleonShopPos.maxX = -DEFAULT_MAX_POSITION; - dungeon->kecleonShopPos.maxY = -DEFAULT_MAX_POSITION; + // Set to values that guarantee they'll be replaced later + dungeon->kecleonShopPos.minX = DEFAULT_MAX_POSITION; + dungeon->kecleonShopPos.minY = DEFAULT_MAX_POSITION; + dungeon->kecleonShopPos.maxX = -DEFAULT_MAX_POSITION; + dungeon->kecleonShopPos.maxY = -DEFAULT_MAX_POSITION; - // Generate the actual shop on the interior, leaving - // a 1-tile border from the room walls - for (curX = sKecleonShopPosition.minX; curX < sKecleonShopPosition.maxX; curX++) { - for (curY = sKecleonShopPosition.minY; curY < sKecleonShopPosition.maxY; curY++) { + // Generate the actual shop on the interior, leaving + // a 1-tile border from the room walls + for (curX = sKecleonShopPosition.minX; curX < sKecleonShopPosition.maxX; curX++) { + for (curY = sKecleonShopPosition.minY; curY < sKecleonShopPosition.maxY; curY++) { Tile *tile = GetTileMut(curX, curY); tile->terrainType |= TERRAIN_TYPE_SHOP; - // Restrict monsters and stairs from spawning here - tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_MONSTER); - tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); + // Restrict monsters and stairs from spawning here + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_MONSTER); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_STAIRS); - // Ensure the borders are assigned properly - if (dungeon->kecleonShopPos.minX > curX) { - dungeon->kecleonShopPos.minX = curX; - } + // Ensure the borders are assigned properly + if (dungeon->kecleonShopPos.minX > curX) { + dungeon->kecleonShopPos.minX = curX; + } - if (dungeon->kecleonShopPos.minY > curY) { - dungeon->kecleonShopPos.minY = curY; - } + if (dungeon->kecleonShopPos.minY > curY) { + dungeon->kecleonShopPos.minY = curY; + } - if (dungeon->kecleonShopPos.maxX < curX) { - dungeon->kecleonShopPos.maxX = curX; - } + if (dungeon->kecleonShopPos.maxX < curX) { + dungeon->kecleonShopPos.maxX = curX; + } - if (dungeon->kecleonShopPos.maxY < curY) { - dungeon->kecleonShopPos.maxY = curY; - } - } - } + if (dungeon->kecleonShopPos.maxY < curY) { + dungeon->kecleonShopPos.maxY = curY; + } + } + } - // Sets an unknown spawn flag for all tiles in the room - for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { - for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { + // Sets an unknown spawn flag for all tiles in the room + for (curX = grid[x][y].start.x; curX < grid[x][y].end.x; curX++) { + for (curY = grid[x][y].start.y; curY < grid[x][y].end.y; curY++) { GetTileMut(curX, curY)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; - } - } + } + } curX = (sKecleonShopPosition.minX + sKecleonShopPosition.maxX) / 2; curY = (sKecleonShopPosition.minY + sKecleonShopPosition.maxY) / 2; - sKecleonShopMiddlePos.x = curX; - sKecleonShopMiddlePos.y = curY; + sKecleonShopMiddlePos.x = curX; + sKecleonShopMiddlePos.y = curY; - return; + return; } } } @@ -3256,14 +3256,14 @@ static void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_L for (x = 0; x < gridSizeX; x++) { for (y = 0; y < gridSizeY; y++) { - // A grid cell can have a monster house if it: - // - is valid - // - is not a merged room - // - is connected - // - is a room - // - is not a maze - // - and some other unknown condition - if (grid[x][y].isInvalid) + // A grid cell can have a monster house if it: + // - is valid + // - is not a merged room + // - is connected + // - is a room + // - is not a maze + // - and some other unknown condition + if (grid[x][y].isInvalid) continue; if (grid[x][y].hasBeenMerged) continue; @@ -3477,60 +3477,60 @@ static void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) // Random walks from upper border for (curX = gridCell->start.x + 1; curX < gridCell->end.x - 1; curX += 2) { if (GetTerrainType(GetTile(curX, gridCell->start.y - 1)) != TERRAIN_TYPE_NORMAL) { - GenerateMazeLine(curX, - gridCell->start.y - 1, - gridCell->start.x, - gridCell->start.y, - gridCell->end.x, - gridCell->end.y, - useSecondaryTerrain, - roomIndex - ); + GenerateMazeLine(curX, + gridCell->start.y - 1, + gridCell->start.x, + gridCell->start.y, + gridCell->end.x, + gridCell->end.y, + useSecondaryTerrain, + roomIndex + ); } } // Random walks from right border for (curY = gridCell->start.y + 1; curY < gridCell->end.y - 1; curY += 2) { if (GetTerrainType(GetTile(gridCell->end.x, curY)) != TERRAIN_TYPE_NORMAL) { - GenerateMazeLine(gridCell->end.x, curY, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); + GenerateMazeLine(gridCell->end.x, curY, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); } } // Random walks from lower border for (curX = gridCell->start.x + 1; curX < gridCell->end.x - 1; curX += 2) { if (GetTerrainType(GetTile(curX, gridCell->end.y)) != TERRAIN_TYPE_NORMAL) { - GenerateMazeLine(curX, gridCell->end.y, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); + GenerateMazeLine(curX, gridCell->end.y, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); } } // Random walks from left border for (curY = gridCell->start.y + 1; curY < gridCell->end.y - 1; curY += 2) { if (GetTerrainType(GetTile(gridCell->start.x - 1, curY)) != TERRAIN_TYPE_NORMAL) { - GenerateMazeLine(gridCell->start.x - 1, - curY, - gridCell->start.x, - gridCell->start.y, - gridCell->end.x, - gridCell->end.y, - useSecondaryTerrain, - roomIndex); + GenerateMazeLine(gridCell->start.x - 1, + curY, + gridCell->start.x, + gridCell->start.y, + gridCell->end.x, + gridCell->end.y, + useSecondaryTerrain, + roomIndex); } } // Fill in all the inner tiles with a stride of 2 for (curX = gridCell->start.x + 3; curX < gridCell->end.x - 3; curX += 2) { for (curY = gridCell->start.y + 3; curY < gridCell->end.y - 3; curY += 2) { - if (GetTerrainType(GetTile(curX, curY)) == TERRAIN_TYPE_NORMAL) { - if (useSecondaryTerrain) { + if (GetTerrainType(GetTile(curX, curY)) == TERRAIN_TYPE_NORMAL) { + if (useSecondaryTerrain) { SetTerrainSecondary(GetTileMut(curX - 1, curY)); - } - else { - SetTerrainWall(GetTileMut(curX - 1, curY)); - } + } + else { + SetTerrainWall(GetTileMut(curX - 1, curY)); + } - // More random walks - GenerateMazeLine(curX, curY, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); - } + // More random walks + GenerateMazeLine(curX, curY, gridCell->start.x, gridCell->start.y, gridCell->end.x, gridCell->end.y, useSecondaryTerrain, roomIndex); + } } } } @@ -3564,11 +3564,11 @@ static void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 y SetTerrainObstacleChecked(GetTileMut(x0, y0), useSecondaryTerrain, roomIndex); while (1) { - s32 offsetX, offsetY; - s32 posX, posY; + s32 offsetX, offsetY; + s32 posX, posY; - // Offset from our current DungeonPos to look 2 tiles in a given direction - switch (direction & CARDINAL_DIRECTION_MASK) { + // Offset from our current DungeonPos to look 2 tiles in a given direction + switch (direction & CARDINAL_DIRECTION_MASK) { case CARDINAL_DIR_RIGHT: offsetX = 2; offsetY = 0; @@ -3586,24 +3586,24 @@ static void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 y offsetX = 0; offsetY = 2; break; - } + } posX = x0 + offsetX; - // Check that this DungeonPos is in-bounds + // Check that this DungeonPos is in-bounds if (xMin <= posX && xMax > posX) { posY = y0 + offsetY; if (yMin <= posY && yMax > posY) { // Check that this tile is open ground - if (GetTerrainType(GetTile(posX, posY)) == TERRAIN_TYPE_NORMAL) { - // We found open ground, we're done! - break; - } + if (GetTerrainType(GetTile(posX, posY)) == TERRAIN_TYPE_NORMAL) { + // We found open ground, we're done! + break; + } } } - // We didn't find any, try a different direction - direction++; + // We didn't find any, try a different direction + direction++; if (++i >= 4) return; } @@ -3614,22 +3614,22 @@ static void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 y case CARDINAL_DIR_RIGHT: SetTerrainObstacleChecked(GetTileMut(x0 + 1, y0), useSecondaryTerrain, roomIndex); - x0 += 2; + x0 += 2; break; case CARDINAL_DIR_UP: SetTerrainObstacleChecked(GetTileMut(x0, y0 - 1), useSecondaryTerrain, roomIndex); - y0 -= 2; + y0 -= 2; break; case CARDINAL_DIR_LEFT: SetTerrainObstacleChecked(GetTileMut(x0 - 1, y0), useSecondaryTerrain, roomIndex); - x0 -= 2; + x0 -= 2; break; case CARDINAL_DIR_DOWN: SetTerrainObstacleChecked(GetTileMut(x0, y0 + 1), useSecondaryTerrain, roomIndex); - y0 += 2; + y0 += 2; break; } } @@ -3672,15 +3672,15 @@ static bool8 IsNextToHallway(s32 x, s32 y) for (offsetY = -1; offsetY <= 1; offsetY++) { posY = y + offsetY; - if (posY < 0) + if (posY < 0) continue; - if (posY >= DUNGEON_MAX_SIZE_Y) + if (posY >= DUNGEON_MAX_SIZE_Y) break; - if (offsetX != 0 && offsetY != 0) + if (offsetX != 0 && offsetY != 0) continue; - if (GetTerrainType(GetTile(posX, posY)) == TERRAIN_TYPE_NORMAL && GetTile(posX, posY)->room == CORRIDOR_ROOM) - return TRUE; + if (GetTerrainType(GetTile(posX, posY)) == TERRAIN_TYPE_NORMAL && GetTile(posX, posY)->room == CORRIDOR_ROOM) + return TRUE; } } @@ -3698,61 +3698,61 @@ static void GenerateSecondaryStructure(struct GridCell *gridCell) sSecondaryStructuresBudget--; - SetSpawnFlag5(gridCell); - if (DungeonRandInt(2) != 0) { - // Split the room with a vertical line + SetSpawnFlag5(gridCell); + if (DungeonRandInt(2) != 0) { + // Split the room with a vertical line s32 curX, curY; - bool8 invalid = FALSE; - s32 middleX = (gridCell->start.x + gridCell->end.x) / 2; + bool8 invalid = FALSE; + s32 middleX = (gridCell->start.x + gridCell->end.x) / 2; - for (i = gridCell->start.y; i < gridCell->end.y; i++) { - if (IsNextToHallway(middleX, i)) { - invalid = TRUE; - break; - } - } + for (i = gridCell->start.y; i < gridCell->end.y; i++) { + if (IsNextToHallway(middleX, i)) { + invalid = TRUE; + break; + } + } - if (!invalid) { - for (i = gridCell->start.y; i < gridCell->end.y; i++) { + if (!invalid) { + for (i = gridCell->start.y; i < gridCell->end.y; i++) { SetTerrainSecondaryWithFlag(GetTileMut(middleX, i), 0); - } + } - for (curX = gridCell->start.x; curX < middleX; curX++) { - for (curY = gridCell->start.y; curY < gridCell->end.y; curY++) { + for (curX = gridCell->start.x; curX < middleX; curX++) { + for (curY = gridCell->start.y; curY < gridCell->end.y; curY++) { GetTileMut(curX, curY)->terrainType |= TERRAIN_TYPE_UNK_7; - } - } + } + } - gridCell->hasSecondaryStructure = TRUE; - } - } - else { + gridCell->hasSecondaryStructure = TRUE; + } + } + else { // Split the room with a horizontal line s32 curX, curY; bool8 invalid = FALSE; s32 middleY = (gridCell->start.y + gridCell->end.y) / 2; - for (i = gridCell->start.x; i < gridCell->end.x; i++) { - if (IsNextToHallway(i, middleY)) { - invalid = TRUE; - break; - } - } + for (i = gridCell->start.x; i < gridCell->end.x; i++) { + if (IsNextToHallway(i, middleY)) { + invalid = TRUE; + break; + } + } - if (!invalid) { - for (i = gridCell->start.x; i < gridCell->end.x; i++) { - SetTerrainSecondaryWithFlag(GetTileMut(i, middleY), 0); - } + if (!invalid) { + for (i = gridCell->start.x; i < gridCell->end.x; i++) { + SetTerrainSecondaryWithFlag(GetTileMut(i, middleY), 0); + } - for (curY = gridCell->start.y; curY < middleY; curY++) { + for (curY = gridCell->start.y; curY < middleY; curY++) { for (curX = gridCell->start.x; curX < gridCell->end.x; curX++) { - GetTileMut(curX, curY)->terrainType |= TERRAIN_TYPE_UNK_7; - } - } + GetTileMut(curX, curY)->terrainType |= TERRAIN_TYPE_UNK_7; + } + } - gridCell->hasSecondaryStructure = TRUE; - } - } + gridCell->hasSecondaryStructure = TRUE; + } + } } break; case SECONDARY_STRUCTURE_ISLAND: @@ -3858,27 +3858,27 @@ static void GenerateSecondaryStructure(struct GridCell *gridCell) sSecondaryStructuresBudget--; // If the dimensions are odd, generate a maze room - if ((gridCell->end.x - gridCell->start.x) % 2 == 0 || (gridCell->end.y - gridCell->start.y) % 2 == 0) { + if ((gridCell->end.x - gridCell->start.x) % 2 == 0 || (gridCell->end.y - gridCell->start.y) % 2 == 0) { s32 middleX = (gridCell->start.x + gridCell->end.x) / 2; s32 middleY = (gridCell->start.y + gridCell->end.y) / 2; - if ((gridCell->end.x - gridCell->start.x) >= 5 && (gridCell->end.y - gridCell->start.y) >= 5) { - // Both dimensions are at least 5, generate a water/lava cross in the center - SetTerrainSecondaryWithFlag(GetTileMut(middleX + 1, middleY), 0); - SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY + 1), 0); - SetTerrainSecondaryWithFlag(GetTileMut(middleX - 1, middleY), 0); - SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY - 1), 0); - } + if ((gridCell->end.x - gridCell->start.x) >= 5 && (gridCell->end.y - gridCell->start.y) >= 5) { + // Both dimensions are at least 5, generate a water/lava cross in the center + SetTerrainSecondaryWithFlag(GetTileMut(middleX + 1, middleY), 0); + SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY + 1), 0); + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 1, middleY), 0); + SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY - 1), 0); + } // Generate a single water/lava spot in the center SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY), 0); - } - else { + } + else { // Both dimensions are odd. Generate a maze room - SetSpawnFlag5(gridCell); - GenerateMaze(gridCell, TRUE); - } + SetSpawnFlag5(gridCell); + GenerateMaze(gridCell, TRUE); + } - gridCell->hasSecondaryStructure = TRUE; + gridCell->hasSecondaryStructure = TRUE; } break; } @@ -3911,7 +3911,7 @@ static void ResolveInvalidSpawns(void) if (tile->spawnOrVisibilityFlags & SPAWN_FLAG_STAIRS) { // This tile has the stairs, make sure the stairs bit is set and - // make sure no traps spawn here + // make sure no traps spawn here tile->terrainType |= TERRAIN_TYPE_STAIRS; tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_TRAP); } @@ -4075,18 +4075,18 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou if (dungeon->stairsSpawn.x == -1 || dungeon->stairsSpawn.y == -1) { count = 0; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { - for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // The stairs can spawn on tiles that are: - // - Open Terrain - // - In a room - // - Not in a Kecleon Shop - // - Not an enemy spawn - // - Not a special tile (flagged by kecleon shops, traps, and items) - // - Not a junction tile (next to a hallway) - // - Not a special tile that can't be broken by Absolute Mover + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // The stairs can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not an enemy spawn + // - Not a special tile (flagged by kecleon shops, traps, and items) + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover const Tile *tile = GetTile(x, y); - if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) continue; if (tile->room == CORRIDOR_ROOM) continue; @@ -4104,21 +4104,21 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou validSpawns[count].x = x; validSpawns[count].y = y; count++; - } + } } if (count != 0) { - // Randomly select one of the valid tiles to spawn the stairs on - s32 stairsIndex = DungeonRandInt(count); - Tile *stairsTile = GetTileMut(validSpawns[stairsIndex].x, validSpawns[stairsIndex].y); + // Randomly select one of the valid tiles to spawn the stairs on + s32 stairsIndex = DungeonRandInt(count); + Tile *stairsTile = GetTileMut(validSpawns[stairsIndex].x, validSpawns[stairsIndex].y); - stairsTile->spawnOrVisibilityFlags |= SPAWN_FLAG_STAIRS; - stairsTile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); - sStairsRoomIndex = stairsTile->room; - dungeon->stairsSpawn.x = validSpawns[stairsIndex].x; - dungeon->stairsSpawn.y = validSpawns[stairsIndex].y; + stairsTile->spawnOrVisibilityFlags |= SPAWN_FLAG_STAIRS; + stairsTile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + sStairsRoomIndex = stairsTile->room; + dungeon->stairsSpawn.x = validSpawns[stairsIndex].x; + dungeon->stairsSpawn.y = validSpawns[stairsIndex].y; - // If we're spawning normal stairs and this is a rescue floor, make the stairs room a Monster House + // If we're spawning normal stairs and this is a rescue floor, make the stairs room a Monster House if (GetFloorType() == FLOOR_TYPE_RESCUE) { u32 stairsRoomIndex = stairsTile->room; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { @@ -4139,15 +4139,15 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou count = 0; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // Normal items can spawn on tiles that are: - // - Open Terrain - // - In a room - // - Not in a Kecleon Shop - // - Not in a Monster House - // - Not a junction tile (next to a hallway) - // - Not a special tile that can't be broken by Absolute Mover + // Normal items can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not in a Monster House + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover - const Tile *tile = GetTile(x, y); + const Tile *tile = GetTile(x, y); if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) continue; if (tile->room == CORRIDOR_ROOM) @@ -4161,7 +4161,7 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) continue; - validSpawns[count].x = x; + validSpawns[count].x = x; validSpawns[count].y = y; count++; } @@ -4170,19 +4170,19 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou if (count != 0) { s32 numItems = floorProps->itemDensity; if (numItems != 0) { - // Add variation to the item count - numItems = DungeonRandRange(numItems - 2, numItems + 2); - if (numItems <= 0) { + // Add variation to the item count + numItems = DungeonRandRange(numItems - 2, numItems + 2); + if (numItems <= 0) { numItems = 1; - } + } } if (numItems != 0) { - // Randomly select among the valid item spawn spots - ShuffleSpawnPositions(validSpawns, count); - randIndex = DungeonRandInt(count); - for (i = 0; i < numItems; i++) { - Tile *tile = GetTileMut(validSpawns[randIndex].x, validSpawns[randIndex].y); + // Randomly select among the valid item spawn spots + ShuffleSpawnPositions(validSpawns, count); + randIndex = DungeonRandInt(count); + for (i = 0; i < numItems; i++) { + Tile *tile = GetTileMut(validSpawns[randIndex].x, validSpawns[randIndex].y); tile->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; randIndex++; @@ -4190,7 +4190,7 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou // Wrap around to the start randIndex = 0; } - } + } } } @@ -4199,12 +4199,12 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou count = 0; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // Any wall tile is all buried items need - if (GetTerrainType(GetTile(x, y)) == TERRAIN_TYPE_WALL) { - validSpawns[count].x = x; + // Any wall tile is all buried items need + if (GetTerrainType(GetTile(x, y)) == TERRAIN_TYPE_WALL) { + validSpawns[count].x = x; validSpawns[count].y = y; count++; - } + } } } @@ -4212,16 +4212,16 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou s32 numItems = floorProps->buriedItemDensity; if (numItems != 0) { - // Add variation to the item count - numItems = DungeonRandRange(numItems - 2, numItems + 2); + // Add variation to the item count + numItems = DungeonRandRange(numItems - 2, numItems + 2); } if (numItems > 0) { - // Randomly select among the valid item spawn spots - ShuffleSpawnPositions(validSpawns, count); - randIndex = DungeonRandInt(count); - for (i = 0; i < numItems; i++) { - Tile *tile = GetTileMut(validSpawns[randIndex].x, validSpawns[randIndex].y); + // Randomly select among the valid item spawn spots + ShuffleSpawnPositions(validSpawns, count); + randIndex = DungeonRandInt(count); + for (i = 0; i < numItems; i++) { + Tile *tile = GetTileMut(validSpawns[randIndex].x, validSpawns[randIndex].y); tile->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; randIndex++; @@ -4229,7 +4229,7 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou // Wrap around to the start randIndex = 0; } - } + } } } @@ -4237,12 +4237,12 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou count = 0; if (!isEmptyMonsterHouse) { for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { - for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // Monster House items/traps can spawn on tiles that are: - // - not in a kecleon shop (how would they be?) - // - in a Monster House - // - not a junction (near a hallway) - const Tile *tile = GetTile(x, y); + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // Monster House items/traps can spawn on tiles that are: + // - not in a kecleon shop (how would they be?) + // - in a Monster House + // - not a junction (near a hallway) + const Tile *tile = GetTile(x, y); if (tile->terrainType & TERRAIN_TYPE_SHOP) continue; if (!(tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE)) @@ -4253,7 +4253,7 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou validSpawns[count].x = x; validSpawns[count].y = y; count++; - } + } } } @@ -4296,15 +4296,15 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou count = 0; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // Normal traps can spawn on tiles that are: - // - Open Terrain - // - In a room - // - Not in a Kecleon Shop - // - Don't already have an item spawn - // - Not a junction tile (next to a hallway) - // - Not a special tile that can't be broken by Absolute Mover + // Normal traps can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Don't already have an item spawn + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover - const Tile *tile = GetTile(x, y); + const Tile *tile = GetTile(x, y); if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) continue; if (tile->room == CORRIDOR_ROOM) @@ -4318,7 +4318,7 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou if (tile->terrainType & TERRAIN_TYPE_UNBREAKABLE) continue; - validSpawns[count].x = x; + validSpawns[count].x = x; validSpawns[count].y = y; count++; } @@ -4329,16 +4329,16 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou if (numTraps > 0) { s32 trapIndex; - if (numTraps >= 56) { - // Cap the number of traps at 56 - numTraps = 56; - } + if (numTraps >= 56) { + // Cap the number of traps at 56 + numTraps = 56; + } - // Randomly select among the valid trap spawn spots - ShuffleSpawnPositions(validSpawns, count); - trapIndex = DungeonRandInt(count); - for (i = 0; i < numTraps; i++) { - Tile *tile = GetTileMut(validSpawns[trapIndex].x, validSpawns[trapIndex].y); + // Randomly select among the valid trap spawn spots + ShuffleSpawnPositions(validSpawns, count); + trapIndex = DungeonRandInt(count); + for (i = 0; i < numTraps; i++) { + Tile *tile = GetTileMut(validSpawns[trapIndex].x, validSpawns[trapIndex].y); tile->spawnOrVisibilityFlags |= SPAWN_FLAG_TRAP; trapIndex++; @@ -4346,7 +4346,7 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou // Wrap around to the start trapIndex = 0; } - } + } } } @@ -4354,16 +4354,16 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou if (dungeon->playerSpawn.x == -1 || dungeon->playerSpawn.y == -1) { count = 0; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { - for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // The player can spawn on tiles that are: - // - Open Terrain - // - In a room - // - Not in a Kecleon Shop - // - Not a junction tile (next to a hallway) - // - Not a special tile that can't be broken by Absolute Mover - // - Not an item, enemy, or trap spawn + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + // The player can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not a junction tile (next to a hallway) + // - Not a special tile that can't be broken by Absolute Mover + // - Not an item, enemy, or trap spawn - const Tile *tile = GetTile(x, y); + const Tile *tile = GetTile(x, y); if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) continue; if (tile->room == CORRIDOR_ROOM) @@ -4384,14 +4384,14 @@ static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHou validSpawns[count].x = x; validSpawns[count].y = y; count++; - } + } } if (count != 0) { - // Randomly select one of the valid tiles to spawn the player on - s32 spawnIndex = DungeonRandInt(count); - dungeon->playerSpawn.x = validSpawns[spawnIndex].x; - dungeon->playerSpawn.y = validSpawns[spawnIndex].y; + // Randomly select one of the valid tiles to spawn the player on + s32 spawnIndex = DungeonRandInt(count); + dungeon->playerSpawn.x = validSpawns[spawnIndex].x; + dungeon->playerSpawn.y = validSpawns[spawnIndex].y; } } } @@ -4415,7 +4415,7 @@ static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) numEnemies = DungeonRandRange(enemyDensity / 2, enemyDensity); if (numEnemies < 1) { - numEnemies = 1; + numEnemies = 1; } } else { @@ -4426,15 +4426,15 @@ static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) count = 0; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // Enemies can spawn on tiles that are: - // - Open Terrain - // - In a room - // - Not in a Kecleon Shop - // - Don't have stairs, an item - // - Not a special tile that can't be broken by Absolute Mover - // - Not where the player spawns - const Tile *tile = GetTile(x, y); - if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + // Enemies can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Don't have stairs, an item + // - Not a special tile that can't be broken by Absolute Mover + // - Not where the player spawns + const Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) continue; if (tile->room == CORRIDOR_ROOM) continue; @@ -4500,16 +4500,16 @@ static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { s32 y; for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - // Monster House enemies can spawn on tiles that are: - // - Open Terrain - // - In a room - // - Not in a Kecleon Shop - // - Not a special tile that can't be broken by Absolute Mover - // - Not where the player spawns - // - In the monster house room + // Monster House enemies can spawn on tiles that are: + // - Open Terrain + // - In a room + // - Not in a Kecleon Shop + // - Not a special tile that can't be broken by Absolute Mover + // - Not where the player spawns + // - In the monster house room - const Tile *tile = GetTile(x, y); - if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) + const Tile *tile = GetTile(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) continue; if (tile->room == CORRIDOR_ROOM) continue; @@ -4536,8 +4536,8 @@ static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) } if (numEnemies >= numMonsterHouseEnemies) { - // Don't spawn more enemies than the designated limit - numEnemies = numMonsterHouseEnemies; + // Don't spawn more enemies than the designated limit + numEnemies = numMonsterHouseEnemies; } // Randomly select among the valid enemy spawn spots @@ -4619,13 +4619,13 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP // Randomly pick between starting from the bottom going up, or from the top going down if (DungeonRandInt(100) < 50) { upwards = TRUE; - y = DUNGEON_MAX_SIZE_Y - 1; - dirY = -1; + y = DUNGEON_MAX_SIZE_Y - 1; + dirY = -1; } else { upwards = FALSE; - y = 0; - dirY = 1; + y = 0; + dirY = 1; } stepsUntilLake = DungeonRandInt(50) + 10; @@ -4635,42 +4635,42 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP dirX = 0; while (1) { - // Fill in tiles in chunks of size 2-7 before changing the flow direction - numTilesFill = DungeonRandInt(6) + 2; - while (numTilesFill != 0) { - if (x >= 0 && x < DUNGEON_MAX_SIZE_X) { - if (GetTerrainType(GetTile(x, y)) == TERRAIN_TYPE_SECONDARY) { - goto LABEL; - } + // Fill in tiles in chunks of size 2-7 before changing the flow direction + numTilesFill = DungeonRandInt(6) + 2; + while (numTilesFill != 0) { + if (x >= 0 && x < DUNGEON_MAX_SIZE_X) { + if (GetTerrainType(GetTile(x, y)) == TERRAIN_TYPE_SECONDARY) { + goto LABEL; + } if (!PosIsOutOfBounds(x, y)) { // Fill in secondary terrain as we go SetSecondaryTerrainOnWall(GetTileMut(x, y)); } - } + } numTilesFill--; - // Move to the next tile - x += dirX; - y += dirY; + // Move to the next tile + x += dirX; + y += dirY; - // Vertically out of bounds, stop - if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { + // Vertically out of bounds, stop + if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { break; - } + } - stepsUntilLake--; - if (stepsUntilLake != 0) + stepsUntilLake--; + if (stepsUntilLake != 0) continue; - // After we go a certain number of steps, make a "lake" + // After we go a certain number of steps, make a "lake" - // This loop will attempt to generate new lake tiles up to 64 times - // We select a random tile, check for space and nearby secondary terrain tiles, - // then if verified add a new lake tile. - for (j = 0; j < 64; j++) { - // Each tile is in a random location +-3 tiles from the current cursor in either direction - s32 offsetX = DungeonRandInt(7) - 3; - s32 offsetY = DungeonRandInt(7) - 3; + // This loop will attempt to generate new lake tiles up to 64 times + // We select a random tile, check for space and nearby secondary terrain tiles, + // then if verified add a new lake tile. + for (j = 0; j < 64; j++) { + // Each tile is in a random location +-3 tiles from the current cursor in either direction + s32 offsetX = DungeonRandInt(7) - 3; + s32 offsetY = DungeonRandInt(7) - 3; // Check that there's enough space for a lake within a 2 tile margin of the map bounds if (offsetX + x < 2 || offsetX + x >= DUNGEON_MAX_SIZE_X - 2 || offsetY + y < 2 || offsetY + y >= DUNGEON_MAX_SIZE_Y - 2) @@ -4692,16 +4692,16 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP SetSecondaryTerrainOnWall(GetTileMut(offsetX + x, offsetY + y)); } } - } + } - // Finalization/gap-filling step because the random approach - // might leave weird gaps. Go through every tile and do an - // on line nearest-neighbor interpolation of secondary terrain - // tiles to smoothen out the "lake" - for (offsetX = -3; offsetX <= 3; offsetX++) { + // Finalization/gap-filling step because the random approach + // might leave weird gaps. Go through every tile and do an + // on line nearest-neighbor interpolation of secondary terrain + // tiles to smoothen out the "lake" + for (offsetX = -3; offsetX <= 3; offsetX++) { - for (offsetY = -3; offsetY <= 3; offsetY++) { - s32 numAdjacent = 0; + for (offsetY = -3; offsetY <= 3; offsetY++) { + s32 numAdjacent = 0; s32 xPlus1, yPlus1; if (offsetX + x < 2 || offsetX + x >= DUNGEON_MAX_SIZE_X - 2 || offsetY + y < 2 || offsetY + y >= DUNGEON_MAX_SIZE_Y - 2) @@ -4724,13 +4724,13 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP if (numAdjacent >= 4 && !PosIsOutOfBounds(x + offsetX , y + offsetY)) { SetSecondaryTerrainOnWall(GetTileMut(offsetX + x , offsetY + y)); } - } - } - } + } + } + } - // Creating a lake doesn't mean we are done yet - // but it's likely that the next iteration will hit the tile - // stopping condition for secondary terrain, if not the river continues + // Creating a lake doesn't mean we are done yet + // but it's likely that the next iteration will hit the tile + // stopping condition for secondary terrain, if not the river continues // Alternate between horizontal and vertical movement each iteration if (dirX != 0) { @@ -4757,11 +4757,11 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP dirY = 0; } - if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { + if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { LABEL: - // Vertically out of bounds, stop - break; - } + // Vertically out of bounds, stop + break; + } } } @@ -4777,13 +4777,13 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP // Up to 200 attempts while (n < 200) { - rndX = DungeonRandRange(0, DUNGEON_MAX_SIZE_X); - rndY = DungeonRandRange(0, DUNGEON_MAX_SIZE_Y); + rndX = DungeonRandRange(0, DUNGEON_MAX_SIZE_X); + rndY = DungeonRandRange(0, DUNGEON_MAX_SIZE_Y); - if (rndX >= 1 && rndX < DUNGEON_MAX_SIZE_X - 1 && rndY >= 1 && rndY < DUNGEON_MAX_SIZE_Y - 1) + if (rndX >= 1 && rndX < DUNGEON_MAX_SIZE_X - 1 && rndY >= 1 && rndY < DUNGEON_MAX_SIZE_Y - 1) break; - n++; + n++; } if (n == 200) @@ -4791,36 +4791,36 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP // Make a 10x10 grid with TRUE on the boundary and FALSE on the interior for (x = 0; x < 10; x++) { - for (y = 0; y < 10; y++) { - if (x == 0 || x == 9 || y == 0 || y == 9) { - table[x][y] = TRUE; - } - else { - table[x][y] = FALSE; - } - } + for (y = 0; y < 10; y++) { + if (x == 0 || x == 9 || y == 0 || y == 9) { + table[x][y] = TRUE; + } + else { + table[x][y] = FALSE; + } + } } // Generate an "inverse lake" by spreading the TRUE values inwards for (n = 0; n < 80; n++) { - // Pick a random interior point on the 10x10 grid - x = DungeonRandInt(8) + 1; - y = DungeonRandInt(8) + 1; + // Pick a random interior point on the 10x10 grid + x = DungeonRandInt(8) + 1; + y = DungeonRandInt(8) + 1; - if (table[x - 1][y] || table[x + 1][y] || table[x][y - 1] || table[x][y + 1]) { - table[x][y] = TRUE; - } + if (table[x - 1][y] || table[x + 1][y] || table[x][y - 1] || table[x][y + 1]) { + table[x][y] = TRUE; + } } // Iterate through the grid, any spaces which are still FALSE form the inverse-inverse lake // or as some may prefer to call it, just a regular lake! for (x = 0; x < 10; x++) { - for (y = 0; y < 10; y++) { - if (!table[x][y]) { - // Shift the 0-10 random offset Position into +- 5 to center around the lake seed tile + for (y = 0; y < 10; y++) { + if (!table[x][y]) { + // Shift the 0-10 random offset Position into +- 5 to center around the lake seed tile SetSecondaryTerrainOnWall(GetTileMut(x + rndX - 5, y + rndY - 5)); - } - } + } + } } } @@ -4828,18 +4828,18 @@ static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorP for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { Tile *tile = GetTileMut(x, y); - if (GetTerrainType(tile) != TERRAIN_TYPE_SECONDARY) + if (GetTerrainType(tile) != TERRAIN_TYPE_SECONDARY) continue; - // Revert tiles back to open terrain if: - // - in a kecleon shop - // - in a monster house - // - is an unbreakable tile - // - on a stairs spawn point - // This really shouldn't happen since we only place terrain on wall tiles to begin with, - // but it provides additional safety + // Revert tiles back to open terrain if: + // - in a kecleon shop + // - in a monster house + // - is an unbreakable tile + // - on a stairs spawn point + // This really shouldn't happen since we only place terrain on wall tiles to begin with, + // but it provides additional safety - if (tile->terrainType & (TERRAIN_TYPE_SHOP | TERRAIN_TYPE_IN_MONSTER_HOUSE | TERRAIN_TYPE_UNBREAKABLE) || (tile->spawnOrVisibilityFlags & SPAWN_FLAG_STAIRS)) { + if (tile->terrainType & (TERRAIN_TYPE_SHOP | TERRAIN_TYPE_IN_MONSTER_HOUSE | TERRAIN_TYPE_UNBREAKABLE) || (tile->spawnOrVisibilityFlags & SPAWN_FLAG_STAIRS)) { SetTerrainNormal(tile); } else { @@ -5589,22 +5589,22 @@ bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) u16 terrain = GetTerrainType(tile); test[x][y] = 0; - if (markUnreachable) { - // Reset all unreachable flags on tiles, they'll be recomputed from scratch - tile->terrainType &= ~(TERRAIN_TYPE_UNREACHABLE_FROM_STAIRS); - } + if (markUnreachable) { + // Reset all unreachable flags on tiles, they'll be recomputed from scratch + tile->terrainType &= ~(TERRAIN_TYPE_UNREACHABLE_FROM_STAIRS); + } - if (terrain != TERRAIN_TYPE_NORMAL) { - if (!(tile->terrainType & TERRAIN_TYPE_CORNER_CUTTABLE)) { - test[x][y] |= STAIRS_FLAG_CANNOT_CORNER_CUT; - } - } + if (terrain != TERRAIN_TYPE_NORMAL) { + if (!(tile->terrainType & TERRAIN_TYPE_CORNER_CUTTABLE)) { + test[x][y] |= STAIRS_FLAG_CANNOT_CORNER_CUT; + } + } - if (terrain == TERRAIN_TYPE_SECONDARY) { - if (!(tile->terrainType & TERRAIN_TYPE_CORNER_CUTTABLE)) { - test[x][y] |= STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT; - } - } + if (terrain == TERRAIN_TYPE_SECONDARY) { + if (!(tile->terrainType & TERRAIN_TYPE_CORNER_CUTTABLE)) { + test[x][y] |= STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT; + } + } } } @@ -5623,36 +5623,36 @@ bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) sNumTilesReachableFromStairs += 1; for (x = 0; x < DUNGEON_MAX_SIZE_X; x++) { - for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - if (!(test[x][y] & STAIRS_FLAG_VISITED) && test[x][y] & STAIRS_FLAG_IN_VISIT_QUEUE) { - checked++; - test[x][y] &= ~(STAIRS_FLAG_IN_VISIT_QUEUE); - test[x][y] |= STAIRS_FLAG_VISITED; + for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { + if (!(test[x][y] & STAIRS_FLAG_VISITED) && test[x][y] & STAIRS_FLAG_IN_VISIT_QUEUE) { + checked++; + test[x][y] &= ~(STAIRS_FLAG_IN_VISIT_QUEUE); + test[x][y] |= STAIRS_FLAG_VISITED; - // Queue up in cardinal directions of this tile + // Queue up in cardinal directions of this tile - // Left - if (x > 0 && !(test[x - 1][y] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { - test[x - 1][y] |= STAIRS_FLAG_IN_VISIT_QUEUE; - } + // Left + if (x > 0 && !(test[x - 1][y] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x - 1][y] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } - // Up - if (y > 0 && !(test[x][y - 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { - test[x][y - 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; - } + // Up + if (y > 0 && !(test[x][y - 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x][y - 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } - // Right - if (x < DUNGEON_MAX_SIZE_X - 1 && !(test[x + 1][y] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { - test[x + 1][y] |= STAIRS_FLAG_IN_VISIT_QUEUE; - } + // Right + if (x < DUNGEON_MAX_SIZE_X - 1 && !(test[x + 1][y] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x + 1][y] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } - // Down - if (y < DUNGEON_MAX_SIZE_Y - 1 && !(test[x][y + 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { - test[x][y + 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; - } + // Down + if (y < DUNGEON_MAX_SIZE_Y - 1 && !(test[x][y + 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED))) { + test[x][y + 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; + } - // Up-left - if (x > 0 && y > 0 + // Up-left + if (x > 0 && y > 0 && !(test[x - 1][y - 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) && !(test[x - 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) && !(test[x][y - 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) @@ -5660,8 +5660,8 @@ bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) test[x - 1][y - 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; } - // Up-Right - if (x < DUNGEON_MAX_SIZE_X - 1 && y > 0 + // Up-Right + if (x < DUNGEON_MAX_SIZE_X - 1 && y > 0 && !(test[x + 1][y - 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) && !(test[x + 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) && !(test[x][y - 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) @@ -5669,8 +5669,8 @@ bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) test[x + 1][y - 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; } - // Down-left - if (x > 0 && y < DUNGEON_MAX_SIZE_Y - 1 + // Down-left + if (x > 0 && y < DUNGEON_MAX_SIZE_Y - 1 && !(test[x - 1][y + 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) && !(test[x - 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) && !(test[x][y + 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) @@ -5678,16 +5678,16 @@ bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) test[x - 1][y + 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; } - // Down-right - if (x < DUNGEON_MAX_SIZE_X - 1 && y < DUNGEON_MAX_SIZE_Y - 1 + // Down-right + if (x < DUNGEON_MAX_SIZE_X - 1 && y < DUNGEON_MAX_SIZE_Y - 1 && !(test[x + 1][y + 1] & (STAIRS_FLAG_CANNOT_CORNER_CUT | STAIRS_FLAG_SECONDARY_TERRAIN_CANNOT_CORNER_CUT | STAIRS_FLAG_VISITED | STAIRS_FLAG_UNKNOWN)) && !(test[x + 1][y] & STAIRS_FLAG_CANNOT_CORNER_CUT) && !(test[x][y + 1] & STAIRS_FLAG_CANNOT_CORNER_CUT)) { test[x + 1][y + 1] |= STAIRS_FLAG_IN_VISIT_QUEUE; } - } - } + } + } } if (checked == 0) @@ -5705,10 +5705,10 @@ bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable) } else { // unbreakable tiles can't really be navigated onto anyways, so if - // we can ignore the tile (otherwise it's a problem!) - if (!(tile->terrainType & TERRAIN_TYPE_UNBREAKABLE)) { + // we can ignore the tile (otherwise it's a problem!) + if (!(tile->terrainType & TERRAIN_TYPE_UNBREAKABLE)) { return FALSE; - } + } } } } @@ -5727,21 +5727,21 @@ static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LE for (x = 0; x < gridSizeX; var_48++, x++) { s32 minX = listX[x] + 2; s32 minY = listY[y] + 2; - s32 rangeX = listX[x + 1] - listX[x] - 4; - s32 rangeY = listY[y + 1] - listY[y] - 4; - s32 minRoomSizeX = 5; - s32 minRoomSizeY = 5; + s32 rangeX = listX[x + 1] - listX[x] - 4; + s32 rangeY = listY[y + 1] - listY[y] - 4; + s32 minRoomSizeX = 5; + s32 minRoomSizeY = 5; - if (gridSizeX <= 2) { + if (gridSizeX <= 2) { minRoomSizeX = 10; rangeX = 14; - } - if (gridSizeY == 1) { + } + if (gridSizeY == 1) { minRoomSizeY = 16; rangeY = 24; - } + } - if (grid[x][y].isRoom) { + if (grid[x][y].isRoom) { // This cell is a room! s32 roomSizeX, roomSizeY; s32 startX, endX; @@ -5782,26 +5782,26 @@ static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LE endY = startY + fixedRoomSizeY; } - // Create the room! - grid[x][y].start.x = startX; + // Create the room! + grid[x][y].start.x = startX; grid[x][y].end.x = endX; - grid[x][y].start.y = startY; - grid[x][y].end.y = endY; + grid[x][y].start.y = startY; + grid[x][y].end.y = endY; - for (roomX = startX; roomX < endX; roomX++) { - for (roomY = startY; roomY < endY; roomY++) { + for (roomX = startX; roomX < endX; roomX++) { + for (roomY = startY; roomY < endY; roomY++) { SetTerrainNormal(GetTileMut(roomX, roomY)); GetTileMut(roomX, roomY)->room = roomNumber; - } - } + } + } - if (var_48 != a5) { + if (var_48 != a5) { grid[x][y].flagSecondaryStructure = TRUE; - } + } - roomNumber++; - } - else { + roomNumber++; + } + else { // This cell is not a room, create a 1x1 hallway anchor s32 pt_x, pt_y; s32 unk_x1 = 2; @@ -5809,34 +5809,34 @@ static void CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LE s32 unk_y1 = 2; s32 unk_y2 = 4; - if (x == 0) { - unk_x1 = 1; - } - if (y == 0) { - unk_y1 = 1; - } + if (x == 0) { + unk_x1 = 1; + } + if (y == 0) { + unk_y1 = 1; + } if (x == gridSizeX - 1) { - unk_x2 = 2; - } - if (y == gridSizeY - 1) { - unk_y2 = 2; - } + unk_x2 = 2; + } + if (y == gridSizeY - 1) { + unk_y2 = 2; + } pt_x = DungeonRandRange(minX + unk_x1, minX + rangeX - unk_x2); pt_y = DungeonRandRange(minY + unk_y1, minY + rangeY - unk_y2); - grid[x][y].start.x = pt_x; + grid[x][y].start.x = pt_x; grid[x][y].end.x = pt_x + 1; - grid[x][y].start.y = pt_y; - grid[x][y].end.y = pt_y + 1; + grid[x][y].start.y = pt_y; + grid[x][y].end.y = pt_y + 1; - // Flag the tile as open to serve as a hallway anchor - SetTerrainNormal(GetTileMut(pt_x, pt_y)); + // Flag the tile as open to serve as a hallway anchor + SetTerrainNormal(GetTileMut(pt_x, pt_y)); - // Set the room index to 0xFE for anchor - GetTileMut(pt_x, pt_y)->room = CORRIDOR_ROOM; - } + // Set the room index to 0xFE for anchor + GetTileMut(pt_x, pt_y)->room = CORRIDOR_ROOM; + } } } } From ab308c9547feb78bd6bf1a1c6ced74a23844ca8c Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Wed, 20 Nov 2024 18:43:54 -0500 Subject: [PATCH 28/30] Fix typo --- include/constants/direction.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/direction.h b/include/constants/direction.h index 73fbdea0e..2e3d5abb1 100644 --- a/include/constants/direction.h +++ b/include/constants/direction.h @@ -2,7 +2,7 @@ #define GUARD_CONSTANTS_DIRECTION_H #define DIRECTION_MASK 7 -#define DIRECTION_MASK_CARDINAL 6 // Only South, Easy, North and West +#define DIRECTION_MASK_CARDINAL 6 // Only South, East, North and West enum Direction { From d53a2666cd6720d66a94eeeb6834d8885dff9e09 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Wed, 20 Nov 2024 18:47:52 -0500 Subject: [PATCH 29/30] Removed unnecessary fill --- include/structs/str_806B7F8.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/structs/str_806B7F8.h b/include/structs/str_806B7F8.h index f3f804755..444aba579 100644 --- a/include/structs/str_806B7F8.h +++ b/include/structs/str_806B7F8.h @@ -9,7 +9,6 @@ struct unkStruct_806B7F8 u8 unk2; u32 unk4; u16 level; - u8 fillA[2]; DungeonPos pos; u8 unk10; }; From bba5f35836ca90cfe90787605dc4463a354c2505 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Wed, 20 Nov 2024 18:52:43 -0500 Subject: [PATCH 30/30] Add missing comment offsets to Dungeon struct --- include/structs/str_dungeon.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 80fe9eb77..ec6ecaefd 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -334,7 +334,7 @@ typedef struct Dungeon Entity *unkBC; u8 fillC0[0x134 - 0xC0]; struct unkStruct_Dungeon134_sub unk134; - RGB colorRamp[0x100]; + /* 0x47C */ RGB colorRamp[0x100]; /* 0x57C */ u8 fill57C[0x5C0 - 0x57c]; /* 0x5C0 */ s32 unk5C0; /* 0x5C4 */ struct unkStruct_Dungeon5C4_sub unk5C4[3]; @@ -376,9 +376,9 @@ typedef struct Dungeon /* 0x3A16 */ s16 unk3A16; /* 0x3A18 */ Tile tiles[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X]; /* 0xEA18 */ DungeonPos playerSpawn; - DungeonPos stairsSpawn; // stairs location + /* 0xEA1C */ DungeonPos stairsSpawn; // stairs location DungeonPos unkE220[8]; - struct MinMaxPosition kecleonShopPos; + /* 0xEA24 */ struct MinMaxPosition kecleonShopPos; struct MinMaxPosition unkE250; unkDungeonE260 unkE260; /* 0xE264 */ Weather weather; // Uses the weather constants in weather.h. @@ -428,7 +428,7 @@ typedef struct Dungeon /* 0x181E8 */ UnkDungeonGlobal_unk181E8_sub unk181e8; u8 fill18220[0x1BDD4 - 0x1822C]; struct UnkStructDungeon1BDD4 unk1BDD4; - struct MessageLogString messageLogStrings[MESSAGE_LOG_STRINGS_COUNT]; + /* 0x1BE14 */ struct MessageLogString messageLogStrings[MESSAGE_LOG_STRINGS_COUNT]; /* 0x1C570 */ DungeonLocation unk1C570; /* 0x1C574 */ FloorProperties unk1C574; /* 0x1C590 */ UnkDungeonGlobal_unk1C590 unk1C590[4];