diff --git a/asm/code_8040094.s b/asm/code_8040094.s index daab66df..8078324d 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 deleted file mode 100644 index 48d8e5dd..00000000 --- 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 deleted file mode 100644 index 0ef076df..00000000 --- a/asm/code_804FD30.s +++ /dev/null @@ -1,4521 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .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 GetTileMut - 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 sub_8043D10 - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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} - 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 sub_804FED0 - 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 GetTileMut - 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 sub_804FED0 - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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} - 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 GetTileMut - 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 GetTileMut - 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} - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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: - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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 GetTileMut - 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} - 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 GetTileMut - 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 GetTileMut - 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} - 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 gUnknown_202F1B8 -_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 gUnknown_202F1B8 -_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 gUnknown_202F1B8 -_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 sub_804FD10 - 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 sub_804FD10 - 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: - 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} - 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_805D8C8.s b/asm/code_805D8C8.s index da22012a..05471bbe 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/asm/code_807CD9C.s b/asm/code_807CD9C.s index 604aa7ce..6e202bc8 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/asm/code_807E5AC.s b/asm/code_807E5AC.s index eaf80cb0..084893b9 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 f86f4a60..e3bfc4be 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/constants/direction.h b/include/constants/direction.h index 7c5cec5c..2e3d5abb 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, East, North and West enum Direction { diff --git a/include/dungeon_generation.h b/include/dungeon_generation.h new file mode 100644 index 00000000..9e37dd96 --- /dev/null +++ b/include/dungeon_generation.h @@ -0,0 +1,63 @@ +#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 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, + FLOOR_SIZE_MEDIUM, +}; + +enum FloorType { + FLOOR_TYPE_NORMAL, + FLOOR_TYPE_FIXED, // Fixed room + 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. +}; + +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/global.h b/include/global.h index e833a584..c9f7791a 100644 --- a/include/global.h +++ b/include/global.h @@ -39,4 +39,14 @@ #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)) + #endif // GUARD_GLOBAL_H diff --git a/include/pokemon.h b/include/pokemon.h index b6418a07..79496cbc 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -102,6 +102,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/include/structs/map.h b/include/structs/map.h index b2127b92..f5f3b5c2 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -5,22 +5,26 @@ #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 { + 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 TERRAIN_TYPE_IN_MONSTER_HOUSE = 1 << 6, // x40 - TERRAIN_TYPE_UNK_8 = 1 << 8, // x100 + TERRAIN_TYPE_UNK_7 = 1 << 7, // x80 + 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, TERRAIN_TYPE_UNK_x1000 = 1 << 12, + TERRAIN_TYPE_UNREACHABLE_FROM_STAIRS = 1 << 15, // 0x8000 }; enum CrossableTerrain @@ -32,13 +36,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/include/structs/str_806B7F8.h b/include/structs/str_806B7F8.h new file mode 100644 index 00000000..444aba57 --- /dev/null +++ b/include/structs/str_806B7F8.h @@ -0,0 +1,18 @@ +#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; + 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 e6866cf7..ec6ecaef 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -116,37 +116,41 @@ 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 +// 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 unk1; + u8 layout; + s8 roomDensity; u8 unk2; u8 unk3; u8 unk4; - u8 unk5; - u8 unk6; - u8 unk7; - u8 unk8; - u8 unk9; + u8 floorConnectivity; + u8 enemyDensity; + 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; u8 unk18; - u8 unk19; + u8 itemlessMonsterHouseChance; // Chance that a monster house will be itemless u8 unk1A; -} UnkDungeonGlobal_unk1C574; +} FloorProperties; typedef struct UnkDungeonGlobal_unk1C590 { @@ -234,6 +238,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: 0x58 typedef struct unkDungeon644 { @@ -277,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; @@ -284,15 +298,6 @@ typedef struct unkDungeon644 /* 0x55 */ u8 unk55; } unkDungeon644; -// size: 0x10 -typedef struct unkDungeonE240 -{ - /* 0x0 */ u32 unk0; - /* 0x4 */ u32 unk4; - /* 0x8 */ u32 unk8; - /* 0xC */ u32 unkC; -} unkDungeonE240; - // size: 0x4 typedef struct unkDungeonE260 { @@ -329,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]; @@ -356,30 +361,30 @@ typedef struct Dungeon // dungeon_serializer.c refers to this as a u16 but elsewhere it's handled as a s16 /* 0x3800 */ s16 deoxysForm; Item unk3804[DUNGEON_MAX_ITEMS]; - /* 0x3904 */ s16 unk3904; + /* 0x3904 */ s16 numItems; Trap unk3908[DUNGEON_MAX_TRAPS]; - /* 0x3A08 */ bool8 unk3A08; + /* 0x3A08 */ bool8 forceMonsterHouse; // Forces the current floor to have monster house /* 0x3A09 */ bool8 unk3A09; /* 0x3A0A */ bool8 unk3A0A; /* 0x3A0B */ bool8 unk3A0B; - u8 unk3A0C; + /* 0x3A0C */ u8 monsterHouseRoom; // room index of monster house /* 0x3A0D */ u8 unk3A0D; /* 0x3A0E */ s16 tileset; /* 0x3A10 */ s16 unk3A10; /* 0x3A12 */ s16 unk3A12; - /* 0x3A14 */ s16 bossBattleIndex; + /* 0x3A14 */ s16 fixedRoomNumber; /* 0x3A16 */ s16 unk3A16; /* 0x3A18 */ Tile tiles[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X]; - DungeonPos unkE218; - DungeonPos unkE21C; // stair location? + /* 0xEA18 */ DungeonPos playerSpawn; + /* 0xEA1C */ DungeonPos stairsSpawn; // stairs location DungeonPos unkE220[8]; - unkDungeonE240 unkE240; - unkDungeonE240 unkE250; + /* 0xEA24 */ struct MinMaxPosition kecleonShopPos; + struct MinMaxPosition unkE250; unkDungeonE260 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]; @@ -393,7 +398,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; @@ -422,9 +428,9 @@ 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 */ UnkDungeonGlobal_unk1C574 unk1C574; + /* 0x1C574 */ FloorProperties unk1C574; /* 0x1C590 */ UnkDungeonGlobal_unk1C590 unk1C590[4]; u16 unk1CD70[20]; UnkDungeonGlobal_unk1CD98 unk1CD98[32]; diff --git a/ld_script.txt b/ld_script.txt index cfc2ea80..79bfe76e 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -226,9 +226,7 @@ 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.o(.text); - asm/code_804FD30.o(.text); + src/dungeon_generation.o(.text); src/dungeon_message.o(.text); src/dungeon_move.o(.text); src/move_actions.o(.text); diff --git a/src/code_803D110.c b/src/code_803D110.c index 3436c5a5..940608aa 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -17,7 +17,7 @@ extern s16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0); extern u32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0); extern void sub_808E9C4(UnkDungeonGlobal_unk1CD98 *r0, s16 r1); 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); @@ -53,7 +53,7 @@ struct UnkDungeonFileData struct UnkDataFileStruct { struct UnkDungeonFileData **unk0; - UnkDungeonGlobal_unk1C574 *unk4; + FloorProperties *unk4; u16 **unk8; UnkDungeonGlobal_unk1CD98 **unkC; u16 **unk10; @@ -1065,7 +1065,7 @@ void sub_803E13C(void) void sub_803E178(void) { - s32 val = sub_8043D10(); + s32 val = GetFloorType(); if (val == 0) { if (gDungeon->unk644.dungeonLocation.id == DUNGEON_METEOR_CAVE && !gDungeon->deoxysDefeat) { diff --git a/src/code_8040094.c b/src/code_8040094.c index 4386cd74..323f7a10 100644 --- a/src/code_8040094.c +++ b/src/code_8040094.c @@ -26,7 +26,6 @@ extern const char *gUnknown_80FD040; // It became brighter on the floor // Luminous Orb??? void HandleLuminousOrbAction(Entity *pokemon) { - Tile *mapTile; int XCoord; int YCoord; @@ -36,8 +35,8 @@ void HandleLuminousOrbAction(Entity *pokemon) { for(XCoord = 0; XCoord < DUNGEON_MAX_SIZE_X; XCoord++) { - mapTile = GetTileMut(XCoord, YCoord); - mapTile->unk4 = mapTile->unk4 | 1; + Tile *mapTile = GetTileMut(XCoord, YCoord); + mapTile->spawnOrVisibilityFlags |= 1; } } sub_803F580(0); diff --git a/src/code_804267C.c b/src/code_804267C.c index 36f0c9ef..594b049b 100644 --- a/src/code_804267C.c +++ b/src/code_804267C.c @@ -28,7 +28,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 @@ -38,7 +38,7 @@ void PlayStairsSound(void) songIndex = 997; - switch (sub_8043D10()) { + switch (GetFloorType()) { case 0: default: songIndex = IsStairDirectionUp(gDungeon->unk644.dungeonLocation.id) ? 340 : 341; diff --git a/src/code_8042B34.c b/src/code_8042B34.c index 89bbcd7c..5630bb3d 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" @@ -310,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); @@ -387,7 +387,7 @@ extern Entity *gLeaderPointer; void EnforceMaxItemsAndMoney(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; @@ -606,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->bossBattleIndex = gDungeon->unk1C574.unk12; + gDungeon->fixedRoomNumber = gDungeon->unk1C574.unk12; sub_807E5E4(0); sub_80842F0(); } @@ -636,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; } @@ -747,7 +747,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); } @@ -868,7 +868,7 @@ void xxx_dungeon_8042F6C(struct UnkStruct_xxx_dungeon_8042F6C *r8) sub_8083AB0(var, NULL, GetLeader()); check = TRUE; } - else if (gDungeon->unk644.unk34 == 1 && sub_8043D10() == 2 && gDungeon->unk644.unk10 == 2) { + else if (gDungeon->unk644.unk34 == 1 && GetFloorType() == FLOOR_TYPE_RESCUE && gDungeon->unk644.unk10 == 2) { sub_8083AB0(0x228, NULL, GetLeader()); if (gDungeon->unk644.unk2A != 0) { IncrementThievingSuccesses(); @@ -990,14 +990,14 @@ bool8 sub_8043CE4(s32 dungeonId) return (gDungeonWaterType[dungeonId] == 2); } -u8 sub_8043D10(void) +u8 GetFloorType(void) { if (gDungeon->unk644.unk34 == 1 && gDungeon->unk644.unk8.unk1 == gDungeon->unk644.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 826c6726..ca7285cf 100644 --- a/src/code_8044CC8.c +++ b/src/code_8044CC8.c @@ -25,17 +25,14 @@ EWRAM_DATA unkStruct_202EE44 gUnknown_202EE44[10] = {0}; extern s32 gUnknown_202EE6C; - - extern const ItemText gActions[]; extern u16 gUnknown_80F6964[NUM_ITEM_CATEGORIES]; extern u8 gUnknown_80F697C[]; extern u8 *gUnknown_80F7C50[10]; extern const unkStr_80F7C54 gUnknown_80F7C54[65]; extern u8 *gUnknown_80F91EC[]; - -extern u8 sub_8043D10(void); extern bool8 sub_8045888(Entity *); +extern u8 GetFloorType(void); void sub_80460F8(DungeonPos *, Item *, u32); bool8 sub_80461C8(DungeonPos *, u32); @@ -169,7 +166,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_80450F8.c b/src/code_80450F8.c index 38f2308b..4ef646b6 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/code_8045A00.c b/src/code_8045A00.c index 28f217f5..7ad221a5 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++; @@ -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 deleted file mode 100644 index f46979a1..00000000 --- a/src/code_804AFAC.c +++ /dev/null @@ -1,152 +0,0 @@ -#include "global.h" -#include "dungeon_map_access.h" -#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 = GetTileMut(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) -{ - 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 = GetTileMut(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 = GetTileMut(x,y); - tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - } - } - } -} - -void sub_804FD10(Tile *tile) -{ - tile->terrainType = 0; - tile->unk4 = 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(GetTileMut(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))) - { - GetTileMut(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_8066D04.c b/src/code_8066D04.c index 80adc540..fb3bad1c 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); SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],entity,0); LogMessageByIdWithPopupCheckUser(entity,*gUnknown_80F8E28); - sub_807AB38(entity,gDungeon->unk3A08); + sub_807AB38(entity,gDungeon->forceMonsterHouse); } } else diff --git a/src/code_806CD90.c b/src/code_806CD90.c index 4bfc2369..71eebcbc 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/code_806FDF4.c b/src/code_806FDF4.c index 102d817c..5389801d 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->fixedRoomNumber - 4))) && (gDungeon->fixedRoomNumber != 9) && (gDungeon->fixedRoomNumber != 0xf)) { + if ((u16)(gDungeon->fixedRoomNumber - 0x2cU) < 5) { if (gDungeon->unk644.unk18 == 0) { return FALSE; } } - else if (gDungeon->bossBattleIndex == 0x31) { + else if (gDungeon->fixedRoomNumber == 0x31) { if (gDungeon->unk644.unk15 == 0) { return FALSE; } diff --git a/src/code_80718D8.c b/src/code_80718D8.c index fe04658e..e444e432 100644 --- a/src/code_80718D8.c +++ b/src/code_80718D8.c @@ -16,17 +16,7 @@ #include "pokemon_3.h" #include "status_checks_1.h" #include "code_805D8C8.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}; @@ -61,7 +51,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); @@ -123,7 +112,7 @@ void sub_8071B48(void) } } if (dungeon->unk644.unk2A == 0) { - if (gDungeon->unk3A0C == 0xff) { + if (gDungeon->monsterHouseRoom == 0xff) { if (counter >= gUnknown_80F4DA6) { return; } diff --git a/src/code_8072B78.c b/src/code_8072B78.c index cee32ad6..45acc4a2 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/code_8073CF0.c b/src/code_8073CF0.c index 2d69cbaf..f5136b62 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 81986f84..6878c324 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); } } } @@ -215,13 +215,11 @@ _0807D11E: sub_803E46C(0x1a); } -void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, - DungeonPos *pos) +void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) { EntityInfo *info; u32 direction; DungeonPos local_2c; - DungeonPos pos2; bool8 flag; info = GetEntInfo(target); @@ -238,8 +236,8 @@ void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, } if (param_3 == 1) { - pos2 = gDungeon->unkE21C; - if(pos2.x == target->pos.x && pos2.y == target->pos.y) { + DungeonPos 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; @@ -274,7 +272,7 @@ void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, } break; case 1: - if (!sub_808384C(&local_2c,&gDungeon->unkE21C)) { + if (!sub_808384C(&local_2c,&gDungeon->stairsSpawn)) { local_2c = target->pos; flag = TRUE; } @@ -323,7 +321,7 @@ void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, 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 8aa35e67..8814d522 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/code_80848F0.c b/src/code_80848F0.c index a285e257..e6efa7ce 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 fixedRoomNumber; 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; + fixedRoomNumber = gDungeon->fixedRoomNumber; + if (fixedRoomNumber - 0x1c < 0x16) { + fixedRoomNumber = 0x1b; } - if (bossBattleIndex == gUnknown_8107234[index].unk0[0]) + if (fixedRoomNumber == gUnknown_8107234[index].unk0[0]) { sub_8084854(&gUnknown_8107234[index]); break; diff --git a/src/dungeon_action.c b/src/dungeon_action.c index 97e9f0d6..4d466d22 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/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 2ed23d4f..dee20d6f 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_engine.c b/src/dungeon_engine.c index 71dae7ea..e06cd468 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->fixedRoomNumber != 0 && gDungeon->fixedRoomNumber <= 0x31) { return TRUE; } diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c new file mode 100644 index 00000000..7f8698f1 --- /dev/null +++ b/src/dungeon_generation.c @@ -0,0 +1,6448 @@ +#include "global.h" +#include "dungeon_generation.h" +#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" +#include "structs/str_dungeon.h" +#include "structs/map.h" +#include "structs/str_806B7F8.h" + +extern const u8 gUnknown_80F6DCC[]; +extern struct FileArchive gDungeonFileArchive; + +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 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 +{ + DungeonPos start; + DungeonPos 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 + +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); +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); +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]); +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; +static EWRAM_DATA bool8 sHasKecleonShop = 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; +static EWRAM_DATA struct MinMaxPosition sKecleonShopPosition = {0}; +static EWRAM_DATA s32 sSecondaryStructuresBudget = 0; +static EWRAM_DATA s32 sNumRooms = 0; +static EWRAM_DATA s32 sFloorLayout = 0; +static EWRAM_DATA s32 sNumTilesReachableFromStairs = 0; +static EWRAM_DATA DungeonPos sKecleonShopMiddlePos = {0}; + +// Helper functions for terrain flags +static inline void SetTerrainType(Tile *tile, u32 terrainType) +{ + tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + tile->terrainType |= terrainType; +} + +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(const 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; +}; + +/* + * 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 spawnAttempts; + bool8 secondaryGen = FALSE; + FloorProperties *floorProps = &gDungeon->unk1C574; + + gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); + sHasKecleonShop = FALSE; + sHasMonsterHouse = 0; + sHasMaze = FALSE; + gUnknown_202F1A8 = (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_WATER); + sStairsRoomIndex = 0xFF; + sFloorSize = 0; + sKecleonShopChance = floorProps->kecleonShopChance; + sMonsterHouseChance = floorProps->monsterHouseChance; + sSecondSpawn = TRUE; + sKecleonShopPosition.minX = -1; + sKecleonShopPosition.maxX = -1; + sKecleonShopPosition.minY = -1; + sKecleonShopPosition.maxY = -1; + + ResetFloor(); + + gDungeon->unk644.unk20 = abs(floorProps->enemyDensity); + + gDungeon->unk3A09 = 0; + gDungeon->unk3A0A = 0; + + sSecondaryStructuresBudget = floorProps->secondaryStructuresBudget; + + 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; + // Actual generation attempts, up to 10 times per entity + for (genAttempts = 0; genAttempts < 10; genAttempts++) { + gDungeon->unk3A16 = genAttempts; + if (genAttempts > 0) { + sSecondaryStructuresBudget = 0; + } + sInvalidGeneration = FALSE; + sKecleonShopMiddlePos.x = -1; + sKecleonShopMiddlePos.y = -1; + + ResetFloor(); + + gDungeon->playerSpawn.x = -1; + gDungeon->playerSpawn.y = -1; + gDungeon->forceMonsterHouse = FALSE; + if (gDungeon->fixedRoomNumber != 0) { + // Check for a full-floor fixed room, if this is the case, generation is done. + if (ProcessFixedRoom(gDungeon->fixedRoomNumber, floorProps)) { + break; + } + } + else { + s32 gridSizeX, gridSizeY; + s32 attempts; + u8 layout = floorProps->layout; + + // Attempt to generate random grid dimensions + attempts = 32; + while (1) { + if (layout != LAYOUT_LARGE_0x8) { + gridSizeX = DungeonRandRange(2, 9); + gridSizeY = DungeonRandRange(2, 8); + } + else { + gridSizeX = DungeonRandRange(2, 5); + gridSizeY = DungeonRandRange(2, 4); + } + + // Limit overall dimensions + if (gridSizeX <= 6 && gridSizeY <= 4) { + break; + } + if (--attempts == 0) { + // We failed to generate random grid dimensions, default to 4x4 + gridSizeX = 4; + gridSizeY = 4; + break; + } + } + + // 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 / gridSizeY < 8) { + gridSizeY = 1; + } + + gDungeon->forceMonsterHouse = FALSE; + gDungeon->monsterHouseRoom = 0xFF; + 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 LAYOUT_MEDIUM: + gridSizeX = 4; + gridSizeY = DungeonRandInt(2) + 2; + sFloorSize = FLOOR_SIZE_MEDIUM; + GenerateStandardFloor(gridSizeX, gridSizeY, floorProps); + secondaryGen = TRUE; + break; + case LAYOUT_LARGE: + case LAYOUT_LARGE_0x8: + default: + GenerateStandardFloor(gridSizeX, gridSizeY, floorProps); + secondaryGen = TRUE; + break; + case LAYOUT_ONE_ROOM_MONSTER_HOUSE: + GenerateOneRoomMonsterHouseFloor(); + gDungeon->forceMonsterHouse = TRUE; + break; + case LAYOUT_OUTER_RING: + GenerateOuterRingFloor(floorProps); + secondaryGen = TRUE; + break; + case LAYOUT_CROSSROADS: + GenerateCrossroadsFloor(floorProps); + secondaryGen = TRUE; + break; + case LAYOUT_TWO_ROOMS_WITH_MONSTER_HOUSE: + GenerateTwoRoomsWithMonsterHouseFloor(); + gDungeon->forceMonsterHouse = TRUE; + break; + case LAYOUT_LINE: + GenerateLineFloor(floorProps); + secondaryGen = TRUE; + break; + case LAYOUT_CROSS: + GenerateCrossFloor(floorProps); + break; + case LAYOUT_BEETLE: + GenerateBeetleFloor(floorProps); + break; + case LAYOUT_OUTER_ROOMS: + GenerateOuterRoomsFloor(gridSizeX, gridSizeY, floorProps); + secondaryGen = TRUE; + break; + } + } + + ResetInnerBoundaryTileRows(); + EnsureImpassableTilesAreWalls(); + + // 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) { + roomTiles++; + if (tile->room < 64) { + rooms[tile->room] = TRUE; + } + } + } + } + + numRooms = 0; + // In order to match, 'y' had to be re-used as an iterator var + for (y = 0; y < 64; y++) { + if (rooms[y]) { + numRooms++; + } + } + + if (roomTiles >= 30 && numRooms >= 2) { + break; // This layout is good! + } + } + } + + // 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 = TRUE; + } + + // We will be guaranteed to have a good layout by this point + FinalizeJunctions(); + if (secondaryGen) { + GenerateSecondaryTerrainFormations(ROOM_FLAG_ALLOW_SECONDARY_TERRAIN, floorProps); + } + + 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 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; + + 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.minX >= 0) { + sub_8051654(floorProps); + gDungeon->unk3A0A = 1; + } + else { + gDungeon->unk3A0A = 0; + } + + sub_804B534(0, 0, DUNGEON_MAX_SIZE_X, DUNGEON_MAX_SIZE_Y); + if (gUnknown_202F1A8) { + sub_804FC74(); + } + + CloseFile(gDungeon->unk13568); +} + +static 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 = GetTileMut(x, y); + + 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++; + if (y > 0 && (GetTerrainType(GetTile(x, y - 1)) == TERRAIN_TYPE_NORMAL)) + unkCount++; + 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 && (GetTerrainType(GetTile(x, y + 1)) == TERRAIN_TYPE_NORMAL)) + unkCount++; + + if (unkCount > 2) { + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + } + } + } + } +} + +/* + * GenerateStandardFloor - Generates a standard, typical floor layout. + * + * Overview: + * 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 + * 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 + */ +static void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + + GetGridPositions(listX, listY, gridSizeX, gridSizeY); + + InitDungeonGrid(grid, gridSizeX, gridSizeY); + + AssignRooms(grid, gridSizeX, gridSizeY, floorProps->roomDensity); + + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); + + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, floorProps); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); + + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + + GenerateMazeRoom(grid, gridSizeX, gridSizeY, floorProps->mazeRoomChance); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); + + 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. +static void GenerateOuterRingFloor(FloorProperties *floorProps) +{ + 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; + + listX[0] = 0; + listX[1] = 5; + listX[3] = 28; + listX[5] = 51; + listX[6] = 56; + listX[2] = 16; + listX[4] = 39; + + listY[0] = 2; + listY[1] = 7; + listY[2] = 16; + listY[3] = 25; + listY[4] = 30; + + 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(GetTileMut(curX, curY)); + GetTileMut(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(GetTileMut(startX, startY)); + GetTileMut(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, floorProps); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); + + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); + + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); +} + +/* + * GenerateCrossroadsFloor - Generates a floor layout with hallways on the inside and rooms on the outside, with empty corners. + * Also nicknamed "Ladder Layout" by some. + */ +static void GenerateCrossroadsFloor(FloorProperties *floorProps) +{ + 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 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 = 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 + 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(GetTileMut(startX, startY)); + GetTileMut(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, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); + + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); +} + +// GenerateLineFloor - Generates a floor layout with 5 grid cells in a horizontal line. +static void GenerateLineFloor(FloorProperties *floorProps) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 gridSizeX, gridSizeY; + bool8 disableRoomMerging; + + listX[0] = 0; + listX[1] = 11; + listX[2] = 22; + listX[3] = 33; + listX[4] = 44; + listX[5] = 56; + + listY[0] = 4; + listY[1] = 15; + + disableRoomMerging = 1; + gridSizeX = 5, gridSizeY = 1; + InitDungeonGrid(grid, gridSizeX, gridSizeY); + + AssignRooms(grid, gridSizeX, gridSizeY, floorProps->roomDensity); + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); + + AssignRandomGridCellConnections(grid, gridSizeX, gridSizeY, floorProps); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, disableRoomMerging); + + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); + + 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. +static void GenerateCrossFloor(FloorProperties *floorProps) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 x, y, gridSizeX, gridSizeY; + + listX[0] = 11; + listX[1] = 22; + listX[2] = 33; + listX[3] = 44; + + listY[0] = 2; + listY[1] = 11; + listY[2] = 20; + listY[3] = 30; + + gridSizeX = 3, gridSizeY = 3; + InitDungeonGrid(grid, gridSizeX, gridSizeY); + + // Set all cells as rooms + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + grid[x][y].isRoom = TRUE; + } + } + + // Invalidate the corners + grid[0][0].isInvalid = TRUE; + grid[2][0].isInvalid = TRUE; + grid[0][2].isInvalid = TRUE; + grid[2][2].isInvalid = TRUE; + + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); + + 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, gridSizeX, gridSizeY, listX, listY, TRUE); + + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); + + 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 +static void GenerateBeetleFloor(FloorProperties *floorProps) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 x, y, gridSizeX, gridSizeY; + + listX[0] = 5; + listX[1] = 15; + listX[2] = 35; + listX[3] = 50; + + listY[0] = 2; + listY[1] = 11; + listY[2] = 20; + listY[3] = 30; + + gridSizeX = 3, gridSizeY = 3; + InitDungeonGrid(grid, gridSizeX, gridSizeY); + // Set all cells as rooms + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + grid[x][y].isRoom = TRUE; + } + } + + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); + + // Connect rooms in the same row together + for (y = 0; y < 3; y++) { + grid[0][y].connectedToRight = TRUE; + grid[1][y].connectedToLeft = TRUE; + grid[1][y].connectedToRight = TRUE; + grid[2][y].connectedToLeft = 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, gridSizeX, gridSizeY, listX, listY); + + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); + + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); +} + +// MergeRoomsVertically - Merges two vertically stacked rooms into one larger room. +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][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][roomY1].start.x, grid[roomX][roomY1].start.y)->room; + + for (x = xStart; x < xEnd; x++) { + for (y = yStart; y < yEnd; y++) { + Tile *tile = GetTileMut(x, y); + SetTerrainNormal(tile); + tile->room = roomId; + } + } + + 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][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 gridSizeX < 3. +static void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 x, y; + s32 gridSizeX = gridSizeX_; + s32 gridSizeY = gridSizeY_; + + GetGridPositions(listX, listY, gridSizeX, gridSizeY); + InitDungeonGrid(grid, gridSizeX, gridSizeY); + + // Make all cells rooms + 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 < gridSizeX - 1; x++) { + for (y = 1; y < gridSizeY - 1; y++) { + grid[x][y].isInvalid = TRUE; + } + } + + CreateRoomsAndAnchors(grid, gridSizeX, gridSizeY, listX, listY, floorProps->roomFlags); + + // Maybe Todo: Add EpicYoshiMaster's fixed implementation of this function + + // 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 < gridSizeX - 1; x++) { + if (x != 0) { + grid[x][0].connectedToRight = TRUE; + grid[x][gridSizeY-1].connectedToRight = TRUE; + } + + // Bug: if gridSizeX <= 2, this branch will never be run. + // Additionally, because the branch above this has no meaningful hallways produced for + // 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][gridSizeY-1].connectedToLeft = TRUE; + } + } + + for (y = 0; y < gridSizeY - 1; y++) { + if (y != 0) { + grid[0][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 < gridSizeY - 2) { + grid[0][y].connectedToBottom = TRUE; + grid[gridSizeX-1][y].connectedToBottom = TRUE; + } + } + + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); + + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + + GenerateMazeRoom(grid, gridSizeX, gridSizeY, floorProps->mazeRoomChance); + GenerateKecleonShop(grid, gridSizeX, gridSizeY, sKecleonShopChance); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, sMonsterHouseChance); + + GenerateExtraHallways(grid, gridSizeX, gridSizeY, floorProps->numExtraHallways); + GenerateRoomImperfections(grid, gridSizeX, gridSizeY); + GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); +} + +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; + s32 gridSizeX, gridSizeY; + + if (fixedRoomSizeX == 0 || fixedRoomSizeY == 0) { + GenerateOneRoomMonsterHouseFloor(); + return FALSE; + } + else if (fixedRoomNumber < 50) { + sub_8051288(fixedRoomNumber); + return TRUE; + } + else { + gridSizeX = DUNGEON_MAX_SIZE_X / (fixedRoomSizeX + 4); + if (gridSizeX <= 1) + gridSizeX = 1; + gridSizeY = DUNGEON_MAX_SIZE_Y / (fixedRoomSizeY + 4); + if (gridSizeY <= 1) + gridSizeY = 1; + sub_804C790(gridSizeX, gridSizeY, fixedRoomSizeX, fixedRoomSizeY, fixedRoomNumber, floorProps); + return FALSE; + } +} + +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]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + s32 r10 = 0; + s32 cursorX = 0, cursorY = 0; + + GetGridPositions(listX, listY, gridSizeX, gridSizeY); + InitDungeonGrid(grid, gridSizeX, gridSizeY); + AssignRooms(grid, gridSizeX, gridSizeY, floorProps->roomDensity); + for (cursorX = 0; cursorX < gridSizeX; cursorX++) { + for (cursorY = 0; cursorY < gridSizeY; cursorY++) { + grid[cursorX][cursorY].unk27 = 1; + } + } + + for (tries = 0; tries < 64; tries++) { + cursorX = DungeonRandInt(gridSizeX); + cursorY = DungeonRandInt(gridSizeY); + r10 = cursorY * gridSizeX + cursorX; + if (grid[cursorX][cursorY].isRoom) + break; + } + CreateRoomsAndAnchorsForFixedFloor(grid, gridSizeX, gridSizeY, listX, listY, r10, fixedRoomSizeX, fixedRoomSizeY); + if (gridSizeX != 1 || gridSizeY != 1) { + AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, floorProps); + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, TRUE); + EnsureConnectedGrid(grid, gridSizeX, gridSizeY, listX, listY); + } + sub_8051438(&grid[cursorX][cursorY], fixedRoomNumber); +} + +/* + * 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. + */ +static void GenerateOneRoomMonsterHouseFloor(void) +{ + s32 x, y; + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + + InitDungeonGrid(grid, 1, 1); + + 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].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++) { + SetTerrainNormal(GetTileMut(x, y)); + GetTileMut(x, y)->room = 0; + } + } + GenerateMonsterHouse(grid, 1, 1, 999); +} + +// GenerateTwoRoomsWithMonsterHouseFloor - Generates a floor layout with two rooms (left and right), with one being a Monster House. +static void GenerateTwoRoomsWithMonsterHouseFloor(void) +{ + struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; + s32 listX[GRID_CELL_LEN]; + s32 listY[GRID_CELL_LEN]; + const s32 gridSizeX = 2; + const s32 gridSizeY = 1; + s32 currRoomId = 0; + s32 x, y; + + listX[0] = 2; + listX[1] = 28; + listX[2] = 54; + listY[0] = 2; + listY[1] = 30; + InitDungeonGrid(grid, gridSizeX, gridSizeY); + + 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; + 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].isRoom = TRUE; + 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++) { + SetTerrainNormal(GetTileMut(currX, currY)); + GetTileMut(currX, currY)->room = currRoomId; + } + } + currRoomId++; + } + } + + grid[0][0].connectedToRight = TRUE; + grid[1][0].connectedToLeft = TRUE; + + CreateGridCellConnections(grid, gridSizeX, gridSizeY, listX, listY, FALSE); + GenerateMonsterHouse(grid, gridSizeX, gridSizeY, 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. + */ +static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, 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(gridSizeX); + s32 y = DungeonRandInt(gridSizeY); + + // To generate extra hallways the cell must be: + // - a room + // - connected + // - valid + // - not a maze room + 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); + 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 >= gridSizeY - 1) { + direction = DIRECTION_EAST; + } + + if (direction == DIRECTION_EAST && x >= gridSizeX - 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 (GetTerrainType(GetTile(currX, currY)) != TERRAIN_TYPE_NORMAL) + break; + + currX += gAdjacentTileOffsets[direction].x; + currY += gAdjacentTileOffsets[direction].y; + } + + // Abort if we reached secondary terrain + if (GetTerrainType(GetTile(currX, currY)) == 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 (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 (GetTerrainType(GetTile(currX + checkX2, currY + checkY2)) == 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 (GetTerrainType(GetTile(currX, currY)) == TERRAIN_TYPE_NORMAL) + break; + 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) && + (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)) + { + 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; + } + + // 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) + 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) + 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 && 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; + } + } +} + +// GetGridPositions - Determines the starting positions of grid cells based on the given floor grid dimensions +static void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY) +{ + s32 i, sum; + + for (i = 0, sum = 0; i < gridSizeX; i++) { + listX[i] = sum; + sum += DUNGEON_MAX_SIZE_X / gridSizeX; + } + listX[gridSizeX] = sum; + + for (i = 0, sum = 0; i < gridSizeY; i++) { + listY[i] = sum; + sum += DUNGEON_MAX_SIZE_Y / gridSizeY; + } + listY[gridSizeY] = 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. + */ +static void InitDungeonGrid(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++) { + if (sFloorSize == 1 && x >= gridSizeX / 2) { + grid[x][y].isInvalid = TRUE; + } + else if (sFloorSize == 2 && x >= (gridSizeX * 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].isMonsterHouse = FALSE; + grid[x][y].isKecleonShop = FALSE; + grid[x][y].connectedToRight = FALSE; + grid[x][y].connectedToLeft = FALSE; + grid[x][y].connectedToBottom = FALSE; + grid[x][y].connectedToTop = 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; + grid[x][y].flagImperfect = FALSE; + grid[x][y].flagSecondaryStructure = 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. + */ + +#define ROOM_BITS_COUNT 256 // Despite max rooms being 32, randomRoomBits can hold up to 256 possible rooms +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; + 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 < ROOM_BITS_COUNT; i++) { + randomRoomBits[i] = FALSE; + } + + // Shuffle around the acceptable rooms + maxRooms = gridSizeX * gridSizeY; + + 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; + 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 (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++; + + // 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++; + } + } + + // We have at least 2 rooms, we're done. + if (sNumRooms >= 2) + return; + + 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) + 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; + } + + sSecondSpawn = FALSE; +} + +/* + * 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. + */ +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; + + 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(GetTileMut(roomX, roomY)); + GetTileMut(roomX, roomY)->room = roomNumber; + } + } + + flagImperfect = TRUE; + // Randomly flag the room for a secondary structure + flagSecondary = DungeonRandInt(100) < GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE; + if (sSecondaryStructuresBudget == 0) { + flagSecondary = FALSE; + } + + // 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) { + 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(GetTileMut(pt_x, pt_y)); + + // Set the room index to 0xFE for anchor + GetTileMut(pt_x, pt_y)->room = ROOM_0xFE; + } + } + } +} + +/* + * 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. + */ +static 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, FloorProperties *floorProps) +{ + s32 cursorX = DungeonRandInt(gridSizeX); + s32 cursorY = DungeonRandInt(gridSizeY); + + AssignGridCellConnections(grid, gridSizeX, gridSizeY, cursorX, cursorY, floorProps); +} + +/* + * 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. + * + */ + +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; + s32 y = cursorY; + s32 floorConnectivity = floorProps->floorConnectivity; + // 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 (floorProps->allowDeadEnds) + 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; + } +} + +/* + * 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. + * + */ +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; + + // 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 = GetTileMut(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 = GetTileMut(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 = GetTileMut(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 = GetTileMut(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; + } + } + } + } +} + +/* + * 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. + */ +static 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) + const 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(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; + } + } + } + } + } + } +} + +/* + * 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 + */ +static 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(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--; + } + } + + 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(GetTileMut(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(GetTileMut(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(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--; + } + } + + 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(GetTileMut(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(GetTileMut(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. + */ +static 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 = 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); + } + } + } + + // 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 = GetTileMut(curX, curY); + // Set it to wall terrain + SetTerrainWall(tile); + + // 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; + } + } + } + } +} + +/* + * 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. + */ +static void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomIndex) +{ + SetTerrainWall(tile); + if (useSecondaryTerrain && tile->room == roomIndex) { + SetTerrainSecondary(tile); + } +} + +/* + * 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 + */ +static void FinalizeJunctions(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; + + // 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) { + // 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); + } + } + } + // Tile below is in a room + if (y < DUNGEON_MAX_SIZE_Y - 1) { + Tile *tile = GetTileMut(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); + } + } + } + //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) { + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + tile->terrainType |= TERRAIN_TYPE_NATURAL_JUNCTION; + if (GetTerrainType(tile) == TERRAIN_TYPE_SECONDARY) { + SetTerrainType(tile, TERRAIN_TYPE_NORMAL); + } + } + } + } + // Hallway Anchor + else if (GetTile(x, y)->room == ROOM_0xFE) { + GetTileMut(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. + */ +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]; + s32 x, y; + s32 i, j; + Dungeon *dungeon = gDungeon; + + sKecleonShopMiddlePos.x = -1; + sKecleonShopMiddlePos.y = -1; + + if (sHasMonsterHouse || GetFloorType() == FLOOR_TYPE_RESCUE || 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 + sHasKecleonShop = TRUE; + grid[x][y].isKecleonShop = TRUE; + + // 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; + + 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; + + // 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); + + // 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++) { + 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; + + return; + } + } +} + +/* + * 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. + */ +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 + // - 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 (sHasKecleonShop) + return; + if (gDungeon->unk644.unk44 != 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! + 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++) { + GetTileMut(curX, curY)->terrainType |= TERRAIN_TYPE_IN_MONSTER_HOUSE; + dungeon->monsterHouseRoom = GetTile(curX, curY)->room; + } + } + return; + } + + i++; + } + } +} + +/* + * 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. + */ +static 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). + * + */ +static void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) +{ + s32 curX, curY; + u8 roomIndex; + + sHasMaze = 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(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); + } + } + } +} + +/* + * 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 DungeonPos (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. + */ +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); + s32 i = 0; + + SetTerrainObstacleChecked(GetTileMut(x0, y0), useSecondaryTerrain, roomIndex); + + while (1) { + s32 offsetX, offsetY; + s32 posX, posY; + + // 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; + 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 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; + } + } + } + + // 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(GetTileMut(x0 + 1, y0), useSecondaryTerrain, roomIndex); + + x0 += 2; + break; + case CARDINAL_DIR_UP: + SetTerrainObstacleChecked(GetTileMut(x0, y0 - 1), useSecondaryTerrain, roomIndex); + + y0 -= 2; + break; + case CARDINAL_DIR_LEFT: + SetTerrainObstacleChecked(GetTileMut(x0 - 1, y0), useSecondaryTerrain, roomIndex); + + x0 -= 2; + break; + case CARDINAL_DIR_DOWN: + SetTerrainObstacleChecked(GetTileMut(x0, y0 + 1), useSecondaryTerrain, roomIndex); + + y0 += 2; + break; + } + } +} + +static void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag) +{ + SetTerrainSecondary(tile); + tile->terrainType |= additionalFlag; +} + +/* + * SetSpawnFlag5 - Sets unknown spawn flag 0x5 on all tiles in a room + */ +static 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++) { + GetTileMut(x, y)->spawnOrVisibilityFlags |= SPAWN_FLAG_UNK5; + } + } +} + +/* + * IsNextToHallway - Checks if a tile DungeonPos is either in a hallway or next to one. + */ +static 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; +} + +// See GenerateSecondaryStructures for more information. +static 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 (sSecondaryStructuresBudget != 0) { + s32 i; + + sSecondaryStructuresBudget--; + + 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(GetTileMut(middleX, i), 0); + } + + 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 { + // 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(GetTileMut(i, middleY), 0); + } + + 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; + } + } + + 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 (sSecondaryStructuresBudget != 0) { + sSecondaryStructuresBudget--; + + SetSpawnFlag5(gridCell); + + // Water "Moat" + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 2, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 1, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX + 1, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 2, middleY - 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 2, middleY), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 2, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 2, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX - 1, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX + 1, middleY - 2), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX + 1, middleY - 1), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX + 1, middleY), TERRAIN_TYPE_CORNER_CUTTABLE); + SetTerrainSecondaryWithFlag(GetTileMut(middleX + 1, middleY + 1), TERRAIN_TYPE_CORNER_CUTTABLE); + + // Trap + GetTileMut(middleX - 1, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_TRAP; + // Warp Tile ? + GetTileMut(middleX - 1, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_UNK6; + + // Items + GetTileMut(middleX, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + GetTileMut(middleX - 1, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + GetTileMut(middleX, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_ITEM; + GetTileMut(middleX - 1, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; + GetTileMut(middleX, middleY - 1)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; + GetTileMut(middleX - 1, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; + GetTileMut(middleX, middleY)->spawnOrVisibilityFlags |= SPAWN_FLAG_SPECIAL_TILE; + + 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 (sSecondaryStructuresBudget != 0) { + sSecondaryStructuresBudget--; + + 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(GetTileMut(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 && sSecondaryStructuresBudget != 0) { + s32 i; + // Dimensions are odd, generate diagonal stripes/checkerboard of water/lava + sSecondaryStructuresBudget--; + + 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(GetTileMut(gridCell->start.x + randX, gridCell->start.y + randY), 0); + } + } + + gridCell->hasSecondaryStructure = TRUE; + } + break; + case SECONDARY_STRUCTURE_MAZE_PLUS_DOT: + 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) { + 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); + } + + // Generate a single water/lava spot in the center + SetTerrainSecondaryWithFlag(GetTileMut(middleX, middleY), 0); + } + else { + // Both dimensions are odd. Generate a maze room + SetSpawnFlag5(gridCell); + GenerateMaze(gridCell, TRUE); + } + + gridCell->hasSecondaryStructure = TRUE; + } + break; + } +} + +/* + * 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 + */ +static 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 = GetTileMut(x, y); + if (GetTerrainType(tile) != TERRAIN_TYPE_NORMAL) { + 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); + } + // 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); + } + } + } +} + +// Converts Secondary terrain to both secondary and normal. Possibly to note that it's a water tile? +static 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(GetTileMut(x,y), TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + } + } + } +} + +/* + * EnsureImpassableTilesAreWalls - Force all tiles with the impassable flag to be set as walls. + */ +static 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(GetTileMut(x,y)); + } + } + } +} + +static 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 DungeonPos is out of bounds on the map. +static inline bool8 PosIsOutOfBounds(s32 x, s32 y) +{ + if (x < 0) + return TRUE; + if (y < 0) + return TRUE; + if (DUNGEON_MAX_SIZE_X <= x) + return TRUE; + if (DUNGEON_MAX_SIZE_Y <= y) + return TRUE; + return FALSE; +} + +static 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(GetTileMut(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))) + { + GetTileMut(x,y)->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + } + } + + // Reset Stairs DungeonPos + 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; + } +} + +struct PositionU8 +{ + u8 x; + u8 y; +}; + +/* + * ShuffleSpawnPositions - Randomly shuffle an array of spawn positions + */ +static 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; +extern const s16 gUnknown_80F4DA4; +static void SpawnNonEnemies(FloorProperties *floorProps, 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; + // 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 + + const 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 = 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; + + // 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 = GetTileMut(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 + + const 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 = floorProps->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 = GetTileMut(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 = floorProps->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 = GetTileMut(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) + const 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 = GetTileMut(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->unk644.unk18) { + 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 + + const 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(floorProps->trapDensity / 2, floorProps->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 = GetTileMut(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 + + const 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; + } + } +} + +/* + * SpawnEnemies - Spawns all enemies, including those in forced monster houses + */ +static void SpawnEnemies(FloorProperties *floorProps, 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 = floorProps->enemyDensity; + + if (enemyDensity > 0) { + // Positive means value with variance + numEnemies = DungeonRandRange(enemyDensity / 2, enemyDensity); + + if (numEnemies < 1) { + numEnemies = 1; + } + } + else { + // Negative means exact value. + numEnemies = abs(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 + const 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->unk644.unk44) { + 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 = GetTileMut(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 + + const 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 = GetTileMut(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]; +// 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 +static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) +{ + s32 densityN; + s32 x, y; + // Stack + + s32 numToGen; + s32 numTilesFill; + + if (!(floorProps->roomFlags & flag)) + return; + + // Generate 1-3 "river+lake" formations + 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) { + upwards = TRUE; + y = DUNGEON_MAX_SIZE_Y - 1; + dirY = -1; + } + else { + upwards = FALSE; + y = 0; + dirY = 1; + } + + stepsUntilLake = DungeonRandInt(50) + 10; + + // Pick a random column in the interior to start the river on + x = DungeonRandRange(2, DUNGEON_MAX_SIZE_X - 2); + 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; + } + 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; + + // Vertically out of bounds, stop + if (y < 0 || y >= DUNGEON_MAX_SIZE_Y) { + break; + } + + stepsUntilLake--; + if (stepsUntilLake != 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(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++) { + + 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(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 + + // Alternate between horizontal and vertical movement each iteration + 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 (upwards) { + dirY = -1; + } + else { + dirY = 1; + } + + dirX = 0; + } + else { + //Randomly pick between left and right + if (DungeonRandInt(100) < 50) { + dirX = -1; + } + else { + dirX = 1; + } + + dirY = 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 < floorProps->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 rndY = 0; + s32 rndX = 0; + s32 n = 0; + + // Up to 200 attempts + while (n < 200) { + 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) + 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(GetTileMut(x + rndX - 5, y + rndY - 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 = GetTileMut(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); + } + } + } + } +} + +#else +NAKED static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) +{ + 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 GetTileMut\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 GetTileMut\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 GetTileMut\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 GetTileMut\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 GetTileMut\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 = GetTileMut(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 = GetTileMut(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; +} + +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(GetTileMut(roomX, roomY)); + GetTileMut(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(GetTileMut(pt_x, pt_y)); + + // Set the room index to 0xFE for anchor + GetTileMut(pt_x, pt_y)->room = CORRIDOR_ROOM; + } + } + } +} + +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; + +static 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; +} + +static bool8 PlaceFixedRoomTile(Tile *tile, u8 a1, s32 x, s32 y, u8 a5); +static bool8 sub_805210C(u8 itemId); + +static bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) +{ + tile->terrainType |= TERRAIN_TYPE_UNBREAKABLE; + tile->unkE = 0; + return PlaceFixedRoomTile(tile, a1, x, y, a5); +} + +static void sub_8051288(s32 fixedRoomNumber) +{ + s32 x, y; + Dungeon *dungeon = gDungeon; + 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))[fixedRoomNumber]->unk3; + gUnknown_202F1E1 = 0; + + for (y = 5; y < fixedRoomSizeY + 5; y++) { + for (x = 5; x < fixedRoomSizeX + 5; x++) { + u8 unk = sub_80511F0(); + if (sub_805124C(GetTileMut(x, y), unk, x, y, 1)) { + dungeon->stairsSpawn.x = x; + dungeon->stairsSpawn.y = 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 = GetTileMut(x, y); + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + if (gUnknown_202F1A8) { + SetTerrainType(tile, TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + } + else { + SetTerrainWall(tile); + } + } + } + } + + if (fixedRoomNumber == 4) { + for (y = 5; y < 17; y++) { + for (x = 2; x < 5; x++) { + Tile *tile = GetTileMut(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 = GetTileMut(x, y); + if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + } + } + } + } + + FinalizeJunctions(); +} + +static void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) +{ + s32 x, y; + Dungeon *dungeon = gDungeon; + + gUnknown_202F1DC = ((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomNumber]->unk3; + gUnknown_202F1E1 = 0; + + if (((struct FixedRoomsData **)(dungeon->unk13568->data))[fixedRoomNumber]->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 = GetTileMut(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 = GetTileMut(x, y); + u8 roomId = tile->room; + + sub_805124C(tile, unk, x, y, 1); + tile->room = roomId; + dungeon->unkE8BC = roomId; + } + } + } +} + +extern const s16 gUnknown_80F57D4[][3][3]; + +static 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. + */ +static 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; + } + } +} + +static 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? +static void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_, u32 UNUSED unused) +{ + 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); + } +} + +static void SpawnEnemyTrapAtPos(u8 trapId, s32 x, s32 y, bool8 isVisible) +{ + DungeonPos pos; + Entity *trapEntity; + Tile *tile = GetTileMut(x, y); + + pos.x = x; + pos.y = y; + trapEntity = SpawnTrap(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 unkC; + u8 unkD; + u8 unkE; +}; + +extern const struct UnkStruct_80F6D20 gUnknown_80F6D20[]; + +// 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 (fixedRoomActionId > 0xF) { + SetTerrainNormal(tile); + } + + switch (fixedRoomActionId) { + case 69: + gDungeon->unk644.unk40 = x; + gDungeon->unk644.unk42 = y; + SpawnEnemyTrapAtPos(TRAP_SEAL_TRAP, x, y, FALSE); + // fall through + case 0: + SetTerrainNormal(tile); + tile->room = 0; + break; + case 1: + SetTerrainWall(tile); + tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE); + tile->room = CORRIDOR_ROOM; + break; + case 4: + SetTerrainNormal(tile); + gDungeon->playerSpawn.x = x; + gDungeon->playerSpawn.y = y; + tile->room = 0; + break; + case 5: + SetTerrainSecondary(tile); + tile->room = 0; + break; + case 6: + SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL); + tile->room = CORRIDOR_ROOM; + 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; + break; + 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; + break; + case 68: + tile->terrainType |= TERRAIN_TYPE_UNK_x800; + SetTerrainNormal(tile); + tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); + tile->room = 0; + break; + case 9: + SetTerrainNormal(tile); + tile->room = CORRIDOR_ROOM; + break; + case 11: + SetTerrainNormal(tile); + tile->terrainType |= TERRAIN_TYPE_UNK_x800; + tile->room = 0; + 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; + break; + case 2: + case 13: + case 14: + SetTerrainWall(tile); + tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + tile->room = CORRIDOR_ROOM; + break; + default: + 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(ptr->unk0, x, y, ptr->unk2, ptr->unk4); + } + else { + gDungeon->unk644.unk47 = ptr->unk0; + } + } + else { + if (ptr->unk4 != 0) { + gDungeon->unkE220[ptr->unk4 - 1].x = x; + gDungeon->unkE220[ptr->unk4 - 1].y = y; + } + } + + if (ptr->unk8 != 0) { + sub_8051998(ptr->unk8, x, y, ptr->unkA, fixedRoomActionId); + } + + if (ptr->unkB != 20 && a5) { + SpawnEnemyTrapAtPos(ptr->unkB, x, y, ptr->unkD); + } + + if (ptr->unkE != 0) { + SetTerrainSecondary(tile); + } + } + break; + case 3: + case 15: + 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_map_access.c b/src/dungeon_map_access.c index c5d82dde..5c28d0cd 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 = GetTileMut(x,y); - tile->unk4 = 0; + tile->spawnOrVisibilityFlags = 0; } } } @@ -1024,7 +1024,7 @@ void sub_804AC20(DungeonPos *pos) for (y = yMin; y <= yMax; y++) { for (x = xMin; x <= xMax; x++) { tile = GetTileMut(x,y); - tile->unk4 = tile->unk4 | 3; + tile->spawnOrVisibilityFlags |= 3; sub_80402AC(x,y); } } diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index d3d729d5..98a43d2b 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -39,7 +39,7 @@ static void ReadDungeonMonsters(DataSerializer *seri); static void ReadDungeonMusic(DataSerializer *seri); static void ReadDungeonTraps(DataSerializer *seri); static void ReadDungeonUnk644(DataSerializer *seri); -static void ReadDungeonUnkE240(DataSerializer *seri, unkDungeonE240 *dst); +static void ReadDungeonkecleonShopPos(DataSerializer *seri, struct MinMaxPosition *dst); static void ReadDungeonUnkE260(DataSerializer *seri, unkDungeonE260 *dst); static void ReadDungeonVisibility(DataSerializer *seri); static void ReadBlinkerClassStatus(DataSerializer *seri, BlinkerClassStatus *dst); @@ -92,7 +92,7 @@ static void WriteDungeonMonsters(DataSerializer *seri); static void WriteDungeonMusic(DataSerializer *seri); static void WriteDungeonTraps(DataSerializer *seri); static void WriteDungeonUnk644(DataSerializer *seri); -static void WriteDungeonUnkE240(DataSerializer *seri, unkDungeonE240 *src); +static void WriteDungeonkecleonShopPos(DataSerializer *seri, struct MinMaxPosition *src); static void WriteDungeonUnkE260(DataSerializer *seri, unkDungeonE260 *src); static void WriteDungeonVisibility(DataSerializer *seri); static void WriteBlinkerClassStatus(DataSerializer *seri, BlinkerClassStatus *src); @@ -405,16 +405,16 @@ static void WriteDungeonFloor(DataSerializer *seri) s32 i; WriteBlame(seri, sMisakiSan); - WriteBool8(seri, gDungeon->unk3A08); + WriteBool8(seri, gDungeon->forceMonsterHouse); WriteBool8(seri, gDungeon->unk3A09); WriteBool8(seri, gDungeon->unk3A0A); WriteBool8(seri, gDungeon->unk3A0B); - WriteU8(seri, gDungeon->unk3A0C); + WriteU8(seri, gDungeon->monsterHouseRoom); WriteU8(seri, gDungeon->unk3A0D); WriteS16(seri, gDungeon->tileset); WriteS16(seri,gDungeon->unk3A10); WriteS16(seri, gDungeon->unk3A12); - WriteS16(seri, gDungeon->bossBattleIndex); + WriteS16(seri, gDungeon->fixedRoomNumber); WriteS16(seri, gDungeon->unk3A16); for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { @@ -423,14 +423,14 @@ static void WriteDungeonFloor(DataSerializer *seri) } } - WriteTilePos(seri, &gDungeon->unkE218); - WriteTilePos(seri, &gDungeon->unkE21C); + WriteTilePos(seri, &gDungeon->playerSpawn); + WriteTilePos(seri, &gDungeon->stairsSpawn); for (i = 0; i < 8; i++) WriteTilePos(seri, &gDungeon->unkE220[i]); - WriteDungeonUnkE240(seri, &gDungeon->unkE240); - WriteDungeonUnkE240(seri, &gDungeon->unkE250); + WriteDungeonkecleonShopPos(seri, &gDungeon->kecleonShopPos); + WriteDungeonkecleonShopPos(seri, &gDungeon->unkE250); WriteDungeonUnkE260(seri, &gDungeon->unkE260); for (y = 0; y < 8; y++) { @@ -693,7 +693,7 @@ static void WriteIQSkills(DataSerializer *seri, u8 *src) static void WriteTile(DataSerializer *seri, Tile *src) { WriteU16(seri, src->terrainType); - WriteU16(seri, src->unk4); + WriteU16(seri, src->spawnOrVisibilityFlags); WriteBytes(seri, &src->room, 1); WriteBytes(seri, &src->unkE, 1); } @@ -767,16 +767,16 @@ static void ReadDungeonFloor(DataSerializer *seri) ReadBlame(seri, sMisakiSan); - gDungeon->unk3A08 = ReadBool8(seri); + gDungeon->forceMonsterHouse = ReadBool8(seri); gDungeon->unk3A09 = ReadBool8(seri); gDungeon->unk3A0A = ReadBool8(seri); gDungeon->unk3A0B = ReadBool8(seri); - gDungeon->unk3A0C = ReadU8(seri); + gDungeon->monsterHouseRoom = ReadU8(seri); gDungeon->unk3A0D = ReadU8(seri); gDungeon->tileset = ReadS16(seri); gDungeon->unk3A10 = ReadS16(seri); gDungeon->unk3A12 = ReadS16(seri); - gDungeon->bossBattleIndex = ReadS16(seri); + gDungeon->fixedRoomNumber = ReadS16(seri); gDungeon->unk3A16 = ReadS16(seri); for (y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { @@ -785,14 +785,14 @@ static void ReadDungeonFloor(DataSerializer *seri) } } - ReadTilePos(seri, &gDungeon->unkE218); - ReadTilePos(seri, &gDungeon->unkE21C); + ReadTilePos(seri, &gDungeon->playerSpawn); + ReadTilePos(seri, &gDungeon->stairsSpawn); for (i = 0; i < 8; i++) ReadTilePos(seri, &gDungeon->unkE220[i]); - ReadDungeonUnkE240(seri, &gDungeon->unkE240); - ReadDungeonUnkE240(seri, &gDungeon->unkE250); + ReadDungeonkecleonShopPos(seri, &gDungeon->kecleonShopPos); + ReadDungeonkecleonShopPos(seri, &gDungeon->unkE250); ReadDungeonUnkE260(seri, &gDungeon->unkE260); for (y = 0; y < 8; y++) { @@ -810,7 +810,7 @@ static void ReadTile(DataSerializer *seri, Tile *dst) memset(dst, 0, sizeof(Tile)); dst->terrainType = ReadU16(seri); - dst->unk4 = ReadU16(seri); + dst->spawnOrVisibilityFlags = ReadU16(seri); ReadBytes(seri, &dst->room, 1); ReadBytes(seri, &dst->unkE, 1); @@ -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; @@ -1633,12 +1633,12 @@ static void WriteTilePos(DataSerializer *seri, DungeonPos *src) WriteBytes(seri, &src->y, 1); } -static void WriteDungeonUnkE240(DataSerializer *seri, unkDungeonE240 *src) +static void WriteDungeonkecleonShopPos(DataSerializer *seri, struct MinMaxPosition *src) { - WriteBytes(seri, &src->unk0, 1); - WriteBytes(seri, &src->unk4, 1); - WriteBytes(seri, &src->unk8, 1); - WriteBytes(seri, &src->unkC, 1); + WriteBytes(seri, &src->minX, 1); + WriteBytes(seri, &src->minY, 1); + WriteBytes(seri, &src->maxX, 1); + WriteBytes(seri, &src->maxY, 1); } static void WriteDungeonUnkE260(DataSerializer *seri, unkDungeonE260 *src) @@ -1716,16 +1716,16 @@ static void ReadTilePos(DataSerializer *seri, DungeonPos *dst) ReadBytes(seri, &dst->y, 1); } -static void ReadDungeonUnkE240(DataSerializer *seri, unkDungeonE240 *dst) +static void ReadDungeonkecleonShopPos(DataSerializer *seri, struct MinMaxPosition *dst) { - dst->unk0 = 0; - dst->unk4 = 0; - dst->unk8 = 0; - dst->unkC = 0; - ReadBytes(seri, &dst->unk0, 1); - ReadBytes(seri, &dst->unk4, 1); - ReadBytes(seri, &dst->unk8, 1); - ReadBytes(seri, &dst->unkC, 1); + dst->minX = 0; + dst->minY = 0; + dst->maxX = 0; + dst->maxY = 0; + ReadBytes(seri, &dst->minX, 1); + ReadBytes(seri, &dst->minY, 1); + ReadBytes(seri, &dst->maxX, 1); + ReadBytes(seri, &dst->maxY, 1); } static void ReadDungeonUnkE260(DataSerializer *seri, unkDungeonE260 *dst) diff --git a/src/dungeon_util.c b/src/dungeon_util.c index b414cc1a..6146b994 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/move_actions.c b/src/move_actions.c index 8543a2eb..3ed87969 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -2751,7 +2751,7 @@ _0805AA5E: sub_807EC28(FALSE); } sub_806A5B8(target); - sub_8075900(target,gDungeon->unk3A08); + sub_8075900(target,gDungeon->forceMonsterHouse); } } return TRUE; diff --git a/src/status.c b/src/status.c index 03d77061..e8dc7fc7 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/tile_types.c b/src/tile_types.c index f489665f..813d2dd5 100644 --- a/src/tile_types.c +++ b/src/tile_types.c @@ -127,7 +127,7 @@ bool8 sub_804AD34(DungeonPos *pos) iVar8 = 0; tile = GetTileMut(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; @@ -166,10 +166,10 @@ bool8 sub_804AE08(DungeonPos *pos) tile = GetTileMut(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->unk4 = tile->unk4 | 0x10; + tile->spawnOrVisibilityFlags = tile->spawnOrVisibilityFlags | 0x10; for(y = -1; y < 2; y++) { @@ -191,8 +191,8 @@ void sub_804AE84(DungeonPos *pos) s32 y; tile = GetTileMut(pos->x,pos->y); - if ((tile->unk4 & 0x10) != 0) { - tile->unk4 = tile->unk4 & 0xffef; + if ((tile->spawnOrVisibilityFlags & 0x10) != 0) { + tile->spawnOrVisibilityFlags &= 0xffef; for(y = -1; y < 2; y++) { diff --git a/src/trap.c b/src/trap.c index 71e798fd..9dd484d6 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); @@ -76,7 +65,7 @@ bool8 sub_806AA0C(s32, s32); void sub_80421EC(DungeonPos *, 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 *); @@ -149,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; @@ -551,7 +540,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); diff --git a/sym_ewram.txt b/sym_ewram.txt index f4a5c026..65a583a9 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -274,47 +274,7 @@ gUnknown_202EE76: /* 202EE76 (sub_804513C - sub_8082A08) */ .space 0x10 .include "src/dungeon_map_access.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) */ - .space 0x4 - -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_generation.o" .include "src/dungeon_message.o" .include "src/dungeon_move.o" .include "src/code_805D8C8_1.o"