diff --git a/asm/include/overlay_29_022E908C.inc b/asm/include/overlay_29_022E908C.inc deleted file mode 100644 index 608f1d70..00000000 --- a/asm/include/overlay_29_022E908C.inc +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -.public abs diff --git a/asm/overlay_29_022E908C.s b/asm/overlay_29_022E908C.s deleted file mode 100644 index 88bb9445..00000000 --- a/asm/overlay_29_022E908C.s +++ /dev/null @@ -1,24 +0,0 @@ - .include "asm/macros.inc" - .include "overlay_29_022E908C.inc" - - .text - - arm_func_start GetChebyshevDistance -GetChebyshevDistance: ; 0x022E908C - stmdb sp!, {r3, r4, r5, lr} - mov r5, r0 - mov r4, r1 - ldrsh r1, [r5] - ldrsh r0, [r4] - sub r0, r1, r0 - bl abs - ldrsh r1, [r4, #2] - ldrsh r2, [r5, #2] - mov r4, r0 - sub r0, r2, r1 - bl abs - cmp r4, r0 - movle r4, r0 - mov r0, r4 - ldmia sp!, {r3, r4, r5, pc} - arm_func_end GetChebyshevDistance diff --git a/include/dungeon_range.h b/include/dungeon_range.h index 7308dea5..97a61e7d 100644 --- a/include/dungeon_range.h +++ b/include/dungeon_range.h @@ -3,6 +3,13 @@ #include "dungeon_mode.h" +// Checks if a given target position is in sight from a given origin position. +// If the origin position is on a hallway or r2 is true, checks if both positions are within tiles of each other. +// If the origin position is on a room, checks that the target position is within the boundaries of said room. +// origin: Origin position +// target: Target position +// user_has_dropeye: True to assume the entity standing on the origin position has the dropeye status +// return: True if the target position is in sight from the origin position bool8 IsPositionActuallyInSight(struct position *origin, struct position *target, bool8 user_has_dropeye); #endif //PMDSKY_DUNGEON_RANGE_H diff --git a/include/position_util.h b/include/position_util.h index 6b9b5cfe..adf0025e 100644 --- a/include/position_util.h +++ b/include/position_util.h @@ -5,5 +5,7 @@ // Gets the direction in which a monster should move to go from the origin position to the target position s32 GetDirectionTowardsPosition(struct position *origin, struct position *target); +// Returns the Chebyshev distance between two positions. Calculated as max(abs(x0-x1), abs(y0-y1)). +s32 GetChebyshevDistance(struct position *position_a, struct position *position_b); #endif //PMDSKY_POSITION_UTIL_H diff --git a/main.lsf b/main.lsf index 69899a0d..47a03956 100644 --- a/main.lsf +++ b/main.lsf @@ -374,7 +374,6 @@ Overlay OVY_29 Object asm/overlay_29_022E37DC.o Object src/position_util.o Object asm/overlay_29_rodata_02351628.o - Object asm/overlay_29_022E908C.o Object src/dungeon_range.o Object asm/overlay_29_022E91A4.o Object src/dg_uty.o diff --git a/src/dungeon_ai_movement.c b/src/dungeon_ai_movement.c index b34b168c..fea533d0 100644 --- a/src/dungeon_ai_movement.c +++ b/src/dungeon_ai_movement.c @@ -47,7 +47,6 @@ const s32 FACING_DIRECTION_INCREMENTS[] = {0, 1, -1, 2, -2, 3, -3, 4}; extern bool8 CanTargetEntity(struct entity *user, struct entity *target); extern bool8 CanTargetPosition(struct entity *monster, struct position *position); -extern s32 GetChebyshevDistance(struct position *position_a, struct position *position_b); extern bool8 IsBagFull(); extern bool8 ShouldMonsterFollowLeader(struct entity *monster); extern bool8 IsPositionWithinTwoTiles(struct position *origin, struct position *target); diff --git a/src/overlay_29_022FA430.c b/src/overlay_29_022FA430.c index 3b07a1bc..210a9516 100644 --- a/src/overlay_29_022FA430.c +++ b/src/overlay_29_022FA430.c @@ -5,8 +5,7 @@ #include "overlay_29_022F7364.h" #include "overlay_29_023018AC.h" #include "overlay_29_02336428.h" - -extern s32 GetChebyshevDistance(struct position *position_a, struct position *position_b); +#include "position_util.h" bool8 ShouldMonsterHeadToStairs(struct entity *entity) { diff --git a/src/position_util.c b/src/position_util.c index 7c273257..9d7b4f08 100644 --- a/src/position_util.c +++ b/src/position_util.c @@ -1,4 +1,5 @@ #include "position_util.h" +#include "main_0208655C.h" const s32 POSITION_DISPLACEMENT_TO_DIRECTION[3][3] = { @@ -28,3 +29,10 @@ s32 GetDirectionTowardsPosition(struct position *origin, struct position *target return POSITION_DISPLACEMENT_TO_DIRECTION[++y_diff][++x_diff]; } + +s32 GetChebyshevDistance(struct position *position_a, struct position *position_b) +{ + s32 var1 = abs(position_a->x - position_b->x); + s32 var0 = abs(position_a->y - position_b->y); + return MAX(var1, var0); +}