dungeon generation is finished

This commit is contained in:
DizzyEggg 2024-11-19 12:39:41 +01:00
parent 0843612de4
commit 4a5fd910aa
10 changed files with 286 additions and 1035 deletions

View File

@ -1,887 +0,0 @@
#include "asm/constants/gba_constants.inc"
#include "asm/macros.inc"
.syntax unified
.text
thumb_func_start sub_8051A74
sub_8051A74:
push {r4-r7,lr}
mov r7, r9
mov r6, r8
push {r6,r7}
sub sp, 0x4
adds r4, r0, 0
adds r6, r2, 0
adds r7, r3, 0
ldr r0, [sp, 0x20]
lsls r1, 24
lsrs r1, 24
mov r8, r1
lsls r0, 24
lsrs r0, 24
mov r9, r0
cmp r1, 0xF
bls _08051AA2
ldrh r0, [r4]
ldr r1, _08051AB4
ands r1, r0
movs r0, 0x1
orrs r1, r0
strh r1, [r4]
_08051AA2:
mov r0, r8
cmp r0, 0x45
bls _08051AAA
b _08051D68
_08051AAA:
lsls r0, 2
ldr r1, _08051AB8
adds r0, r1
ldr r0, [r0]
mov pc, r0
.align 2, 0
_08051AB4: .4byte 0x0000fffc
_08051AB8: .4byte _08051ABC
.align 2, 0
_08051ABC:
.4byte _08051BF0
.4byte _08051C0C
.4byte _08051D50
.4byte _08051E1A
.4byte _08051C20
.4byte _08051C54
.4byte _08051C64
.4byte _08051C74
.4byte _08051C94
.4byte _08051D00
.4byte _08051C7E
.4byte _08051D10
.4byte _08051D24
.4byte _08051D50
.4byte _08051D50
.4byte _08051E1A
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051D68
.4byte _08051C94
.4byte _08051CD4
.4byte _08051BD4
_08051BD4:
ldr r0, _08051BFC
ldr r0, [r0]
ldr r2, _08051C00
adds r1, r0, r2
strh r6, [r1]
ldr r3, _08051C04
adds r0, r3
strh r7, [r0]
movs r0, 0xB
adds r1, r6, 0
adds r2, r7, 0
movs r3, 0
bl sub_8051A24
_08051BF0:
ldrh r1, [r4]
ldr r0, _08051C08
ands r0, r1
movs r1, 0x1
movs r2, 0
b _08051D42
.align 2, 0
_08051BFC: .4byte gDungeon
_08051C00: .4byte 0x00000684
_08051C04: .4byte 0x00000686
_08051C08: .4byte 0x0000fffc
_08051C0C:
ldrh r1, [r4]
ldr r0, _08051C18
ands r0, r1
ldr r1, _08051C1C
ands r0, r1
b _08051D5A
.align 2, 0
_08051C18: .4byte 0x0000fffc
_08051C1C: .4byte 0x0000feff
_08051C20:
ldrh r1, [r4]
ldr r0, _08051C44
ands r0, r1
movs r1, 0x1
movs r2, 0
orrs r0, r1
strh r0, [r4]
ldr r0, _08051C48
ldr r0, [r0]
ldr r3, _08051C4C
adds r1, r0, r3
strh r6, [r1]
ldr r1, _08051C50
adds r0, r1
strh r7, [r0]
strb r2, [r4, 0x9]
b _08051E1A
.align 2, 0
_08051C44: .4byte 0x0000fffc
_08051C48: .4byte gDungeon
_08051C4C: .4byte 0x0000e218
_08051C50: .4byte 0x0000e21a
_08051C54:
ldrh r1, [r4]
ldr r0, _08051C60
ands r0, r1
movs r2, 0
movs r1, 0x2
b _08051D42
.align 2, 0
_08051C60: .4byte 0x0000fffc
_08051C64:
ldrh r1, [r4]
ldr r0, _08051C70
ands r0, r1
movs r1, 0x3
b _08051D58
.align 2, 0
_08051C70: .4byte 0x0000fffc
_08051C74:
ldr r1, _08051C8C
movs r0, 0x1
strb r0, [r1]
bl sub_8049840
_08051C7E:
ldrh r1, [r4]
ldr r0, _08051C90
ands r0, r1
movs r1, 0x3
orrs r0, r1
b _08051D56
.align 2, 0
_08051C8C: .4byte gUnknown_202F1A8
_08051C90: .4byte 0x0000fffc
_08051C94:
ldrh r1, [r4]
ldr r0, _08051CC0
ands r0, r1
movs r1, 0x1
orrs r0, r1
strh r0, [r4]
ldrh r0, [r4, 0x4]
movs r2, 0
orrs r0, r1
ldr r1, _08051CC4
ands r0, r1
strh r0, [r4, 0x4]
strb r2, [r4, 0x9]
ldr r0, _08051CC8
ldr r0, [r0]
ldr r2, _08051CCC
adds r1, r0, r2
strh r6, [r1]
ldr r3, _08051CD0
adds r0, r3
strh r7, [r0]
b _08051E1A
.align 2, 0
_08051CC0: .4byte 0x0000fffc
_08051CC4: .4byte 0x0000fffd
_08051CC8: .4byte gDungeon
_08051CCC: .4byte 0x0000e21c
_08051CD0: .4byte 0x0000e21e
_08051CD4:
ldrh r1, [r4]
movs r2, 0x80
lsls r2, 4
adds r0, r2, 0
orrs r0, r1
ldr r1, _08051CF8
ands r0, r1
movs r1, 0x1
movs r2, 0
orrs r0, r1
strh r0, [r4]
ldrh r1, [r4, 0x4]
ldr r0, _08051CFC
ands r0, r1
strh r0, [r4, 0x4]
strb r2, [r4, 0x9]
b _08051E1A
.align 2, 0
_08051CF8: .4byte 0x0000fffc
_08051CFC: .4byte 0x0000fffd
_08051D00:
ldrh r1, [r4]
ldr r0, _08051D0C
ands r0, r1
movs r1, 0x1
b _08051D58
.align 2, 0
_08051D0C: .4byte 0x0000fffc
_08051D10:
ldrh r1, [r4]
ldr r0, _08051D20
ands r0, r1
movs r1, 0x1
movs r2, 0
orrs r0, r1
b _08051D3C
.align 2, 0
_08051D20: .4byte 0x0000fffc
_08051D24:
ldrh r1, [r4]
ldr r0, _08051D4C
ands r0, r1
movs r1, 0x1
orrs r0, r1
movs r2, 0x80
lsls r2, 5
adds r1, r2, 0
orrs r0, r1
movs r1, 0x10
orrs r0, r1
movs r2, 0
_08051D3C:
movs r3, 0x80
lsls r3, 4
adds r1, r3, 0
_08051D42:
orrs r0, r1
strh r0, [r4]
strb r2, [r4, 0x9]
b _08051E1A
.align 2, 0
_08051D4C: .4byte 0x0000fffc
_08051D50:
ldrh r1, [r4]
ldr r0, _08051D64
ands r0, r1
_08051D56:
movs r1, 0x10
_08051D58:
orrs r0, r1
_08051D5A:
strh r0, [r4]
movs r0, 0xFF
strb r0, [r4, 0x9]
b _08051E1A
.align 2, 0
_08051D64: .4byte 0x0000fffc
_08051D68:
mov r0, r8
subs r0, 0x10
lsls r0, 24
lsrs r0, 24
cmp r0, 0xCB
bhi _08051E1A
mov r1, r8
lsls r0, r1, 4
ldr r1, _08051DA0
adds r5, r0, r1
ldrb r0, [r5, 0xC]
strb r0, [r4, 0x9]
ldrb r1, [r5]
cmp r1, 0
beq _08051DB8
mov r2, r9
cmp r2, 0
beq _08051DA4
ldrb r0, [r5]
movs r1, 0x2
ldrsh r3, [r5, r1]
ldr r1, [r5, 0x4]
str r1, [sp]
adds r1, r6, 0
adds r2, r7, 0
bl sub_805193C
b _08051DDC
.align 2, 0
_08051DA0: .4byte gUnknown_80F6D20
_08051DA4:
ldr r0, _08051DB0
ldr r0, [r0]
ldr r2, _08051DB4
adds r0, r2
strb r1, [r0]
b _08051DDC
.align 2, 0
_08051DB0: .4byte gDungeon
_08051DB4: .4byte 0x0000068b
_08051DB8:
ldr r2, [r5, 0x4]
cmp r2, 0
beq _08051DDC
ldr r0, _08051E2C
ldr r1, [r0]
subs r0, r2, 0x1
lsls r0, 2
adds r0, r1, r0
ldr r3, _08051E30
adds r0, r3
strh r6, [r0]
ldr r0, [r5, 0x4]
subs r0, 0x1
lsls r0, 2
adds r1, r0
ldr r0, _08051E34
adds r1, r0
strh r7, [r1]
_08051DDC:
movs r1, 0x8
ldrsh r0, [r5, r1]
cmp r0, 0
beq _08051DF2
ldrb r3, [r5, 0xA]
mov r1, r8
str r1, [sp]
adds r1, r6, 0
adds r2, r7, 0
bl sub_8051998
_08051DF2:
ldrb r0, [r5, 0xB]
cmp r0, 0x14
beq _08051E08
mov r2, r9
cmp r2, 0
beq _08051E08
ldrb r3, [r5, 0xD]
adds r1, r6, 0
adds r2, r7, 0
bl sub_8051A24
_08051E08:
ldrb r0, [r5, 0xE]
cmp r0, 0
beq _08051E1A
ldrh r0, [r4]
ldr r1, _08051E38
ands r1, r0
movs r0, 0x2
orrs r1, r0
strh r1, [r4]
_08051E1A:
movs r0, 0
add sp, 0x4
pop {r3,r4}
mov r8, r3
mov r9, r4
pop {r4-r7}
pop {r1}
bx r1
.align 2, 0
_08051E2C: .4byte gDungeon
_08051E30: .4byte 0x0000e220
_08051E34: .4byte 0x0000e222
_08051E38: .4byte 0x0000fffc
thumb_func_end sub_8051A74
thumb_func_start sub_8051E3C
sub_8051E3C:
push {r4-r6,lr}
sub sp, 0x4
movs r5, 0
_08051E42:
movs r4, 0
adds r6, r5, 0x1
_08051E46:
adds r0, r4, 0
adds r1, r5, 0
bl GetTileMut
adds r2, r0, 0
ldrb r0, [r2, 0xE]
cmp r0, 0xF
bls _08051E66
adds r1, r0, 0
movs r0, 0
str r0, [sp]
adds r0, r2, 0
adds r2, r4, 0
adds r3, r5, 0
bl sub_8051A74
_08051E66:
adds r4, 0x1
cmp r4, 0x37
ble _08051E46
adds r5, r6, 0
cmp r5, 0x1F
ble _08051E42
add sp, 0x4
pop {r4-r6}
pop {r0}
bx r0
thumb_func_end sub_8051E3C
thumb_func_start sub_8051E7C
sub_8051E7C:
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x14
mov r9, r0
movs r1, 0x4
ldrsh r0, [r0, r1]
mov r2, r9
movs r3, 0x6
ldrsh r1, [r2, r3]
subs r1, 0x1
bl GetTileMut
str r0, [sp, 0x8]
ldrh r1, [r0]
movs r0, 0x80
lsls r0, 5
ands r0, r1
cmp r0, 0
bne _08051EB8
ldr r0, _08051EB4
ldr r1, [r0]
mov r0, r9
bl LogMessageByIdWithPopupCheckUser
b _080520F6
.align 2, 0
_08051EB4: .4byte gUnknown_80FDDF0
_08051EB8:
ldr r0, _08051EF0
ldr r0, [r0]
ldr r1, _08051EF4
adds r0, r1
ldrb r0, [r0]
cmp r0, 0
beq _08051EC8
b _080520EC
_08051EC8:
mov r2, r9
ldrh r1, [r2, 0x6]
subs r1, 0x1
lsls r1, 16
ldrh r0, [r2, 0x4]
orrs r0, r1
str r0, [sp, 0x4]
mov r0, r9
bl GetEntityRoom
lsls r0, 24
lsrs r0, 24
str r0, [sp, 0xC]
mov r3, r9
movs r1, 0x6
ldrsh r0, [r3, r1]
adds r6, r0, 0
subs r6, 0x15
b _08051FE0
.align 2, 0
_08051EF0: .4byte gDungeon
_08051EF4: .4byte 0x00003a09
_08051EF8:
mov r2, r9
movs r3, 0x4
ldrsh r0, [r2, r3]
adds r5, r0, 0
subs r5, 0x14
adds r0, 0x14
adds r1, r6, 0x1
str r1, [sp, 0x10]
cmp r5, r0
bgt _08051FD8
ldr r2, _080520C0
mov r10, r2
_08051F10:
mov r0, r10
ldr r3, [r0]
ldr r1, _080520C4
adds r0, r3, r1
ldr r1, [r0]
subs r2, r5, r1
mov r8, r2
ldr r2, _080520C8
adds r0, r3, r2
ldr r2, [r0]
subs r7, r6, r2
mov r0, r8
cmp r0, 0
blt _08051FCA
cmp r7, 0
blt _08051FCA
cmp r0, 0x7
bgt _08051FCA
cmp r7, 0x7
bgt _08051FCA
adds r0, r1, 0x1
cmp r5, r0
blt _08051FCA
adds r0, r2, 0x1
cmp r6, r0
blt _08051FCA
ldr r1, _080520CC
adds r0, r3, r1
ldr r0, [r0]
subs r0, 0x1
cmp r5, r0
bge _08051FCA
ldr r2, _080520D0
adds r0, r3, r2
ldr r0, [r0]
subs r0, 0x1
cmp r6, r0
bge _08051FCA
adds r0, r5, 0
adds r1, r6, 0
bl GetTileMut
adds r4, r0, 0
ldrh r0, [r4]
movs r3, 0x80
lsls r3, 1
adds r1, r3, 0
ands r0, r1
cmp r0, 0
beq _08051F9A
mov r0, r10
ldr r2, [r0]
lsls r1, r7, 1
adds r1, r7
lsls r1, 3
mov r3, r8
lsls r0, r3, 1
add r0, r8
lsls r0, 6
adds r1, r0
adds r2, r1
ldr r1, _080520D4
adds r0, r2, r1
ldrh r0, [r0]
strh r0, [r4]
ldr r3, _080520D8
adds r2, r3
ldrh r0, [r2]
strh r0, [r4, 0x4]
_08051F9A:
mov r1, r10
ldr r0, [r1]
mov r2, r8
lsls r1, r2, 3
adds r1, r7, r1
ldr r3, _080520DC
adds r0, r3
adds r0, r1
ldrb r1, [r0]
movs r0, 0x1
str r0, [sp]
adds r0, r4, 0
adds r2, r5, 0
adds r3, r6, 0
bl sub_8051A74
ldrh r1, [r4, 0x4]
movs r0, 0x3
orrs r0, r1
strh r0, [r4, 0x4]
ldr r0, [sp, 0xC]
cmp r0, 0xFF
beq _08051FCA
strb r0, [r4, 0x9]
_08051FCA:
adds r5, 0x1
mov r2, r9
movs r3, 0x4
ldrsh r0, [r2, r3]
adds r0, 0x14
cmp r5, r0
ble _08051F10
_08051FD8:
ldr r6, [sp, 0x10]
mov r1, r9
movs r2, 0x6
ldrsh r0, [r1, r2]
_08051FE0:
adds r0, 0x13
cmp r6, r0
ble _08051EF8
mov r3, r9
movs r1, 0x6
ldrsh r0, [r3, r1]
adds r6, r0, 0
subs r6, 0x15
adds r0, 0x13
ldr r7, _080520C0
cmp r6, r0
bgt _0805207A
_08051FF8:
mov r2, r9
movs r3, 0x4
ldrsh r0, [r2, r3]
adds r5, r0, 0
subs r5, 0x14
adds r0, 0x14
adds r1, r6, 0x1
str r1, [sp, 0x10]
cmp r5, r0
bgt _0805206C
ldr r7, _080520C0
_0805200E:
ldr r0, _080520C0
ldr r4, [r0]
ldr r2, _080520C4
adds r0, r4, r2
ldr r2, [r0]
subs r1, r5, r2
ldr r3, _080520C8
adds r0, r4, r3
ldr r3, [r0]
subs r0, r6, r3
cmp r1, 0
blt _0805205E
cmp r0, 0
blt _0805205E
cmp r1, 0x7
bgt _0805205E
cmp r0, 0x7
bgt _0805205E
adds r0, r2, 0x1
cmp r5, r0
blt _0805205E
adds r0, r3, 0x1
cmp r6, r0
blt _0805205E
ldr r1, _080520CC
adds r0, r4, r1
ldr r0, [r0]
subs r0, 0x1
cmp r5, r0
bge _0805205E
ldr r2, _080520D0
adds r0, r4, r2
ldr r0, [r0]
subs r0, 0x1
cmp r6, r0
bge _0805205E
adds r0, r5, 0
adds r1, r6, 0
bl sub_80498A8
_0805205E:
adds r5, 0x1
mov r3, r9
movs r1, 0x4
ldrsh r0, [r3, r1]
adds r0, 0x14
cmp r5, r0
ble _0805200E
_0805206C:
ldr r6, [sp, 0x10]
mov r2, r9
movs r3, 0x6
ldrsh r0, [r2, r3]
adds r0, 0x13
cmp r6, r0
ble _08051FF8
_0805207A:
ldr r0, [r7]
ldr r1, _080520E0
adds r0, r1
movs r1, 0x1
strb r1, [r0]
ldr r2, [sp, 0x8]
ldrh r1, [r2]
ldr r0, _080520E4
ands r0, r1
strh r0, [r2]
mov r3, r9
movs r1, 0x4
ldrsh r0, [r3, r1]
movs r2, 0x6
ldrsh r1, [r3, r2]
subs r1, 0x1
bl sub_80498A8
bl sub_8049B8C
bl sub_8049ED4
add r0, sp, 0x4
bl sub_80429FC
ldr r0, _080520E8
ldr r1, [r0]
mov r0, r9
bl LogMessageByIdWithPopupCheckUser
movs r0, 0x14
movs r1, 0x3C
bl sub_803E708
b _080520F6
.align 2, 0
_080520C0: .4byte gDungeon
_080520C4: .4byte 0x0000e250
_080520C8: .4byte 0x0000e254
_080520CC: .4byte 0x0000e258
_080520D0: .4byte 0x0000e25c
_080520D4: .4byte 0x0000e27c
_080520D8: .4byte 0x0000e280
_080520DC: .4byte 0x0000e87c
_080520E0: .4byte 0x00003a09
_080520E4: .4byte 0x0000efef
_080520E8: .4byte gUnknown_80FDDD0
_080520EC:
ldr r0, _08052108
ldr r1, [r0]
mov r0, r9
bl LogMessageByIdWithPopupCheckUser
_080520F6:
add sp, 0x14
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_08052108: .4byte gUnknown_80FDDF0
thumb_func_end sub_8051E7C
thumb_func_start sub_805210C
sub_805210C:
push {r4-r7,lr}
lsls r0, 24
lsrs r5, r0, 24
movs r3, 0
ldr r7, _080521B4
movs r4, 0x1
ldr r2, [r7]
_0805211A:
ldrb r1, [r2]
adds r0, r4, 0
ands r0, r1
cmp r0, 0
beq _0805212A
ldrb r0, [r2, 0x2]
cmp r0, r5
beq _080521C8
_0805212A:
adds r2, 0x4
adds r3, 0x1
cmp r3, 0x13
ble _0805211A
movs r3, 0
ldr r0, _080521B8
ldr r4, [r0]
movs r6, 0x1
_0805213A:
movs r0, 0x64
adds r2, r3, 0
muls r2, r0
adds r0, r2, r4
ldr r1, _080521BC
adds r0, r1
ldrb r1, [r0]
adds r0, r6, 0
ands r0, r1
cmp r0, 0
beq _0805216C
adds r0, r2, r4
ldr r1, _080521C0
adds r0, r1
ldrb r1, [r0]
adds r0, r6, 0
ands r0, r1
adds r1, r2, r4
cmp r0, 0
beq _0805216C
ldr r2, _080521C4
adds r0, r1, r2
ldrb r0, [r0]
cmp r0, r5
beq _080521C8
_0805216C:
adds r3, 0x1
cmp r3, 0x3
ble _0805213A
movs r3, 0
ldr r0, _080521B8
ldr r4, [r0]
_08052178:
movs r0, 0x58
muls r0, r3
adds r2, r0, r4
ldrb r1, [r2]
movs r0, 0x1
ands r0, r1
cmp r0, 0
beq _08052196
adds r0, r2, 0
adds r0, 0x28
ldrb r0, [r0]
cmp r0, 0
beq _08052196
cmp r0, r5
beq _080521C8
_08052196:
adds r3, 0x1
movs r0, 0xCE
lsls r0, 1
cmp r3, r0
ble _08052178
ldr r0, [r7]
lsls r1, r5, 1
adds r0, 0x50
adds r0, r1
ldrh r0, [r0]
cmp r0, 0
bne _080521C8
movs r0, 0
b _080521CA
.align 2, 0
_080521B4: .4byte gTeamInventoryRef
_080521B8: .4byte gRecruitedPokemonRef
_080521BC: .4byte 0x00008df8
_080521C0: .4byte 0x00008e38
_080521C4: .4byte 0x00008e3a
_080521C8:
movs r0, 0x1
_080521CA:
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end sub_805210C
.align 2,0

