Decomp GetSanitizedRandomTrapId and GetRandomTrapId

This commit is contained in:
slaw-22
2026-05-20 19:11:27 +00:00
parent a6c46ee399
commit f10fde7f91
10 changed files with 54 additions and 79 deletions

View File

@@ -14,7 +14,7 @@
.public LoadWteFromFileDirectory
.public memset
.public MemZero
.public ov29_022E7A30
.public GetRandomTrapId
.public ov29_02352690
.public ov29_02352698
.public ov29_023526A0

View File

@@ -20,7 +20,7 @@
.public LogMessageByIdWithPopupCheckUserUnknown
.public ov29_022E2CA0
.public ov29_022E58B0
.public ov29_022E7A30
.public GetRandomTrapId
.public ov29_022F9840
.public PlaySeByIdIfShouldDisplayEntity
.public SpawnTrap

View File

@@ -20,7 +20,7 @@
.public GetItemInfo
.public GetKecleonIdToSpawnByFloor
.public GetMonsterIdToSpawn
.public GetRandomTrapId
.public GetSanitizedRandomTrapId
.public GetTile
.public GetTrapInfo
.public GetVisibilityRange

View File

@@ -5330,76 +5330,3 @@ _022E7A24: .word 0xFFFF8AD0
_022E7A28: .word 0x000286D2 + LOAD_MAPPA_FILE_ATTRIBUTES_OFFSET
_022E7A2C: .word 0x000286F2 + LOAD_MAPPA_FILE_ATTRIBUTES_OFFSET
arm_func_end LoadMappaFileAttributes
arm_func_start ov29_022E7A30
ov29_022E7A30: ; 0x022E7A30
stmdb sp!, {r3, lr}
ldr r0, _022E7A80 ; =0x00002710
bl DungeonRandInt
ldr r1, _022E7A84 ; =DUNGEON_PTR
#ifdef JAPAN
mov r2, #0
ldr r3, [r1]
b _022E90E0
_022E7A50:
add r1, r3, r2, lsl #1
add r1, r1, #0x2c800
ldrh r1, [r1, #0x8e]
cmp r1, #0
beq _022E90DC
cmp r1, r0
andge r0, r2, #0xff
ldmgeia sp!, {r3, pc}
_022E90DC:
add r2, r2, #1
_022E90E0:
cmp r2, #0x19
#else
mov r3, #0
ldr ip, [r1]
ldr r1, _022E7A88 ; =0x0002C932
b _022E7A70
_022E7A50:
add r2, ip, r3, lsl #1
ldrh r2, [r2, r1]
cmp r2, #0
beq _022E7A6C
cmp r2, r0
andge r0, r3, #0xff
ldmgeia sp!, {r3, pc}
_022E7A6C:
add r3, r3, #1
_022E7A70:
cmp r3, #0x19
#endif
blt _022E7A50
mov r0, #0x10
ldmia sp!, {r3, pc}
.align 2, 0
_022E7A80: .word 0x00002710
_022E7A84: .word DUNGEON_PTR
#ifndef JAPAN
_022E7A88: .word 0x0002C932
#endif
arm_func_end ov29_022E7A30
arm_func_start GetRandomTrapId
GetRandomTrapId: ; 0x022E7A8C
stmdb sp!, {r4, lr}
mov r4, #0
b _022E7AB0
_022E7A98:
bl ov29_022E7A30
cmp r0, #0
cmpne r0, #0x17
cmpne r0, #0x11
bne _022E7AB8
add r4, r4, #1
_022E7AB0:
cmp r4, #0x1e
blt _022E7A98
_022E7AB8:
cmp r4, #0x1e
moveq r0, #0x10
ldmia sp!, {r4, pc}
arm_func_end GetRandomTrapId

View File

@@ -852,7 +852,7 @@ _022ED8C4:
tst r0, #0x40
movne r0, r4
bne _022ED8FC
bl ov29_022E7A30
bl GetRandomTrapId
_022ED8FC:
cmp r0, #0x11
mov r1, r6

View File

@@ -19,7 +19,7 @@ TrySpawnTrap: ; 0x022EDCBC
mov sb, #0
b _022EDD04
_022EDCF0:
bl ov29_022E7A30
bl GetRandomTrapId
mov r7, r0
cmp r7, #0x11
bne _022EDD0C

View File

@@ -1066,7 +1066,7 @@ ApplyRandomTrapEffect: ; 0x022EEF40
str r3, [sp, #0x10 + APPLY_RANDOM_TRAP_EFFECT_OFFSET]
ldr r8, [sp, #0x88]
beq _022EF064
bl GetRandomTrapId
bl GetSanitizedRandomTrapId
ldr r1, _022EF06C ; =ov10_022C4B18
mov r4, r0
ldrb r0, [r1, r4]

7
include/random_trap.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef PMDSKY_RANDOM_TRAP_H
#define PMDSKY_RANDOM_TRAP_H
u8 GetRandomTrapId();
s32 GetSanitizedRandomTrapId();
#endif //PMDSKY_RANDOM_TRAP_H

View File

@@ -506,6 +506,7 @@ Overlay OVY_29
Object asm/overlay_29_022E335C.o
Object src/dg_effect.o
Object asm/overlay_29_022E37DC.o
Object src/random_trap.o
Object src/spawn_1.o
Object src/spawn_2.o
Object asm/overlay_29_022E7EC4.o

40
src/random_trap.c Normal file
View File

@@ -0,0 +1,40 @@
#include "dg_random.h"
#include "dungeon.h"
#include "enums.h"
#include "random_trap.h"
extern struct dungeon *DUNGEON_PTR[];
u8 GetRandomTrapId() {
s32 rnd = DungeonRandInt(10000);
for(s32 i = 0; i < TRAP_NONE; i++) {
u16 weight = DUNGEON_PTR[0]->trap_weights[i];
if(weight == 0) {
continue;
}
if(weight >= rnd) {
return i;
}
}
return TRAP_CHESTNUT_TRAP;
}
s32 GetSanitizedRandomTrapId() {
s32 trap_id;
s32 i;
for(i = 0; i < 30; i++) {
trap_id = GetRandomTrapId();
if(trap_id != TRAP_NULL_TRAP && trap_id != TRAP_RANDOM_TRAP && trap_id != TRAP_WONDER_TILE) {
break;
}
}
if(i == TRAP_0x1E) {
return TRAP_CHESTNUT_TRAP;
}
return trap_id;
}