Decomped GetChebyshevDistance

Decomped by @SethBarberee
This commit is contained in:
AnonymousRandomPerson
2025-10-23 22:39:13 -04:00
parent 33662d75e4
commit fc766689e1
8 changed files with 18 additions and 30 deletions

View File

@@ -1,2 +0,0 @@
#pragma once
.public abs

View File

@@ -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

View File

@@ -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 <dungeon::display_data::visibility_range> 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

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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);
}