View File

@ -2497,7 +2497,7 @@ _0807FA56:
movs r0, 0x11 movs r0, 0x11
mov r1, sp mov r1, sp
movs r2, 0x2 movs r2, 0x2
bl sub_8045684 bl SpawnTrap
cmp r0, 0 cmp r0, 0
beq _0807FA88 beq _0807FA88
str r0, [r4, 0x14] str r0, [r4, 0x14]
@ -2508,7 +2508,7 @@ _0807FA56:
_0807FA72: _0807FA72:
mov r1, sp mov r1, sp
movs r2, 0 movs r2, 0
bl sub_8045684 bl SpawnTrap
cmp r0, 0 cmp r0, 0
beq _0807FA88 beq _0807FA88
str r0, [r4, 0x14] str r0, [r4, 0x14]

View File

@ -3,8 +3,8 @@
#include "structs/dungeon_entity.h" #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); Entity *sub_8045708(DungeonPos *pos);
void sub_80457DC(Entity* ent); void sub_80457DC(Entity* ent);
#endif // GUARD_CODE_80227B8_H #endif // GUARD_CODE_80227B8_H

View File

@ -53,5 +53,11 @@ enum SecondaryStructureType {
void GenerateFloor(void); void GenerateFloor(void);
bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); 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 #endif

