diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index 62fe24223..e54657da0 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -5,1037 +5,6 @@ .text - thumb_func_start CreateGridCellConnections -CreateGridCellConnections: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x58 - str r0, [sp, 0xC] - str r1, [sp, 0x10] - str r2, [sp, 0x14] - str r3, [sp, 0x18] - ldr r0, [sp, 0x7C] - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x1C] - movs r0, 0 - str r0, [sp, 0x20] - cmp r0, r1 - bge _0804D968 -_0804D8EC: - movs r1, 0 - mov r10, r1 - ldr r2, [sp, 0x20] - adds r2, 0x1 - str r2, [sp, 0x38] - ldr r3, [sp, 0x14] - cmp r10, r3 - bge _0804D95E - ldr r4, [sp, 0x20] - lsls r1, r4, 4 - subs r1, r4 - movs r3, 0 - lsls r1, 5 - ldr r0, [sp, 0xC] - adds r0, 0x8 - adds r1, r0 -_0804D90C: - ldrb r2, [r1] - cmp r2, 0 - beq _0804D91C - strb r3, [r1, 0xF] - strb r3, [r1, 0x10] - strb r3, [r1, 0x11] - strb r3, [r1, 0x12] - b _0804D952 -_0804D91C: - ldr r5, [sp, 0x20] - cmp r5, 0 - bgt _0804D924 - strb r2, [r1, 0xD] -_0804D924: - mov r6, r10 - cmp r6, 0 - bgt _0804D92C - strb r2, [r1, 0xB] -_0804D92C: - ldr r0, [sp, 0x10] - subs r0, 0x1 - ldr r7, [sp, 0x20] - cmp r7, r0 - blt _0804D938 - strb r2, [r1, 0xE] -_0804D938: - ldr r0, [sp, 0x14] - subs r0, 0x1 - cmp r10, r0 - blt _0804D942 - strb r2, [r1, 0xC] -_0804D942: - ldrb r0, [r1, 0xB] - strb r0, [r1, 0xF] - ldrb r0, [r1, 0xC] - strb r0, [r1, 0x10] - ldrb r0, [r1, 0xD] - strb r0, [r1, 0x11] - ldrb r0, [r1, 0xE] - strb r0, [r1, 0x12] -_0804D952: - adds r1, 0x20 - movs r0, 0x1 - add r10, r0 - ldr r2, [sp, 0x14] - cmp r10, r2 - blt _0804D90C -_0804D95E: - ldr r3, [sp, 0x38] - str r3, [sp, 0x20] - ldr r4, [sp, 0x10] - cmp r3, r4 - blt _0804D8EC -_0804D968: - movs r5, 0 - str r5, [sp, 0x20] - ldr r6, [sp, 0x10] - cmp r5, r6 - blt _0804D974 - b _0804DBC6 -_0804D974: - movs r7, 0 - mov r10, r7 - ldr r0, [sp, 0x20] - adds r0, 0x1 - str r0, [sp, 0x38] - ldr r1, [sp, 0x14] - cmp r10, r1 - blt _0804D986 - b _0804DBBA -_0804D986: - ldr r2, [sp, 0x20] - lsls r2, 4 - str r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r1, r2, r3 - lsls r1, 5 - movs r4, 0 - str r4, [sp, 0x48] - ldr r5, [sp, 0xC] - movs r6, 0xF0 - lsls r6, 1 - adds r0, r5, r6 - adds r0, r1 - mov r8, r0 - adds r5, r1, r5 - ldr r7, [sp, 0xC] - ldr r2, _0804DA0C - adds r0, r7, r2 - adds r7, r1, r0 - ldr r3, [sp, 0x78] - str r3, [sp, 0x4C] - ldr r0, [sp, 0xC] - adds r0, 0x20 - adds r0, r1, r0 - str r0, [sp, 0x50] - ldr r0, [sp, 0xC] - subs r0, 0x20 - adds r6, r1, r0 - ldr r4, [sp, 0x20] - lsls r0, r4, 2 - ldr r1, [sp, 0x18] - adds r0, r1 - str r0, [sp, 0x24] -_0804D9C8: - ldr r2, [sp, 0x20] - lsls r0, r2, 4 - subs r0, r2 - lsls r0, 5 - ldr r3, [sp, 0xC] - adds r0, r3 - ldr r1, [sp, 0x48] - adds r4, r1, r0 - ldrb r0, [r4, 0x8] - cmp r0, 0 - beq _0804D9E0 - b _0804DB92 -_0804D9E0: - ldrb r0, [r4, 0xA] - cmp r0, 0 - beq _0804DA10 - movs r2, 0 - ldrsh r0, [r4, r2] - adds r0, 0x1 - movs r3, 0x4 - ldrsh r1, [r4, r3] - subs r1, 0x1 - bl DungeonRandRange - mov r9, r0 - movs r1, 0x2 - ldrsh r0, [r4, r1] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r4, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r4, r0, 0 - b _0804DA1A - .align 2, 0 -_0804DA0C: .4byte 0xfffffe20 -_0804DA10: - movs r0, 0 - ldrsh r3, [r4, r0] - mov r9, r3 - movs r1, 0x2 - ldrsh r4, [r4, r1] -_0804DA1A: - ldrb r0, [r5, 0x17] - cmp r0, 0 - beq _0804DA74 - ldrb r0, [r6, 0x8] - cmp r0, 0 - bne _0804DA68 - ldrb r0, [r6, 0xA] - cmp r0, 0 - beq _0804DA40 - movs r2, 0 - ldrsh r0, [r6, r2] - adds r0, 0x1 - movs r3, 0x4 - ldrsh r1, [r6, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r2, r0, 0 - b _0804DA44 -_0804DA40: - movs r0, 0 - ldrsh r2, [r6, r0] -_0804DA44: - movs r3, 0x2 - ldrsh r1, [r5, r3] - movs r0, 0x6 - ldrsh r3, [r6, r0] - subs r3, 0x1 - mov r12, r3 - movs r3, 0x1 - str r3, [sp] - ldr r3, [sp, 0x24] - ldr r0, [r3] - str r0, [sp, 0x4] - ldr r3, [sp, 0x4C] - ldr r0, [r3] - str r0, [sp, 0x8] - mov r0, r9 - mov r3, r12 - bl sub_804E328 -_0804DA68: - movs r0, 0 - strb r0, [r5, 0x17] - strb r0, [r6, 0x18] - movs r1, 0x1 - strb r1, [r5, 0xB] - strb r1, [r6, 0xB] -_0804DA74: - ldrb r0, [r5, 0x18] - cmp r0, 0 - beq _0804DAD4 - ldr r2, [sp, 0x50] - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _0804DAC6 - ldrb r0, [r2, 0xA] - cmp r0, 0 - beq _0804DA9C - movs r3, 0x20 - ldrsh r0, [r5, r3] - adds r0, 0x1 - movs r2, 0x24 - ldrsh r1, [r5, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r2, r0, 0 - b _0804DAA0 -_0804DA9C: - movs r3, 0x20 - ldrsh r2, [r5, r3] -_0804DAA0: - movs r0, 0x6 - ldrsh r1, [r5, r0] - subs r1, 0x1 - movs r0, 0x22 - ldrsh r3, [r5, r0] - mov r12, r3 - movs r3, 0x1 - str r3, [sp] - ldr r3, [sp, 0x24] - ldr r0, [r3] - str r0, [sp, 0x4] - ldr r3, [sp, 0x4C] - ldr r0, [r3, 0x4] - subs r0, 0x1 - str r0, [sp, 0x8] - mov r0, r9 - mov r3, r12 - bl sub_804E328 -_0804DAC6: - movs r0, 0 - strb r0, [r5, 0x18] - ldr r1, [sp, 0x50] - strb r0, [r1, 0x17] - movs r2, 0x1 - strb r2, [r5, 0xB] - strb r2, [r1, 0xB] -_0804DAD4: - ldrb r0, [r5, 0x19] - cmp r0, 0 - beq _0804DB2E - ldrb r0, [r7, 0x8] - cmp r0, 0 - bne _0804DB22 - ldrb r0, [r7, 0xA] - cmp r0, 0 - beq _0804DAFA - movs r3, 0x2 - ldrsh r0, [r7, r3] - adds r0, 0x1 - movs r2, 0x6 - ldrsh r1, [r7, r2] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804DAFE -_0804DAFA: - movs r0, 0x2 - ldrsh r3, [r7, r0] -_0804DAFE: - movs r1, 0 - ldrsh r0, [r5, r1] - movs r1, 0 - ldrsh r2, [r7, r1] - subs r2, 0x1 - mov r9, r2 - movs r2, 0 - str r2, [sp] - ldr r2, [sp, 0x24] - ldr r1, [r2] - str r1, [sp, 0x4] - ldr r2, [sp, 0x4C] - ldr r1, [r2] - str r1, [sp, 0x8] - adds r1, r4, 0 - mov r2, r9 - bl sub_804E328 -_0804DB22: - movs r3, 0 - strb r3, [r5, 0x19] - strb r3, [r7, 0x1A] - movs r0, 0x1 - strb r0, [r5, 0xB] - strb r0, [r7, 0xB] -_0804DB2E: - ldrb r0, [r5, 0x1A] - cmp r0, 0 - beq _0804DB92 - mov r1, r8 - ldrb r0, [r1, 0x8] - cmp r0, 0 - bne _0804DB84 - ldrb r0, [r1, 0xA] - cmp r0, 0 - beq _0804DB56 - movs r2, 0x2 - ldrsh r0, [r1, r2] - adds r0, 0x1 - movs r3, 0x6 - ldrsh r1, [r1, r3] - subs r1, 0x1 - bl DungeonRandRange - adds r3, r0, 0 - b _0804DB5C -_0804DB56: - mov r0, r8 - movs r1, 0x2 - ldrsh r3, [r0, r1] -_0804DB5C: - movs r2, 0x4 - ldrsh r0, [r5, r2] - subs r0, 0x1 - mov r1, r8 - movs r2, 0 - ldrsh r1, [r1, r2] - mov r9, r1 - movs r1, 0 - str r1, [sp] - ldr r2, [sp, 0x24] - ldr r1, [r2, 0x4] - subs r1, 0x1 - str r1, [sp, 0x4] - ldr r2, [sp, 0x4C] - ldr r1, [r2] - str r1, [sp, 0x8] - adds r1, r4, 0 - mov r2, r9 - bl sub_804E328 -_0804DB84: - movs r3, 0 - strb r3, [r5, 0x1A] - mov r4, r8 - strb r3, [r4, 0x19] - movs r0, 0x1 - strb r0, [r5, 0xB] - strb r0, [r4, 0xB] -_0804DB92: - ldr r1, [sp, 0x48] - adds r1, 0x20 - str r1, [sp, 0x48] - movs r2, 0x20 - add r8, r2 - adds r5, 0x20 - adds r7, 0x20 - ldr r3, [sp, 0x4C] - adds r3, 0x4 - str r3, [sp, 0x4C] - ldr r4, [sp, 0x50] - adds r4, 0x20 - str r4, [sp, 0x50] - adds r6, 0x20 - movs r0, 0x1 - add r10, r0 - ldr r1, [sp, 0x14] - cmp r10, r1 - bge _0804DBBA - b _0804D9C8 -_0804DBBA: - ldr r2, [sp, 0x38] - str r2, [sp, 0x20] - ldr r3, [sp, 0x10] - cmp r2, r3 - bge _0804DBC6 - b _0804D974 -_0804DBC6: - ldr r4, [sp, 0x1C] - cmp r4, 0 - beq _0804DBCE - b _0804E026 -_0804DBCE: - movs r5, 0 - str r5, [sp, 0x20] - ldr r6, [sp, 0x10] - cmp r5, r6 - blt _0804DBDA - b _0804E026 -_0804DBDA: - movs r7, 0 - mov r10, r7 - ldr r0, [sp, 0x20] - adds r0, 0x1 - str r0, [sp, 0x38] - ldr r1, [sp, 0x14] - cmp r10, r1 - blt _0804DBEC - b _0804E018 -_0804DBEC: - movs r0, 0x64 - bl DungeonRandInt - mov r2, r10 - adds r2, 0x1 - str r2, [sp, 0x3C] - cmp r0, 0x4 - ble _0804DBFE - b _0804E00C -_0804DBFE: - mov r3, r10 - lsls r1, r3, 5 - ldr r4, [sp, 0x20] - lsls r2, r4, 4 - subs r0, r2, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - adds r4, r1, r0 - ldrb r0, [r4, 0x8] - str r1, [sp, 0x44] - str r2, [sp, 0x40] - cmp r0, 0 - beq _0804DC1C - b _0804E00C -_0804DC1C: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _0804DC24 - b _0804E00C -_0804DC24: - ldrb r0, [r4, 0x12] - cmp r0, 0 - beq _0804DC2C - b _0804E00C -_0804DC2C: - ldrb r0, [r4, 0x9] - cmp r0, 0 - beq _0804DC34 - b _0804E00C -_0804DC34: - ldrb r0, [r4, 0xA] - cmp r0, 0 - bne _0804DC3C - b _0804E00C -_0804DC3C: - movs r0, 0x4 - bl DungeonRandInt - cmp r0, 0x1 - bne _0804DC48 - b _0804DD50 -_0804DC48: - cmp r0, 0x1 - bgt _0804DC52 - cmp r0, 0 - beq _0804DC60 - b _0804E00C -_0804DC52: - cmp r0, 0x2 - bne _0804DC58 - b _0804DE3C -_0804DC58: - cmp r0, 0x3 - bne _0804DC5E - b _0804DF30 -_0804DC5E: - b _0804E00C -_0804DC60: - ldr r6, [sp, 0x20] - cmp r6, 0 - bgt _0804DC68 - b _0804E00C -_0804DC68: - ldr r7, _0804DD48 - adds r2, r4, r7 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DC74 - b _0804E00C -_0804DC74: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DC7C - b _0804E00C -_0804DC7C: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DC84 - b _0804E00C -_0804DC84: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DC8C - b _0804E00C -_0804DC8C: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DC94 - b _0804E00C -_0804DC94: - movs r1, 0 - ldrsh r0, [r2, r1] - str r0, [sp, 0x28] - ldrh r3, [r4, 0x2] - movs r5, 0x2 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x2] - movs r6, 0x2 - ldrsh r0, [r2, r6] - cmp r1, r0 - ble _0804DCAC - adds r3, r5, 0 -_0804DCAC: - lsls r0, r3, 16 - asrs r0, 16 - mov r9, r0 - movs r0, 0x4 - ldrsh r7, [r4, r0] - mov r10, r7 - ldrh r3, [r4, 0x6] - movs r5, 0x6 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x6] - movs r6, 0x6 - ldrsh r0, [r2, r6] - cmp r1, r0 - bge _0804DCCA - adds r3, r5, 0 -_0804DCCA: - lsls r0, r3, 16 - asrs r7, r0, 16 - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r8, r0 - ldr r5, [sp, 0x28] - cmp r5, r10 - bge _0804DD16 -_0804DCE4: - mov r4, r9 - adds r6, r5, 0x1 - cmp r9, r7 - bge _0804DD10 - ldr r0, _0804DD4C - adds r3, r0, 0 -_0804DCF0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r8 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DCF0 -_0804DD10: - adds r5, r6, 0 - cmp r5, r10 - blt _0804DCE4 -_0804DD16: - ldr r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r0, r2, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x44] - adds r0, r5, r0 - ldr r6, _0804DD48 - adds r3, r0, r6 - mov r1, sp - ldrh r1, [r1, 0x28] - strh r1, [r3] - mov r2, r10 - strh r2, [r3, 0x4] - mov r4, r9 - strh r4, [r3, 0x2] - strh r7, [r3, 0x6] - movs r5, 0x1 - strb r5, [r0, 0x12] - strb r5, [r3, 0x12] - movs r6, 0 - strb r6, [r0, 0xB] - strb r5, [r0, 0x11] - b _0804E00C - .align 2, 0 -_0804DD48: .4byte 0xfffffe20 -_0804DD4C: .4byte 0x0000fffc -_0804DD50: - mov r7, r10 - cmp r7, 0 - bgt _0804DD58 - b _0804E00C -_0804DD58: - adds r2, r4, 0 - subs r2, 0x20 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DD64 - b _0804E00C -_0804DD64: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DD6C - b _0804E00C -_0804DD6C: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DD74 - b _0804E00C -_0804DD74: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DD7C - b _0804E00C -_0804DD7C: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DD84 - b _0804E00C -_0804DD84: - ldrh r3, [r4] - movs r0, 0 - ldrsh r1, [r4, r0] - ldrh r5, [r2] - movs r6, 0 - ldrsh r0, [r2, r6] - cmp r1, r0 - ble _0804DD96 - adds r3, r5, 0 -_0804DD96: - lsls r0, r3, 16 - asrs r0, 16 - str r0, [sp, 0x2C] - movs r0, 0x2 - ldrsh r7, [r2, r0] - mov r10, r7 - ldrh r3, [r4, 0x4] - movs r5, 0x4 - ldrsh r1, [r4, r5] - ldrh r5, [r2, 0x4] - movs r6, 0x4 - ldrsh r0, [r2, r6] - cmp r1, r0 - bge _0804DDB4 - adds r3, r5, 0 -_0804DDB4: - lsls r0, r3, 16 - asrs r0, 16 - mov r8, r0 - movs r0, 0x6 - ldrsh r7, [r4, r0] - movs r1, 0 - ldrsh r0, [r4, r1] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrb r0, [r0, 0x9] - mov r9, r0 - ldr r5, [sp, 0x2C] - cmp r5, r8 - bge _0804DE06 -_0804DDD4: - mov r4, r10 - adds r6, r5, 0x1 - cmp r10, r7 - bge _0804DE00 - ldr r0, _0804DE38 - adds r3, r0, 0 -_0804DDE0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r9 - strb r1, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DDE0 -_0804DE00: - adds r5, r6, 0 - cmp r5, r8 - blt _0804DDD4 -_0804DE06: - ldr r2, [sp, 0x40] - ldr r3, [sp, 0x20] - subs r0, r2, r3 - lsls r0, 5 - ldr r4, [sp, 0xC] - adds r0, r4 - ldr r5, [sp, 0x44] - adds r0, r5, r0 - adds r3, r0, 0 - subs r3, 0x20 - mov r6, sp - ldrh r6, [r6, 0x2C] - strh r6, [r3] - mov r1, r8 - strh r1, [r3, 0x4] - mov r2, r10 - strh r2, [r3, 0x2] - strh r7, [r3, 0x6] - movs r4, 0x1 - strb r4, [r0, 0x12] - strb r4, [r3, 0x12] - movs r5, 0 - strb r5, [r0, 0xB] - strb r4, [r0, 0x11] - b _0804E00C - .align 2, 0 -_0804DE38: .4byte 0x0000fffc -_0804DE3C: - ldr r0, [sp, 0x10] - subs r0, 0x2 - ldr r6, [sp, 0x20] - cmp r6, r0 - ble _0804DE48 - b _0804E00C -_0804DE48: - movs r7, 0xF0 - lsls r7, 1 - adds r2, r4, r7 - ldrb r0, [r2, 0xB] - cmp r0, 0 - bne _0804DE56 - b _0804E00C -_0804DE56: - ldrb r0, [r2, 0x8] - cmp r0, 0 - beq _0804DE5E - b _0804E00C -_0804DE5E: - ldrb r0, [r2, 0xA] - cmp r0, 0 - bne _0804DE66 - b _0804E00C -_0804DE66: - ldrb r0, [r2, 0x9] - cmp r0, 0 - beq _0804DE6E - b _0804E00C -_0804DE6E: - ldrb r0, [r2, 0x12] - cmp r0, 0 - beq _0804DE76 - b _0804E00C -_0804DE76: - movs r1, 0 - ldrsh r0, [r4, r1] - str r0, [sp, 0x30] - ldrh r3, [r2, 0x2] - movs r5, 0x2 - ldrsh r1, [r2, r5] - ldrh r5, [r4, 0x2] - movs r6, 0x2 - ldrsh r0, [r4, r6] - cmp r1, r0 - ble _0804DE8E - adds r3, r5, 0 -_0804DE8E: - lsls r0, r3, 16 - asrs r0, 16 - mov r9, r0 - movs r0, 0x4 - ldrsh r7, [r2, r0] - mov r10, r7 - ldrh r3, [r2, 0x6] - movs r5, 0x6 - ldrsh r1, [r2, r5] - ldrh r2, [r4, 0x6] - movs r6, 0x6 - ldrsh r0, [r4, r6] - cmp r1, r0 - bge _0804DEAC - adds r3, r2, 0 -_0804DEAC: - lsls r0, r3, 16 - asrs r7, r0, 16 - movs r0, 0x2 - ldrsh r1, [r4, r0] - ldr r0, [sp, 0x30] - bl GetTile - ldrb r0, [r0, 0x9] - mov r8, r0 - ldr r5, [sp, 0x30] - cmp r5, r10 - bge _0804DEF6 -_0804DEC4: - mov r4, r9 - adds r6, r5, 0x1 - cmp r9, r7 - bge _0804DEF0 - ldr r1, _0804DF2C - adds r3, r1, 0 -_0804DED0: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - ldr r3, [sp, 0x54] - ands r1, r3 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r2, r8 - strb r2, [r0, 0x9] - adds r4, 0x1 - cmp r4, r7 - blt _0804DED0 -_0804DEF0: - adds r5, r6, 0 - cmp r5, r10 - blt _0804DEC4 -_0804DEF6: - ldr r3, [sp, 0x40] - ldr r4, [sp, 0x20] - subs r0, r3, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - ldr r6, [sp, 0x44] - adds r0, r6, r0 - mov r1, sp - ldrh r1, [r1, 0x30] - strh r1, [r0] - mov r2, r10 - strh r2, [r0, 0x4] - mov r3, r9 - strh r3, [r0, 0x2] - strh r7, [r0, 0x6] - movs r4, 0xF0 - lsls r4, 1 - adds r1, r0, r4 - movs r5, 0x1 - strb r5, [r1, 0x12] - strb r5, [r0, 0x12] - movs r6, 0 - strb r6, [r1, 0xB] - strb r5, [r1, 0x11] - b _0804E00C - .align 2, 0 -_0804DF2C: .4byte 0x0000fffc -_0804DF30: - ldr r0, [sp, 0x14] - subs r0, 0x2 - cmp r10, r0 - bgt _0804E00C - adds r3, r4, 0 - adds r3, 0x20 - ldrb r0, [r3, 0xB] - cmp r0, 0 - beq _0804E00C - ldrb r0, [r3, 0x8] - cmp r0, 0 - bne _0804E00C - ldrb r0, [r3, 0xA] - cmp r0, 0 - beq _0804E00C - ldrb r0, [r3, 0x9] - cmp r0, 0 - bne _0804E00C - ldrb r0, [r3, 0x12] - cmp r0, 0 - bne _0804E00C - ldrh r2, [r4, 0x20] - movs r7, 0x20 - ldrsh r1, [r4, r7] - ldrh r5, [r4] - movs r6, 0 - ldrsh r0, [r4, r6] - cmp r1, r0 - ble _0804DF6C - adds r2, r5, 0 -_0804DF6C: - lsls r0, r2, 16 - asrs r0, 16 - str r0, [sp, 0x34] - movs r7, 0x2 - ldrsh r6, [r4, r7] - ldrh r2, [r3, 0x4] - movs r0, 0x4 - ldrsh r1, [r3, r0] - ldrh r5, [r4, 0x4] - movs r7, 0x4 - ldrsh r0, [r4, r7] - cmp r1, r0 - bge _0804DF88 - adds r2, r5, 0 -_0804DF88: - lsls r0, r2, 16 - asrs r0, 16 - mov r8, r0 - movs r0, 0x6 - ldrsh r3, [r3, r0] - movs r1, 0 - ldrsh r0, [r4, r1] - adds r1, r6, 0 - str r3, [sp, 0x54] - bl GetTile - ldrb r0, [r0, 0x9] - mov r10, r0 - ldr r5, [sp, 0x34] - ldr r3, [sp, 0x54] - cmp r5, r8 - bge _0804DFDE -_0804DFAA: - adds r4, r6, 0 - adds r7, r5, 0x1 - cmp r6, r3 - bge _0804DFD8 - ldr r2, _0804E038 - mov r9, r2 -_0804DFB6: - adds r0, r5, 0 - adds r1, r4, 0 - str r3, [sp, 0x54] - bl GetTileSafe - ldrh r1, [r0] - mov r2, r9 - ands r1, r2 - movs r2, 0x1 - orrs r1, r2 - strh r1, [r0] - mov r1, r10 - strb r1, [r0, 0x9] - adds r4, 0x1 - ldr r3, [sp, 0x54] - cmp r4, r3 - blt _0804DFB6 -_0804DFD8: - adds r5, r7, 0 - cmp r5, r8 - blt _0804DFAA -_0804DFDE: - ldr r2, [sp, 0x40] - ldr r4, [sp, 0x20] - subs r0, r2, r4 - lsls r0, 5 - ldr r5, [sp, 0xC] - adds r0, r5 - ldr r7, [sp, 0x44] - adds r0, r7, r0 - mov r1, sp - ldrh r1, [r1, 0x34] - strh r1, [r0] - mov r2, r8 - strh r2, [r0, 0x4] - strh r6, [r0, 0x2] - strh r3, [r0, 0x6] - adds r1, r0, 0 - adds r1, 0x20 - movs r3, 0x1 - strb r3, [r1, 0x12] - strb r3, [r0, 0x12] - movs r4, 0 - strb r4, [r1, 0xB] - strb r3, [r1, 0x11] -_0804E00C: - ldr r5, [sp, 0x3C] - mov r10, r5 - ldr r6, [sp, 0x14] - cmp r10, r6 - bge _0804E018 - b _0804DBEC -_0804E018: - ldr r7, [sp, 0x38] - str r7, [sp, 0x20] - adds r0, r7, 0 - ldr r1, [sp, 0x10] - cmp r0, r1 - bge _0804E026 - b _0804DBDA -_0804E026: - add sp, 0x58 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0804E038: .4byte 0x0000fffc - thumb_func_end CreateGridCellConnections - thumb_func_start GenerateRoomImperfections GenerateRoomImperfections: push {r4-r7,lr} @@ -1452,8 +421,8 @@ _0804E318: bx r0 thumb_func_end GenerateRoomImperfections - thumb_func_start sub_804E328 -sub_804E328: + thumb_func_start CreateHallway +CreateHallway: push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -1788,7 +757,7 @@ _0804E57E: pop {r4-r7} pop {r0} bx r0 - thumb_func_end sub_804E328 + thumb_func_end CreateHallway thumb_func_start EnsureConnectedGrid EnsureConnectedGrid: @@ -1957,7 +926,7 @@ _0804E6AC: str r0, [sp, 0x8] ldr r0, [sp, 0x24] adds r2, r5, 0 - bl sub_804E328 + bl CreateHallway mov r5, r10 strb r5, [r6, 0xB] strb r5, [r6, 0x13] @@ -2019,7 +988,7 @@ _0804E728: str r0, [sp, 0x8] ldr r0, [sp, 0x24] adds r2, r5, 0 - bl sub_804E328 + bl CreateHallway mov r3, r10 strb r3, [r6, 0xB] strb r3, [r6, 0x14] @@ -2076,7 +1045,7 @@ _0804E79E: ldr r1, [r4] str r1, [sp, 0x8] adds r1, r5, 0 - bl sub_804E328 + bl CreateHallway mov r5, r10 strb r5, [r6, 0xB] strb r5, [r6, 0x15] @@ -2139,7 +1108,7 @@ _0804E818: ldr r1, [r4] str r1, [sp, 0x8] adds r1, r5, 0 - bl sub_804E328 + bl CreateHallway mov r5, r10 strb r5, [r6, 0xB] strb r5, [r6, 0x16] diff --git a/src/code_804AFAC_1.c b/src/code_804AFAC_1.c index d12626ca0..83ad0a0c9 100644 --- a/src/code_804AFAC_1.c +++ b/src/code_804AFAC_1.c @@ -996,7 +996,7 @@ struct GridCell Position start; Position end; bool8 isInvalid; - bool8 unk9; + bool8 hasSecondaryStructure; bool8 isRoom; bool8 isConnected; bool8 unk12; @@ -1010,10 +1010,10 @@ struct GridCell bool8 connectedToBottom; bool8 connectedToLeft; bool8 connectedToRight; - bool8 unk23; - bool8 unk24; - bool8 unk25; - bool8 unk26; + bool8 shouldConnectToTop; + bool8 shouldConnectToBottom; + bool8 shouldConnectToLeft; + bool8 shouldConnectToRight; bool8 unk27; bool8 flagImperfect; bool8 flagSecondaryStructure; @@ -1042,6 +1042,7 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways); static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]); +void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s32 turnX, s32 turnY); /* * GenerateStandardFloor - Generates a standard, typical floor layout. @@ -2040,11 +2041,11 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gri grid[x][y].connectedToLeft = FALSE; grid[x][y].connectedToBottom = FALSE; grid[x][y].connectedToTop = FALSE; - grid[x][y].unk26 = FALSE; - grid[x][y].unk25 = FALSE; - grid[x][y].unk24 = FALSE; - grid[x][y].unk23 = FALSE; - grid[x][y].unk9 = FALSE; + grid[x][y].shouldConnectToRight = FALSE; + grid[x][y].shouldConnectToLeft = FALSE; + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y].hasSecondaryStructure = FALSE; grid[x][y].hasBeenMerged = FALSE; grid[x][y].isMazeRoom = FALSE; grid[x][y].isMerged = FALSE; @@ -2163,6 +2164,7 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz } #define GENERATION_CONSTANT_SECONDARY_STRUCTURE_FLAG_CHANCE 80 +#define GENERATION_CONSTANT_MERGE_ROOMS_CHANCE 5 /* * CreateRoomsAndAnchors - Creates the rectangle regions of open terrain for each room @@ -2581,4 +2583,384 @@ void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN } } +/* + * CreateGridCellConnections - Creates connections through generating hallways and merging rooms + * + * First, connection links are copied over to a work array for managing hallway generation. + * + * Then, for each connection specified between two cells, a hallway is generated based on the following: + * - If the cell is a hallway anchor, the hallway is generated based on the exact point of the anchor tile + * - If the cell is a room, the hallway is generated based on a random interior point inside the room + * + * See: CreateHallway for how these points generate the hallway path + * + * Finally, if room merging is enabled there is a 9.75% chance that two connected rooms will be merged + * into a single larger room. (9.75% comes from two 5% rolls, one for each of the two rooms being merged) + * A room can only participate in a merge once. + * + * Merged rooms take up the full tile space occupied between the two rooms. + * + */ +void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging) +{ + s32 x, y; + + // Validate and copy grid connections over to a work array + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + if (grid[x][y].isInvalid) { + // For invalid cells, assign no connections + + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y].shouldConnectToLeft = FALSE; + grid[x][y].shouldConnectToRight = FALSE; + } + else { + // For valid cells, remove cell connections beyond the grid bounds + if (x <= 0) { + grid[x][y].connectedToLeft = FALSE; + } + + if (y <= 0) { + grid[x][y].connectedToTop = FALSE; + } + + if (x >= gridSizeX - 1) { + grid[x][y].connectedToRight = FALSE; + } + + if (y >= gridSizeY - 1) { + grid[x][y].connectedToBottom = FALSE; + } + + // Assign the connections + grid[x][y].shouldConnectToTop = grid[x][y].connectedToTop; + grid[x][y].shouldConnectToBottom = grid[x][y].connectedToBottom; + grid[x][y].shouldConnectToLeft = grid[x][y].connectedToLeft; + grid[x][y].shouldConnectToRight = grid[x][y].connectedToRight; + } + } + } + + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + s32 pt_x, pt_y, pt2_x, pt2_y; + + if (grid[x][y].isInvalid) + continue; + + if (grid[x][y].isRoom) { + // Room, pick a random point in the interior of the room + pt_x = DungeonRandRange(grid[x][y].start.x + 1, grid[x][y].end.x - 1); + pt_y = DungeonRandRange(grid[x][y].start.y + 1, grid[x][y].end.y - 1); + } + else { + // Hallway anchor, point is the 1x1 we've placed + pt_x = grid[x][y].start.x; + pt_y = grid[x][y].start.y; + } + + if (grid[x][y].shouldConnectToTop) { + // Connect to the cell above + if (!grid[x][y - 1].isInvalid) { + if (grid[x][y - 1].isRoom) { + // Room, pick a random interior x coordinate + pt2_x = DungeonRandRange(grid[x][y - 1].start.x + 1, grid[x][y - 1].end.x - 1); + } + else { + // Anchor, use the central x coordinate + pt2_x = grid[x][y - 1].start.x; + } + + // Create the hallway + CreateHallway(pt_x, grid[x][y].start.y, pt2_x, grid[x][y - 1].end.y - 1, TRUE, listX[x], listY[y]); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToTop = FALSE; + grid[x][y - 1].shouldConnectToBottom = FALSE; + grid[x][y].isConnected = TRUE; + grid[x][y - 1].isConnected = TRUE; + } + + if (grid[x][y].shouldConnectToBottom) { + // Connect to the cell below + if (!grid[x][y + 1].isInvalid) { + if (grid[x][y + 1].isRoom) { + // Room, pick a random interior x coordinate + pt2_x = DungeonRandRange(grid[x][y + 1].start.x + 1, grid[x][y + 1].end.x - 1); + } + else { + // Anchor, use the central x coordinate + pt2_x = grid[x][y + 1].start.x; + } + + // Create the hallway + CreateHallway(pt_x, grid[x][y].end.y - 1, pt2_x, grid[x][y + 1].start.y, TRUE, listX[x], listY[y + 1] - 1); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToBottom = FALSE; + grid[x][y + 1].shouldConnectToTop = FALSE; + grid[x][y].isConnected = TRUE; + grid[x][y + 1].isConnected = TRUE; + } + + if (grid[x][y].shouldConnectToLeft) { + // Connect to the cell on the left + if (!grid[x - 1][y].isInvalid) { + if (grid[x - 1][y].isRoom) { + // Room, pick a random interior y coordinate + pt2_y = DungeonRandRange(grid[x - 1][y].start.y + 1, grid[x - 1][y].end.y - 1); + } + else { + // Anchor, use the central y coordinate + pt2_y = grid[x - 1][y].start.y; + } + + // Create the hallway + // Using (grid[x-1][y].start.x - 1) is a bug, it should be (grid[x-1][y].end.x - 1) + // But CreateHallway has safety checks making the end result the same anyways. + CreateHallway(grid[x][y].start.x, pt_y, grid[x - 1][y].start.x - 1, pt2_y, FALSE, listX[x], listY[y]); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToLeft = FALSE; + grid[x - 1][y].shouldConnectToRight = FALSE; + grid[x][y].isConnected = TRUE; + grid[x - 1][y].isConnected = TRUE; + } + + if (grid[x][y].shouldConnectToRight) { + // Connect to the cell on the right + if (!grid[x + 1][y].isInvalid) { + if (grid[x + 1][y].isRoom) { + // Room, pick a random interior y coordinate + pt2_y = DungeonRandRange(grid[x + 1][y].start.y + 1, grid[x + 1][y].end.y - 1); + } + else { + // Anchor, use the central y coordinate + pt2_y = grid[x + 1][y].start.y; + } + + // Create the hallway + CreateHallway(grid[x][y].end.x - 1, pt_y, grid[x + 1][y].start.x, pt2_y, FALSE, listX[x + 1] - 1, listY[y]); + } + + // Mark the connection and unassign it so we don't try to draw + // a second connection from the other way + + grid[x][y].shouldConnectToRight = FALSE; + grid[x + 1][y].shouldConnectToLeft = FALSE; + grid[x][y].isConnected = TRUE; + grid[x + 1][y].isConnected = TRUE; + } + } + } + + // If we don't want to merge rooms, we're done + if (disableRoomMerging) { + return; + } + + // If we do, we can try to merge some! + for (x = 0; x < gridSizeX; x++) { + for (y = 0; y < gridSizeY; y++) { + s32 chance = DungeonRandInt(100); + + // Conditions for merging a room: + // - rolls for merge chance + // - valid + // - connected to another room + // - not already merged + // - not have a secondary structure + // - is a room, not an anchor + if (chance < GENERATION_CONSTANT_MERGE_ROOMS_CHANCE && + !grid[x][y].isInvalid && + grid[x][y].isConnected && + !grid[x][y].isMerged && + !grid[x][y].hasSecondaryStructure && + grid[x][y].isRoom) + { + s32 chanceTwo = DungeonRandInt(4); + + // Verify the same for the target room + switch (chanceTwo) { + case 0: + if (x > 0 && + grid[x - 1][y].isConnected && + !grid[x - 1][y].isInvalid && + grid[x - 1][y].isRoom && + !grid[x - 1][y].hasSecondaryStructure && + !grid[x - 1][y].isMerged) + { + // Merge with the room to the left + s32 curX, curY; + s32 srcX = grid[x - 1][y].start.x; + s32 srcY = min(grid[x - 1][y].start.y, grid[x][y].start.y); + s32 dstX = grid[x][y].end.x; + s32 dstY = max(grid[x - 1][y].end.y, grid[x][y].end.y); + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x - 1][y].start.x = srcX; + grid[x - 1][y].end.x = dstX; + grid[x - 1][y].start.y = srcY; + grid[x - 1][y].end.y = dstY; + + // Mark merge flags on both rooms + grid[x][y].isMerged = TRUE; + grid[x - 1][y].isMerged = TRUE; + grid[x][y].isConnected = FALSE; + grid[x][y].hasBeenMerged = TRUE; + } + break; + case 1: + if (y >= 1 && + grid[x][y - 1].isConnected && + !grid[x][y - 1].isInvalid && + grid[x][y - 1].isRoom && + !grid[x][y - 1].hasSecondaryStructure && + !grid[x][y - 1].isMerged) + { + // Merge with the room above + s32 curX, curY; + s32 srcX = min(grid[x][y - 1].start.x, grid[x][y].start.x); + s32 srcY = grid[x][y - 1].start.y; + s32 dstX = max(grid[x][y - 1].end.x, grid[x][y].end.x); + s32 dstY = grid[x][y].end.y; + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x][y - 1].start.x = srcX; + grid[x][y - 1].end.x = dstX; + grid[x][y - 1].start.y = srcY; + grid[x][y - 1].end.y = dstY; + + // Mark merge flags on both rooms + grid[x][y].isMerged = TRUE; + grid[x][y - 1].isMerged = TRUE; + grid[x][y].isConnected = FALSE; + grid[x][y].hasBeenMerged = TRUE; + } + break; + case 2: + if (x <= gridSizeX - 2 && + grid[x + 1][y].isConnected && + !grid[x + 1][y].isInvalid && + grid[x + 1][y].isRoom && + !grid[x + 1][y].hasSecondaryStructure && + !grid[x + 1][y].isMerged) + { + // Merge with the room to the right + s32 curX, curY; + s32 srcX = grid[x][y].start.x; + s32 srcY = min(grid[x][y].start.y, grid[x + 1][y].start.y); + s32 dstX = grid[x + 1][y].end.x; + s32 dstY = max(grid[x][y].end.y, grid[x + 1][y].end.y); + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x][y].start.x = srcX; + grid[x][y].end.x = dstX; + grid[x][y].start.y = srcY; + grid[x][y].end.y = dstY; + + // Mark merge flags on both rooms + grid[x + 1][y].isMerged = TRUE; + grid[x][y].isMerged = TRUE; + grid[x + 1][y].isConnected = FALSE; + grid[x + 1][y].hasBeenMerged = TRUE; + } + break; + case 3: + if (y <= gridSizeY - 2 && + grid[x][y + 1].isConnected && + !grid[x][y + 1].isInvalid && + grid[x][y + 1].isRoom && + !grid[x][y + 1].hasSecondaryStructure && + !grid[x][y + 1].isMerged) + { + // Merge with the room below + s32 curX, curY; + s32 srcX = min(grid[x][y].start.x, grid[x][y + 1].start.x); + s32 srcY = grid[x][y].start.y; + s32 dstX = max(grid[x][y].end.x, grid[x][y + 1].end.x); + s32 dstY = grid[x][y + 1].end.y; + + // Use the original room's index + s32 mergeRoomIndex = GetTile(grid[x][y].start.x, grid[x][y].start.y)->room; + + // Carve out the merged room + for (curX = srcX; curX < dstX; curX++) { + for (curY = srcY; curY < dstY; curY++) { + Tile *tile = GetTileSafe(curX, curY); + + SetTerrainNormal(tile); + tile->room = mergeRoomIndex; + } + } + + // Update room boundaries + grid[x][y].start.x = srcX; + grid[x][y].end.x = dstX; + grid[x][y].start.y = srcY; + grid[x][y].end.y = dstY; + + // Mark merge flags on both rooms + grid[x][y + 1].isMerged = TRUE; + grid[x][y].isMerged = TRUE; + grid[x][y + 1].isConnected = FALSE; + grid[x][y + 1].hasBeenMerged = TRUE; + } + break; + } + } + } + } +} + //