From 92d098e694a15053d8f8abb685ee3c50a10cb950 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Mon, 22 Sep 2025 21:44:48 -0400 Subject: [PATCH] Decomped FindDirectionOfAdjacentMonsterWithItem --- asm/include/overlay_29_0230F8D0.inc | 6 ---- asm/overlay_29_0230F8D0.s | 56 ----------------------------- include/overlay_29_0230F8AC.h | 3 ++ include/overlay_29_0230F980.h | 9 ----- main.lsf | 2 -- src/dungeon_ai_attack.c | 9 +++-- src/overlay_29_0230F8AC.c | 29 +++++++++++++++ src/overlay_29_0230F980.c | 10 ------ 8 files changed, 36 insertions(+), 88 deletions(-) delete mode 100644 asm/include/overlay_29_0230F8D0.inc delete mode 100644 asm/overlay_29_0230F8D0.s delete mode 100644 include/overlay_29_0230F980.h delete mode 100644 src/overlay_29_0230F980.c diff --git a/asm/include/overlay_29_0230F8D0.inc b/asm/include/overlay_29_0230F8D0.inc deleted file mode 100644 index 130387c0..00000000 --- a/asm/include/overlay_29_0230F8D0.inc +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -.public DIRECTIONS_XY -.public EntityIsValid__0230F008 -.public GetTile -.public IsMonster__0230F980 -.public ItemIsActive__0230F810 diff --git a/asm/overlay_29_0230F8D0.s b/asm/overlay_29_0230F8D0.s deleted file mode 100644 index 199be58e..00000000 --- a/asm/overlay_29_0230F8D0.s +++ /dev/null @@ -1,56 +0,0 @@ - .include "asm/macros.inc" - .include "overlay_29_0230F8D0.inc" - - .text - - arm_func_start ov29_0230F8D0 -ov29_0230F8D0: ; 0x0230F8D0 - stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, lr} - mov r8, r0 - mov r7, r1 - bl EntityIsValid__0230F008 - cmp r0, #0 - moveq r0, #0xff - ldmeqia sp!, {r3, r4, r5, r6, r7, r8, sb, pc} - ldr r0, [r8, #0xb4] - mov r5, #0 - ldrb r6, [r0, #0x4c] - ldr r4, _0230F97C ; =DIRECTIONS_XY - b _0230F96C -_0230F900: - mov r1, r6, lsl #2 - add r0, r4, r6, lsl #2 - ldrsh ip, [r8, #4] - ldrsh r3, [r4, r1] - ldrsh r2, [r8, #6] - ldrsh r1, [r0, #2] - add r0, ip, r3 - add r1, r2, r1 - bl GetTile - ldr sb, [r0, #0xc] - cmp sb, #0 - beq _0230F958 - mov r0, sb - bl IsMonster__0230F980 - cmp r0, #0 - beq _0230F958 - mov r0, sb - mov r1, r7 - bl ItemIsActive__0230F810 - cmp r0, #0 - movne r0, r6 - ldmneia sp!, {r3, r4, r5, r6, r7, r8, sb, pc} -_0230F958: - add r0, r6, #1 - and r0, r0, #0xff - add r1, r5, #1 - and r6, r0, #7 - and r5, r1, #0xff -_0230F96C: - cmp r5, #8 - blo _0230F900 - mov r0, #0xff - ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, pc} - .align 2, 0 -_0230F97C: .word DIRECTIONS_XY - arm_func_end ov29_0230F8D0 diff --git a/include/overlay_29_0230F8AC.h b/include/overlay_29_0230F8AC.h index d6c850ba..40dd28a9 100644 --- a/include/overlay_29_0230F8AC.h +++ b/include/overlay_29_0230F8AC.h @@ -5,5 +5,8 @@ // Checks if a monster is a team member under the effects of a certain exclusive item effect. bool8 ExclusiveItemEffectIsActive__0230F8AC(struct entity *entity, enum exclusive_item_effect_id effect_id); +u8 FindDirectionOfAdjacentMonsterWithItem(struct entity *pokemon, enum item_id item_id); +// Checks if an entity is a monster (entity type 1). +bool8 IsMonster__0230F980(struct entity *entity); #endif //PMDSKY_OVERLAY_29_0230F8AC_H diff --git a/include/overlay_29_0230F980.h b/include/overlay_29_0230F980.h deleted file mode 100644 index 5329bd42..00000000 --- a/include/overlay_29_0230F980.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef PMDSKY_OVERLAY_29_0230F980_H -#define PMDSKY_OVERLAY_29_0230F980_H - -#include "dungeon_mode.h" - -// Checks if an entity is a monster (entity type 1). -bool8 IsMonster__0230F980(struct entity *entity); - -#endif //PMDSKY_OVERLAY_29_0230F980_H diff --git a/main.lsf b/main.lsf index b942915b..8f3e9988 100644 --- a/main.lsf +++ b/main.lsf @@ -496,8 +496,6 @@ Overlay OVY_29 Object src/overlay_29_0230F810.o Object asm/overlay_29_0230F840.o Object src/overlay_29_0230F8AC.o - Object asm/overlay_29_0230F8D0.o - Object src/overlay_29_0230F980.o Object asm/overlay_29_0230F9A4.o Object src/overlay_29_02311010.o Object asm/overlay_29_02311088.o diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index be8d8256..71ea85d4 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -21,6 +21,7 @@ #include "moves_2.h" #include "moves_3.h" #include "moves_4.h" +#include "overlay_29_0230F8AC.h" #include "overlay_29_0231ACAC.h" #include "position_util.h" @@ -33,8 +34,6 @@ s32 AI_POTENTIAL_ATTACK_TARGET_WEIGHTS[NUM_DIRECTIONS] = {0}; struct entity *AI_POTENTIAL_ATTACK_TARGETS[NUM_DIRECTIONS] = {0}; #endif -extern enum direction_id ov29_0230F8D0(struct entity *pokemon, s32); - void ResetAiCanAttackInDirection() { for (s32 i = 0; i < NUM_DIRECTIONS; i++) @@ -945,10 +944,10 @@ bool8 TargetRegularAttack(struct entity *pokemon, u32 *target_dir, bool8 skip_pe face_turn_limit = 1; else { - enum direction_id ov29_0230F8D0_result = ov29_0230F8D0(pokemon, 15); + u8 gaggle_specs_direction = FindDirectionOfAdjacentMonsterWithItem(pokemon, ITEM_GAGGLE_SPECS); face_turn_limit = 8; - if (ov29_0230F8D0_result != 0xFF) - direction = ov29_0230F8D0_result; + if (gaggle_specs_direction != DIR_NONE_UNSIGNED) + direction = gaggle_specs_direction; } s32 potential_attack_target_directions[NUM_DIRECTIONS]; diff --git a/src/overlay_29_0230F8AC.c b/src/overlay_29_0230F8AC.c index f8f695cc..40600e37 100644 --- a/src/overlay_29_0230F8AC.c +++ b/src/overlay_29_0230F8AC.c @@ -1,6 +1,10 @@ #include "overlay_29_0230F8AC.h" +#include "dungeon_ai_items_1.h" +#include "dungeon_map_access.h" +#include "dungeon_util.h" #include "dungeon_util_static.h" #include "exclusive_item.h" +#include "overlay_29_0230F810.h" bool8 ExclusiveItemEffectIsActive__0230F8AC(struct entity *entity, enum exclusive_item_effect_id effect_id) { @@ -10,3 +14,28 @@ bool8 ExclusiveItemEffectIsActive__0230F8AC(struct entity *entity, enum exclusiv return FALSE; } + +u8 FindDirectionOfAdjacentMonsterWithItem(struct entity *pokemon, enum item_id item_id) +{ + if (!EntityIsValid__0230F008(pokemon)) + return DIR_NONE_UNSIGNED; + + u8 i = 0; + u8 direction = GetEntInfo(pokemon)->action.direction; + for (; i < NUM_DIRECTIONS; i++, direction = (u8)(direction + 1) & DIRECTION_MASK) + { + struct entity *monster_in_direction = GetTile(pokemon->pos.x + DIRECTIONS_XY[direction].x, pokemon->pos.y + DIRECTIONS_XY[direction].y)->monster; + if (monster_in_direction != NULL && IsMonster__0230F980(monster_in_direction) && ItemIsActive__0230F810(monster_in_direction, item_id)) + return direction; + } + + return DIR_NONE_UNSIGNED; +} + +bool8 IsMonster__0230F980(struct entity *entity) +{ + if (entity == NULL) + return FALSE; + + return GetEntityType(entity) == ENTITY_MONSTER; +} diff --git a/src/overlay_29_0230F980.c b/src/overlay_29_0230F980.c deleted file mode 100644 index c1b3358a..00000000 --- a/src/overlay_29_0230F980.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "overlay_29_0230F980.h" -#include "dungeon_util_static.h" - -bool8 IsMonster__0230F980(struct entity *entity) -{ - if (entity == NULL) - return FALSE; - - return GetEntityType(entity) == ENTITY_MONSTER; -}