View File

@ -105,6 +105,11 @@ static inline bool8 PokemonFlag1(PokemonStruct1 *mon)
return (mon->unk0 >> (FLAG_UNK_1 - 1)) & 1; 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) static inline bool8 PokemonFlag2(PokemonStruct1 *mon)
{ {
return (mon->unk0 >> (FLAG_ON_TEAM - 1)) & 1; return (mon->unk0 >> (FLAG_ON_TEAM - 1)) & 1;

View File

@ -227,7 +227,6 @@ SECTIONS {
src/dungeon_map_access.o(.text); src/dungeon_map_access.o(.text);
src/tile_types.o(.text); src/tile_types.o(.text);
src/dungeon_generation.o(.text); src/dungeon_generation.o(.text);
asm/code_804FD30.o(.text);
src/dungeon_message.o(.text); src/dungeon_message.o(.text);
src/dungeon_move.o(.text); src/dungeon_move.o(.text);
src/move_actions.o(.text); src/move_actions.o(.text);

View File

@ -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; Entity *entity;
s32 i; s32 i;

View File

@ -3,10 +3,13 @@
#include "file_system.h" #include "file_system.h"
#include "tile_types.h" #include "tile_types.h"
#include "dungeon_map_access.h" #include "dungeon_map_access.h"
#include "dungeon_message.h"
#include "dungeon_random.h" #include "dungeon_random.h"
#include "dungeon_util.h"
#include "items.h" #include "items.h"
#include "pokemon.h" #include "pokemon.h"
#include "code_80450F8.h" #include "code_80450F8.h"
#include "code_803E668.h"
#include "constants/direction.h" #include "constants/direction.h"
#include "constants/item.h" #include "constants/item.h"
#include "constants/monster.h" #include "constants/monster.h"
@ -17,15 +20,15 @@
extern const u8 gUnknown_80F6DCC[]; extern const u8 gUnknown_80F6DCC[];
extern struct FileArchive gDungeonFileArchive; extern struct FileArchive gDungeonFileArchive;
extern void ResetFloor(void); extern void sub_80460F8(DungeonPos *, Item *, u32);
extern void ResetFloor(void); extern s32 sub_803DA20(s16 species);
extern void GenerateOneRoomMonsterHouseFloor(void); extern void sub_8049840(void);
extern void ResolveInvalidSpawns(void); extern void sub_80429FC(DungeonPos *r0);
extern void GenerateTwoRoomsWithMonsterHouseFloor(void); extern void sub_80498A8(s32, s32);
extern void sub_8049B8C(void);
extern u8 GetFloorType(); extern u8 GetFloorType();
extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3); extern void sub_806C330(s32 a0, s32 a1, s16 a2, u8 a3);
extern const DungeonPos gAdjacentTileOffsets[];
extern const bool8 gUnknown_80F6DD5[][NUM_DIRECTIONS]; extern const bool8 gUnknown_80F6DD5[][NUM_DIRECTIONS];
enum CardinalDirection enum CardinalDirection
@ -71,48 +74,50 @@ struct GridCell
#define GRID_CELL_LEN 15 #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 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 CreateRoomsAndAnchorsForFixedFloor(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, s32 a5, s32 fixedRoomSizeX, s32 fixedRoomSizeY);
void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber); static void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber);
void sub_8051288(s32 fixedRoomNumber); static void sub_8051288(s32 fixedRoomNumber);
void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY); static void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY);
void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); static void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY);
void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); static void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY);
void GenerateSecondaryStructure(struct GridCell *gridCell); static void GenerateSecondaryStructure(struct GridCell *gridCell);
void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY); static void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY);
void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber); static void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber);
void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags); static void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags);
void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging); static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging);
void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY); static void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY);
static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps); static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps);
void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps); static void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps);
void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); static void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance);
void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain); static void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain);
void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex); static void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex);
void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); static void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance);
void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance); static 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 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 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); static void CreateHallway(s32 startX, s32 startY, s32 endX, s32 endY, bool8 vertical, s32 turnX, s32 turnY);
void EnsureImpassableTilesAreWalls(void); static void EnsureImpassableTilesAreWalls(void);
void sub_804FC74(void); static void sub_804FC74(void);
void sub_804EB30(void); static void FinalizeJunctions(void);
void FinalizeJunctions(void); static void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3);
void sub_804B534(s32 a0, s32 a1, s32 a2, s32 a3); static bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps);
bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps); static void GenerateStandardFloor(s32 a0, s32 a1, FloorProperties *a2);
void GenerateStandardFloor(s32 a0, s32 a1, FloorProperties *a2); static void GenerateOuterRingFloor(FloorProperties *a0);
void GenerateOuterRingFloor(FloorProperties *a0); static void GenerateCrossroadsFloor(FloorProperties *a0);
void GenerateCrossroadsFloor(FloorProperties *a0); static void GenerateLineFloor(FloorProperties *a0);
void GenerateLineFloor(FloorProperties *a0); static void GenerateCrossFloor(FloorProperties *a0);
void GenerateCrossFloor(FloorProperties *a0); static void GenerateBeetleFloor(FloorProperties *a0);
void GenerateBeetleFloor(FloorProperties *a0); static void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps);
void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps); static void sub_8051654(FloorProperties *floorProps);
void sub_8051654(FloorProperties *floorProps); static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps);
void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps); static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse);
void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse);
void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse); static void ResetInnerBoundaryTileRows(void);
bool8 StairsAlwaysReachable(s32 stairsX, s32 stairsY, bool8 markUnreachable); static void GenerateOneRoomMonsterHouseFloor(void);
void ResetInnerBoundaryTileRows(void); static void ResolveInvalidSpawns(void);
static void GenerateTwoRoomsWithMonsterHouseFloor(void);
EWRAM_DATA bool8 gUnknown_202F1A8 = FALSE; EWRAM_DATA bool8 gUnknown_202F1A8 = FALSE;
static EWRAM_DATA bool8 sInvalidGeneration = FALSE; static EWRAM_DATA bool8 sInvalidGeneration = FALSE;
@ -450,7 +455,7 @@ void GenerateFloor(void)
CloseFile(gDungeon->unk13568); CloseFile(gDungeon->unk13568);
} }
void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY) static void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY)
{ {
s32 x, y; s32 x, y;
for (x = xStart; x < maxX; x++) { for (x = xStart; x < maxX; x++) {
@ -490,7 +495,7 @@ void sub_804B534(s32 xStart, s32 yStart, s32 maxX, s32 maxY)
* 6. Create additional "extra hallways" with random walks outside of existing rooms * 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 * 7. Finalize extra room details with imperfections (unused in vanilla?), and structures with secondary terrain
*/ */
void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps) static void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorProps)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -519,7 +524,7 @@ void GenerateStandardFloor(s32 gridSizeX, s32 gridSizeY, FloorProperties *floorP
} }
// GenerateOuterRingFloor - Generates on a 6x4 grid, with the outer border of grid cells being hallways and the inner 4x2 grid being rooms. // GenerateOuterRingFloor - Generates on a 6x4 grid, with the outer border of grid cells being hallways and the inner 4x2 grid being rooms.
void GenerateOuterRingFloor(FloorProperties *floorProps) static void GenerateOuterRingFloor(FloorProperties *floorProps)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -668,7 +673,7 @@ void GenerateOuterRingFloor(FloorProperties *floorProps)
* GenerateCrossroadsFloor - Generates a floor layout with hallways on the inside and rooms on the outside, with empty corners. * GenerateCrossroadsFloor - Generates a floor layout with hallways on the inside and rooms on the outside, with empty corners.
* Also nicknamed "Ladder Layout" by some. * Also nicknamed "Ladder Layout" by some.
*/ */
void GenerateCrossroadsFloor(FloorProperties *floorProps) static void GenerateCrossroadsFloor(FloorProperties *floorProps)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -799,7 +804,7 @@ void GenerateCrossroadsFloor(FloorProperties *floorProps)
} }
// GenerateLineFloor - Generates a floor layout with 5 grid cells in a horizontal line. // GenerateLineFloor - Generates a floor layout with 5 grid cells in a horizontal line.
void GenerateLineFloor(FloorProperties *floorProps) static void GenerateLineFloor(FloorProperties *floorProps)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -837,7 +842,7 @@ void GenerateLineFloor(FloorProperties *floorProps)
} }
// GenerateCrossFloor - Generates a floor layout with 5 rooms arranged in a "plus" or "cross" configuration. // GenerateCrossFloor - Generates a floor layout with 5 rooms arranged in a "plus" or "cross" configuration.
void GenerateCrossFloor(FloorProperties *floorProps) static void GenerateCrossFloor(FloorProperties *floorProps)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -893,7 +898,7 @@ void GenerateCrossFloor(FloorProperties *floorProps)
// GenerateBeetleFloor - Generates a floor layout in a "beetle" shape, with a // GenerateBeetleFloor - Generates a floor layout in a "beetle" shape, with a
// 3x3 grid of rooms, a merged center column, and hallways along each row // 3x3 grid of rooms, a merged center column, and hallways along each row
void GenerateBeetleFloor(FloorProperties *floorProps) static void GenerateBeetleFloor(FloorProperties *floorProps)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -976,7 +981,7 @@ static void MergeRoomsVertically(s32 roomX, s32 roomY1, s32 room_dy, struct Grid
// GenerateOuterRoomsFloor - Generates a floor layout with a ring of rooms and nothing on the interior. // 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. // This layout is bugged and will not properly connect rooms for gridSizeX < 3.
void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps) static void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *floorProps)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -1054,7 +1059,7 @@ void GenerateOuterRoomsFloor(s32 gridSizeX_, s32 gridSizeY_, FloorProperties *fl
GenerateSecondaryStructures(grid, gridSizeX, gridSizeY); GenerateSecondaryStructures(grid, gridSizeX, gridSizeY);
} }
bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps) static bool8 ProcessFixedRoom(s32 fixedRoomNumber, FloorProperties *floorProps)
{ {
s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->x; s32 fixedRoomSizeX = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->x;
s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->y; s32 fixedRoomSizeY = ((struct FixedRoomsData **)(gDungeon->unk13568->data))[fixedRoomNumber]->y;
@ -1118,7 +1123,7 @@ static void sub_804C790(s32 gridSizeX, s32 gridSizeY, s32 fixedRoomSizeX, s32 fi
* GenerateOneRoomMonsterHouseFloor - Generates a floor layout with just one large room which is a Monster House. * 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. * This generator is used as a fallback if the event generation fails too many times.
*/ */
void GenerateOneRoomMonsterHouseFloor(void) static void GenerateOneRoomMonsterHouseFloor(void)
{ {
s32 x, y; s32 x, y;
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
@ -1144,7 +1149,7 @@ void GenerateOneRoomMonsterHouseFloor(void)
} }
// GenerateTwoRoomsWithMonsterHouseFloor - Generates a floor layout with two rooms (left and right), with one being a Monster House. // GenerateTwoRoomsWithMonsterHouseFloor - Generates a floor layout with two rooms (left and right), with one being a Monster House.
void GenerateTwoRoomsWithMonsterHouseFloor(void) static void GenerateTwoRoomsWithMonsterHouseFloor(void)
{ {
struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN]; struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN];
s32 listX[GRID_CELL_LEN]; s32 listX[GRID_CELL_LEN];
@ -1228,7 +1233,7 @@ void GenerateTwoRoomsWithMonsterHouseFloor(void)
* *
* Repeat 4-8 until a check fails. * Repeat 4-8 until a check fails.
*/ */
void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways) static void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 numExtraHallways)
{ {
s32 i, j; s32 i, j;
@ -1426,7 +1431,7 @@ void GenerateExtraHallways(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s
} }
// GetGridPositions - Determines the starting positions of grid cells based on the given floor grid dimensions // GetGridPositions - Determines the starting positions of grid cells based on the given floor grid dimensions
void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY) static void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY)
{ {
s32 i, sum; s32 i, sum;
@ -1449,7 +1454,7 @@ void GetGridPositions(s32 *listX, s32 *listY, s32 gridSizeX, s32 gridSizeY)
* The dungeon grid is an array of grid cells stored in column-major order * 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. * (to give contiguous storage to cells with the same x value), with a fixed column size of 15.
*/ */
void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) static void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY)
{ {
s32 x, y; s32 x, y;
@ -1502,7 +1507,7 @@ void InitDungeonGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gri
*/ */
#define ROOM_BITS_COUNT 256 // Despite max rooms being 32, randomRoomBits can hold up to 256 possible rooms #define ROOM_BITS_COUNT 256 // Despite max rooms being 32, randomRoomBits can hold up to 256 possible rooms
void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber) static void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 roomsNumber)
{ {
bool8 randomRoomBits[ROOM_BITS_COUNT]; bool8 randomRoomBits[ROOM_BITS_COUNT];
s32 i, nShuffles; s32 i, nShuffles;
@ -1602,7 +1607,7 @@ void AssignRooms(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSiz
* *
* If the room is an anchor, a single tile is placed with a hallway indicator for later. * If the room is an anchor, a single tile is placed with a hallway indicator for later.
*/ */
void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags) static void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, u32 roomFlags)
{ {
s32 roomNumber = 0; s32 roomNumber = 0;
s32 x, y; s32 x, y;
@ -1748,7 +1753,7 @@ void CreateRoomsAndAnchors(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s
* *
* If a room doesn't meet the conditions for the secondary structure chosen, it will be left unchanged. * If a room doesn't meet the conditions for the secondary structure chosen, it will be left unchanged.
*/ */
void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) static void GenerateSecondaryStructures(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY)
{ {
s32 x, y; s32 x, y;
@ -1799,7 +1804,7 @@ static void AssignRandomGridCellConnections(struct GridCell grid[GRID_CELL_LEN][
* *
*/ */
void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps) static void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 cursorX, s32 cursorY, FloorProperties *floorProps)
{ {
s32 i; s32 i;
s32 x = cursorX; s32 x = cursorX;
@ -2031,7 +2036,7 @@ void AssignGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN
* Merged rooms take up the full tile space occupied between the two rooms. * Merged rooms take up the full tile space occupied between the two rooms.
* *
*/ */
void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging) static void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY, bool8 disableRoomMerging)
{ {
s32 x, y; s32 x, y;
@ -2407,7 +2412,7 @@ void CreateGridCellConnections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN
* We pick a random corner, derive our direction from the movement being used, then seek up to 10 tiles for one to replace. * We 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. * We avoid getting too close to hallways and ensure our cardinal neighbor tiles match what we expect for open terrain.
*/ */
void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY) static void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY)
{ {
s32 x, y; s32 x, y;
@ -2620,7 +2625,7 @@ void GenerateRoomImperfections(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN
* *
* The vertical flag specifies whether the hallway is being generated horizontally or vertically * The vertical flag specifies whether the hallway is being generated horizontally or vertically
*/ */
void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 turnX_, s32 turnY_) static void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 turnX_, s32 turnY_)
{ {
s32 startX = x; s32 startX = x;
s32 startY = y; s32 startY = y;
@ -2780,7 +2785,7 @@ void CreateHallway(s32 x, s32 y, s32 endX, s32 endY, bool8 vertical, s32 turnX_,
* *
* If no eligible room is found, the room will be removed and filled back in. * If no eligible room is found, the room will be removed and filled back in.
*/ */
void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY) static void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 *listX, s32 *listY)
{ {
s32 x, y; s32 x, y;
@ -2927,7 +2932,7 @@ void EnsureConnectedGrid(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32
* *
* Otherwise, the tile will be a wall. * Otherwise, the tile will be a wall.
*/ */
void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomIndex) static void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomIndex)
{ {
SetTerrainWall(tile); SetTerrainWall(tile);
if (useSecondaryTerrain && tile->room == roomIndex) { if (useSecondaryTerrain && tile->room == roomIndex) {
@ -2962,7 +2967,7 @@ void SetTerrainObstacleChecked(Tile *tile, bool8 useSecondaryTerrain, u8 roomInd
* X | X X X * X | X X X
* X | X X X * X | X X X
*/ */
void FinalizeJunctions(void) static void FinalizeJunctions(void)
{ {
s32 x, y; s32 x, y;
@ -3066,7 +3071,7 @@ void sub_804EB30(void)
* The kecleon shop will occupy the whole room interior, with a one tile margin from the room walls. * 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. * Kecleon shop tiles restrict monster and stair spawns.
*/ */
void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) static void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance)
{ {
s16 listX[GRID_CELL_LEN]; s16 listX[GRID_CELL_LEN];
s16 listY[GRID_CELL_LEN]; s16 listY[GRID_CELL_LEN];
@ -3224,7 +3229,7 @@ void GenerateKecleonShop(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32
* A Monster House will be generated in a random room that's valid, connected, not merged, not a maze room, and * 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. * is not a few unknown conditions.
*/ */
void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) static void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance)
{ {
// To spawn a monster house on this floor: // To spawn a monster house on this floor:
// - It must meet the probability chance // - It must meet the probability chance
@ -3351,7 +3356,7 @@ void GenerateMonsterHouse(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s3
* Candidate maze rooms have to be valid, connected, have odd dimensions, and not have any other features. * 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. * If any candidates are found, the game will select one of these rooms and call GenerateMaze.
*/ */
void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance) static void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gridSizeX, s32 gridSizeY, s32 chance)
{ {
bool8 values[256]; bool8 values[256];
s32 i; s32 i;
@ -3459,7 +3464,7 @@ void GenerateMazeRoom(struct GridCell grid[GRID_CELL_LEN][GRID_CELL_LEN], s32 gr
* surrounded by striples of obstacles (maze walls). * surrounded by striples of obstacles (maze walls).
* *
*/ */
void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain) static void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain)
{ {
s32 curX, curY; s32 curX, curY;
u8 roomIndex; u8 roomIndex;
@ -3550,7 +3555,7 @@ void GenerateMaze(struct GridCell *gridCell, bool8 useSecondaryTerrain)
* If an open tile is found, an obstacle is placed between the two tiles, and (x0, y0) moves to the new open tile. * 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. * This process continues until no valid open tile can be found.
*/ */
void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex) static void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bool8 useSecondaryTerrain, u32 roomIndex)
{ {
while (1) { while (1) {
s32 direction = DungeonRandInt(NUM_CARDINAL_DIRECTIONS); s32 direction = DungeonRandInt(NUM_CARDINAL_DIRECTIONS);
@ -3630,7 +3635,7 @@ void GenerateMazeLine(s32 x0, s32 y0, s32 xMin, s32 yMin, s32 xMax, s32 yMax, bo
} }
} }
void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag) static void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag)
{ {
SetTerrainSecondary(tile); SetTerrainSecondary(tile);
tile->terrainType |= additionalFlag; tile->terrainType |= additionalFlag;
@ -3639,7 +3644,7 @@ void SetTerrainSecondaryWithFlag(Tile *tile, u32 additionalFlag)
/* /*
* SetSpawnFlag5 - Sets unknown spawn flag 0x5 on all tiles in a room * SetSpawnFlag5 - Sets unknown spawn flag 0x5 on all tiles in a room
*/ */
void SetSpawnFlag5(struct GridCell *gridCell) static void SetSpawnFlag5(struct GridCell *gridCell)
{ {
s32 x, y; s32 x, y;
@ -3653,7 +3658,7 @@ void SetSpawnFlag5(struct GridCell *gridCell)
/* /*
* IsNextToHallway - Checks if a tile DungeonPos is either in a hallway or next to one. * IsNextToHallway - Checks if a tile DungeonPos is either in a hallway or next to one.
*/ */
bool8 IsNextToHallway(s32 x, s32 y) static bool8 IsNextToHallway(s32 x, s32 y)
{ {
s32 offsetX, offsetY; s32 offsetX, offsetY;
s32 posX, posY; s32 posX, posY;
@ -3683,7 +3688,7 @@ bool8 IsNextToHallway(s32 x, s32 y)
} }
// See GenerateSecondaryStructures for more information. // See GenerateSecondaryStructures for more information.
void GenerateSecondaryStructure(struct GridCell *gridCell) static void GenerateSecondaryStructure(struct GridCell *gridCell)
{ {
switch (DungeonRandInt(6)) { switch (DungeonRandInt(6)) {
// Generate a "split room" with two sides separated by a line of water/lava // Generate a "split room" with two sides separated by a line of water/lava
@ -3888,7 +3893,7 @@ void GenerateSecondaryStructure(struct GridCell *gridCell)
* *
* A tile marked for an item also must not have a trap there * A tile marked for an item also must not have a trap there
*/ */
void ResolveInvalidSpawns(void) static void ResolveInvalidSpawns(void)
{ {
s32 x, y; s32 x, y;
@ -3919,7 +3924,7 @@ void ResolveInvalidSpawns(void)
} }
// Converts Secondary terrain to both secondary and normal. Possibly to note that it's a water tile? // Converts Secondary terrain to both secondary and normal. Possibly to note that it's a water tile?
void sub_804FC74(void) static void sub_804FC74(void)
{ {
s32 x, y; s32 x, y;
@ -3935,7 +3940,7 @@ void sub_804FC74(void)
/* /*
* EnsureImpassableTilesAreWalls - Force all tiles with the impassable flag to be set as walls. * EnsureImpassableTilesAreWalls - Force all tiles with the impassable flag to be set as walls.
*/ */
void EnsureImpassableTilesAreWalls(void) static void EnsureImpassableTilesAreWalls(void)
{ {
s32 x, y; s32 x, y;
@ -3948,7 +3953,7 @@ void EnsureImpassableTilesAreWalls(void)
} }
} }
void ResetTile(Tile *tile) static void ResetTile(Tile *tile)
{ {
tile->terrainType = 0; tile->terrainType = 0;
tile->spawnOrVisibilityFlags = 0; tile->spawnOrVisibilityFlags = 0;
@ -3977,7 +3982,7 @@ static inline bool8 PosIsOutOfBounds(s32 x, s32 y)
return FALSE; return FALSE;
} }
void ResetFloor(void) static void ResetFloor(void)
{ {
s32 x, y; s32 x, y;
@ -4028,7 +4033,7 @@ struct PositionU8
/* /*
* ShuffleSpawnPositions - Randomly shuffle an array of spawn positions * ShuffleSpawnPositions - Randomly shuffle an array of spawn positions
*/ */
void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count) static void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count)
{ {
s32 i; s32 i;
// Do twice as many swaps as there are items in the array // Do twice as many swaps as there are items in the array
@ -4058,7 +4063,7 @@ void ShuffleSpawnPositions(struct PositionU8 *spawns, s32 count)
*/ */
extern const s16 gUnknown_80F4DA0; extern const s16 gUnknown_80F4DA0;
extern const s16 gUnknown_80F4DA4; extern const s16 gUnknown_80F4DA4;
void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) static void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse)
{ {
struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y];
s32 count; s32 count;
@ -4394,7 +4399,7 @@ void SpawnNonEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse)
/* /*
* SpawnEnemies - Spawns all enemies, including those in forced monster houses * SpawnEnemies - Spawns all enemies, including those in forced monster houses
*/ */
void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse)
{ {
struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y]; struct PositionU8 validSpawns[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y];
s32 count; s32 count;
@ -4590,7 +4595,7 @@ extern const s32 gUnknown_80F6DF8[8];
// https://decomp.me/scratch/sA4YH - Blue // https://decomp.me/scratch/sA4YH - Blue
// https://decomp.me/scratch/SNyV8 - Sky // https://decomp.me/scratch/SNyV8 - Sky
#ifdef NONMATCHING #ifdef NONMATCHING
void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps)
{ {
s32 densityN; s32 densityN;
s32 x, y; s32 x, y;
@ -4848,7 +4853,7 @@ void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps)
} }
#else #else
NAKED void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps) NAKED static void GenerateSecondaryTerrainFormations(u32 flag, FloorProperties *floorProps)
{ {
asm_unified("\n" asm_unified("\n"
" push {r4-r7,lr}\n" " push {r4-r7,lr}\n"
@ -5841,7 +5846,7 @@ static EWRAM_DATA u8 gUnknown_202F1E0 = 0;
static EWRAM_DATA u8 gUnknown_202F1E1 = 0; static EWRAM_DATA u8 gUnknown_202F1E1 = 0;
static UNUSED EWRAM_DATA s32 sUnusedEwram = 0; static UNUSED EWRAM_DATA s32 sUnusedEwram = 0;
u8 sub_80511F0(void) static u8 sub_80511F0(void)
{ {
if (gUnknown_202F1E1 != 0) { if (gUnknown_202F1E1 != 0) {
gUnknown_202F1E1--; gUnknown_202F1E1--;
@ -5861,16 +5866,17 @@ u8 sub_80511F0(void)
return gUnknown_202F1E0; return gUnknown_202F1E0;
} }
bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5); static bool8 PlaceFixedRoomTile(Tile *tile, u8 a1, s32 x, s32 y, u8 a5);
static bool8 sub_805210C(u8 itemId);
bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) static bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5)
{ {
tile->terrainType |= TERRAIN_TYPE_UNBREAKABLE; tile->terrainType |= TERRAIN_TYPE_UNBREAKABLE;
tile->unkE = 0; tile->unkE = 0;
return sub_8051A74(tile, a1, x, y, a5); return PlaceFixedRoomTile(tile, a1, x, y, a5);
} }
void sub_8051288(s32 fixedRoomNumber) static void sub_8051288(s32 fixedRoomNumber)
{ {
s32 x, y; s32 x, y;
Dungeon *dungeon = gDungeon; Dungeon *dungeon = gDungeon;
@ -5931,7 +5937,7 @@ void sub_8051288(s32 fixedRoomNumber)
FinalizeJunctions(); FinalizeJunctions();
} }
void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) static void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber)
{ {
s32 x, y; s32 x, y;
Dungeon *dungeon = gDungeon; Dungeon *dungeon = gDungeon;
@ -5987,7 +5993,7 @@ void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber)
extern const s16 gUnknown_80F57D4[][3][3]; extern const s16 gUnknown_80F57D4[][3][3];
void sub_8051654(FloorProperties *floorProps) static void sub_8051654(FloorProperties *floorProps)
{ {
s32 i, n; s32 i, n;
s32 x, y; s32 x, y;
@ -6094,7 +6100,7 @@ void sub_8051654(FloorProperties *floorProps)
* *
* This is needed because during generation these soft border walls may have been altered or breached. * This is needed because during generation these soft border walls may have been altered or breached.
*/ */
void ResetInnerBoundaryTileRows(void) static void ResetInnerBoundaryTileRows(void)
{ {
s32 x; s32 x;
@ -6113,12 +6119,7 @@ void ResetInnerBoundaryTileRows(void)
} }
} }
bool8 sub_805210C(u8 itemId); static void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags)
extern void sub_80460F8(DungeonPos *, Item *, u32);
extern s32 sub_803DA20(s16 species);
void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags)
{ {
Item item; Item item;
DungeonPos pos = {x, y}; DungeonPos pos = {x, y};
@ -6139,7 +6140,7 @@ void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags)
} }
// s16 species memes strike again. Will the fix ever be discovered? // s16 species memes strike again. Will the fix ever be discovered?
void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_) static void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_, u32 UNUSED unused)
{ {
struct unkStruct_806B7F8 unkStruct; struct unkStruct_806B7F8 unkStruct;
s32 species = SpeciesId(species_); s32 species = SpeciesId(species_);
@ -6167,7 +6168,7 @@ void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_)
} }
} }
void sub_8051A24(u8 trapId, s32 x, s32 y, bool8 isVisible) static void SpawnEnemyTrapAtPos(u8 trapId, s32 x, s32 y, bool8 isVisible)
{ {
DungeonPos pos; DungeonPos pos;
Entity *trapEntity; Entity *trapEntity;
@ -6175,7 +6176,7 @@ void sub_8051A24(u8 trapId, s32 x, s32 y, bool8 isVisible)
pos.x = x; pos.x = x;
pos.y = y; pos.y = y;
trapEntity = sub_8045684(trapId, &pos, 0); trapEntity = SpawnTrap(trapId, &pos, 0);
if (trapEntity != NULL) { if (trapEntity != NULL) {
tile->object = trapEntity; tile->object = trapEntity;
trapEntity->isVisible = isVisible; trapEntity->isVisible = isVisible;
@ -6190,59 +6191,58 @@ struct UnkStruct_80F6D20
s16 unk8; s16 unk8;
u8 unkA; u8 unkA;
u8 unkB; u8 unkB;
u8 fillC; u8 unkC;
u8 unkD; u8 unkD;
u8 unkE; u8 unkE;
}; };
extern const struct UnkStruct_80F6D20 gUnknown_80F6D20[]; extern const struct UnkStruct_80F6D20 gUnknown_80F6D20[];
extern void sub_8049840(void); // 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)
bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5)
{ {
if (a1 > 0xF) { if (fixedRoomActionId > 0xF) {
SetTerrainNormal(tile); SetTerrainNormal(tile);
} }
switch (a1) { switch (fixedRoomActionId) {
case 69: case 69:
gDungeon->unk644.unk40 = x; gDungeon->unk644.unk40 = x;
gDungeon->unk644.unk42 = y; gDungeon->unk644.unk42 = y;
sub_8051A24(0xB, x, y, FALSE); SpawnEnemyTrapAtPos(TRAP_SEAL_TRAP, x, y, FALSE);
// fall through // fall through
case 0: case 0:
SetTerrainNormal(tile); SetTerrainNormal(tile);
tile->room = 0; tile->room = 0;
return FALSE; break;
case 1: case 1:
SetTerrainWall(tile); SetTerrainWall(tile);
tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE); tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE);
tile->room = CORRIDOR_ROOM; tile->room = CORRIDOR_ROOM;
return FALSE; break;
case 4: case 4:
SetTerrainNormal(tile); SetTerrainNormal(tile);
tile->room = 0;
gDungeon->playerSpawn.x = x; gDungeon->playerSpawn.x = x;
gDungeon->playerSpawn.x = y; gDungeon->playerSpawn.y = y;
tile->room = 0; tile->room = 0;
return FALSE; break;
case 5: case 5:
SetTerrainNormal(tile); SetTerrainSecondary(tile);
tile->room = 0; tile->room = 0;
return FALSE; break;
case 6: case 6:
SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL); SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL);
tile->terrainType &= ~(TERRAIN_TYPE_UNBREAKABLE);
tile->room = CORRIDOR_ROOM; tile->room = CORRIDOR_ROOM;
return FALSE; break;
case 7: case 7:
gUnknown_202F1A8 = 1; gUnknown_202F1A8 = 1;
sub_8049840(); sub_8049840();
// fall through
case 10:
SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL); SetTerrainType(tile, TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL);
tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL;
tile->room = CORRIDOR_ROOM; tile->room = CORRIDOR_ROOM;
return FALSE; break;
case 8: case 8:
case 67: case 67:
SetTerrainNormal(tile); SetTerrainNormal(tile);
@ -6251,70 +6251,198 @@ bool8 sub_8051A74(Tile *tile, u8 a1, s32 x, s32 y, u8 a5)
tile->room = 0; tile->room = 0;
gDungeon->stairsSpawn.x = x; gDungeon->stairsSpawn.x = x;
gDungeon->stairsSpawn.y = y; gDungeon->stairsSpawn.y = y;
return FALSE; break;
case 68: case 68:
tile->terrainType |= TERRAIN_TYPE_UNK_x800; tile->terrainType |= TERRAIN_TYPE_UNK_x800;
SetTerrainNormal(tile); SetTerrainNormal(tile);
tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM); tile->spawnOrVisibilityFlags &= ~(SPAWN_FLAG_ITEM);
tile->room = 0; tile->room = 0;
return FALSE; break;
case 9: case 9:
SetTerrainNormal(tile); SetTerrainNormal(tile);
tile->room = CORRIDOR_ROOM; tile->room = CORRIDOR_ROOM;
return FALSE; break;
case 11: case 11:
SetTerrainNormal(tile); SetTerrainNormal(tile);
tile->terrainType |= TERRAIN_TYPE_UNK_x800; tile->terrainType |= TERRAIN_TYPE_UNK_x800;
tile->room = 0; tile->room = 0;
return FALSE; break;
case 12: case 12:
SetTerrainNormal(tile); SetTerrainNormal(tile);
tile->terrainType |= TERRAIN_TYPE_UNK_x1000; tile->terrainType |= TERRAIN_TYPE_UNK_x1000;
tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL;
tile->terrainType |= TERRAIN_TYPE_UNK_x800; tile->terrainType |= TERRAIN_TYPE_UNK_x800;
tile->room = 0; tile->room = 0;
return FALSE; break;
case 2: case 2:
case 13: case 13:
case 14: case 14:
SetTerrainWall(tile); SetTerrainWall(tile);
tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL;
tile->room = CORRIDOR_ROOM; tile->room = CORRIDOR_ROOM;
return FALSE; break;
default: default:
if (a1 > 16 && a1 < 190) { if (fixedRoomActionId > 15 && fixedRoomActionId < 220) {
if (gUnknown_80F6D20[a1].unk0 != 0) { const struct UnkStruct_80F6D20 *ptr = &gUnknown_80F6D20[fixedRoomActionId];
tile->room = ptr->unkC;
if (ptr->unk0 != 0) {
if (a5) { if (a5) {
sub_805193C(gUnknown_80F6D20[a1].unk0, x, y, gUnknown_80F6D20[a1].unk2, gUnknown_80F6D20[a1].unk4); sub_805193C(ptr->unk0, x, y, ptr->unk2, ptr->unk4);
} }
else { else {
gDungeon->unk644.unk47 = gUnknown_80F6D20[a1].unk0; gDungeon->unk644.unk47 = ptr->unk0;
} }
} }
else { else {
if (gUnknown_80F6D20[a1].unk4 != 0) { if (ptr->unk4 != 0) {
gDungeon->unkE220[gUnknown_80F6D20[a1].unk4 - 1].x = x; gDungeon->unkE220[ptr->unk4 - 1].x = x;
gDungeon->unkE220[gUnknown_80F6D20[a1].unk4 - 1].y = y; gDungeon->unkE220[ptr->unk4 - 1].y = y;
} }
} }
if (gUnknown_80F6D20[a1].unk8 != 0) { if (ptr->unk8 != 0) {
sub_8051998(gUnknown_80F6D20[a1].unk8, x, y, gUnknown_80F6D20[a1].unkA); sub_8051998(ptr->unk8, x, y, ptr->unkA, fixedRoomActionId);
} }
if (gUnknown_80F6D20[a1].unkB != 20 && a5) { if (ptr->unkB != 20 && a5) {
sub_8051A24(gUnknown_80F6D20[a1].unkB, x, y, gUnknown_80F6D20[a1].unkD); SpawnEnemyTrapAtPos(ptr->unkB, x, y, ptr->unkD);
} }
if (gUnknown_80F6D20[a1].unkD != 0) { if (ptr->unkE != 0) {
SetTerrainSecondary(tile); SetTerrainSecondary(tile);
} }
} }
break; break;
case 3: case 3:
case 15: case 15:
return FALSE; break;
} }
return FALSE; 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;
}

View File

@ -911,7 +911,7 @@ static void ReadDungeonTraps(DataSerializer *seri)
if (trapID != 0xFF) { if (trapID != 0xFF) {
tile = GetTileMut(pos.x, pos.y); tile = GetTileMut(pos.x, pos.y);
entity = sub_8045684(trapID, &pos, unk1); entity = SpawnTrap(trapID, &pos, unk1);
if (entity) { if (entity) {
tile->object = entity; tile->object = entity;
entity->isVisible = isVisible; entity->isVisible = isVisible;

View File

@ -138,7 +138,7 @@ bool8 LayTrap(DungeonPos *pos, u8 trapID, u8 param_3)
tile->object->isVisible = TRUE; tile->object->isVisible = TRUE;
} }
else { else {
entity = sub_8045684(trapID,pos,param_3); entity = SpawnTrap(trapID,pos,param_3);
if (entity == NULL) if (entity == NULL)
_0807FD6E: _0807FD6E:
return FALSE; return FALSE;