diff --git a/asm/include/overlay_29_022E2810.inc b/asm/include/overlay_29_022E28D4.inc similarity index 100% rename from asm/include/overlay_29_022E2810.inc rename to asm/include/overlay_29_022E28D4.inc index 333bb6aa..f4d4270a 100644 --- a/asm/include/overlay_29_022E2810.inc +++ b/asm/include/overlay_29_022E28D4.inc @@ -1,8 +1,7 @@ #pragma once -.public abs .public CanSeeInvisibleMonsters -.public DrawMinimapTile .public DUNGEON_PTR +.public DrawMinimapTile .public EntityIsValid__022E1A1C .public EntityIsValid__022E32E8 .public GetForcedLossReason @@ -13,6 +12,14 @@ .public IsPositionActuallyInSight .public IsPositionInSight .public ItemIsActive__022E330C +.public PrepareItemForPrinting2 +.public SetPreprocessorArgsStringToName +.public StringFromId +.public SubstitutePlaceholderTrapTags +.public TeamMemberHasEnabledIqSkill +.public UpdateMinimap +.public UpdateTrapsVisibility +.public abs .public ov29_022E34C8 .public ov29_022E3534 .public ov29_022E3A58 @@ -22,13 +29,6 @@ .public ov29_0233711C .public ov29_023372A4 .public ov29_0237C84C -.public PrepareItemForPrinting2 -.public SetPreprocessorArgsStringToName .public strcpy -.public StringFromId .public sub_02009194 .public sub_020091B0 -.public SubstitutePlaceholderTrapTags -.public TeamMemberHasEnabledIqSkill -.public UpdateMinimap -.public UpdateTrapsVisibility diff --git a/asm/overlay_29_022E2810.s b/asm/overlay_29_022E28D4.s similarity index 94% rename from asm/overlay_29_022E2810.s rename to asm/overlay_29_022E28D4.s index aada78ca..6b293059 100644 --- a/asm/overlay_29_022E2810.s +++ b/asm/overlay_29_022E28D4.s @@ -1,63 +1,8 @@ .include "asm/macros.inc" - .include "overlay_29_022E2810.inc" + .include "overlay_29_022E28D4.inc" .text - arm_func_start CanTargetEntity -CanTargetEntity: ; 0x022E2810 - stmdb sp!, {r3, r4, r5, lr} - mov r5, r0 - mov r4, r1 - bl EntityIsValid__022E1A1C - cmp r0, #0 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} - mov r0, r4 - bl EntityIsValid__022E1A1C - cmp r0, #0 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} - ldrb r0, [r4, #0x20] - cmp r0, #0 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} - ldr r0, [r4] - cmp r0, #1 - bne _022E28B8 - ldr r0, [r5] - cmp r0, #1 - bne _022E28A4 - mov r0, r5 - bl CanSeeInvisibleMonsters - cmp r0, #0 - ldreq r0, [r4, #0xb4] - ldreqb r0, [r0, #0xef] - cmpeq r0, #1 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} - mov r0, r5 - mov r1, #1 - bl IsBlinded - cmp r0, #0 - beq _022E28B8 - mov r0, #0 - ldmia sp!, {r3, r4, r5, pc} -_022E28A4: - ldr r0, [r4, #0xb4] - ldrb r0, [r0, #0xef] - cmp r0, #1 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} -_022E28B8: - mov r0, r5 - bl HasDropeyeStatus - mov r2, r0 - add r0, r5, #4 - add r1, r4, #4 - bl IsPositionInSight - ldmia sp!, {r3, r4, r5, pc} - arm_func_end CanTargetEntity - arm_func_start ov29_022E28D4 ov29_022E28D4: ; 0x022E28D4 stmdb sp!, {r3, r4, r5, lr} diff --git a/include/dungeon_visibility.h b/include/dungeon_visibility.h index e977f8d6..6b678e2b 100644 --- a/include/dungeon_visibility.h +++ b/include/dungeon_visibility.h @@ -7,5 +7,9 @@ // Calls IsPositionActuallyInSight. Also checks if the user is blinded, if the target is invisible, etc. // This function is almost the same as CanTargetEntity, the only difference is that the latter calls IsPositionInSight instead. bool8 CanSeeTarget(struct entity *user, struct entity *target); +// Checks if a monster can target another entity when controlled by the AI. +// More specifically, it checks if the target is invisible, if the user can see invisible monsters, if the user is blinded and if the target position is in sight from the position of the user (this last check is done by calling IsPositionInSight with the user's and the target's position). +// This function is almost the same as CanSeeTarget, the only difference is that the latter calls IsPositionActuallyInSight instead. +bool8 CanTargetEntity(struct entity *user, struct entity *target); #endif //PMDSKY_DUNGEON_VISIBILITY_H diff --git a/main.lsf b/main.lsf index 30140fee..c5a2a6f0 100644 --- a/main.lsf +++ b/main.lsf @@ -379,7 +379,7 @@ Overlay OVY_29 Object src/dg_object.o Object asm/overlay_29_022E1AD4.o Object src/dungeon_visibility.o - Object asm/overlay_29_022E2810.o + Object asm/overlay_29_022E28D4.o Object src/dg_camera.o Object asm/overlay_29_022E335C.o Object src/dg_effect.o diff --git a/src/dungeon_ai_movement.c b/src/dungeon_ai_movement.c index f1ea6360..f7a5137d 100644 --- a/src/dungeon_ai_movement.c +++ b/src/dungeon_ai_movement.c @@ -47,7 +47,6 @@ struct can_move_in_direction_info 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 bool8 IsPositionWithinTwoTiles(struct position *origin, struct position *target); extern s32 ov29_022FBE04(struct monster*); diff --git a/src/dungeon_visibility.c b/src/dungeon_visibility.c index 967a7af1..4328e5fe 100644 --- a/src/dungeon_visibility.c +++ b/src/dungeon_visibility.c @@ -5,6 +5,8 @@ #include "dungeon_statuses.h" #include "dungeon_util_static.h" +extern bool8 IsPositionInSight(struct position *origin, struct position *target, bool8 user_has_dropeye); + bool8 CanSeeTarget(struct entity *user, struct entity *target) { if (!EntityIsValid__022E1A1C(user)) @@ -32,3 +34,30 @@ bool8 CanSeeTarget(struct entity *user, struct entity *target) return IsPositionActuallyInSight(&user->pos, &target->pos, HasDropeyeStatus(user)); } + +bool8 CanTargetEntity(struct entity *user, struct entity *target) +{ + if (!EntityIsValid__022E1A1C(user)) + return FALSE; + + if (!EntityIsValid__022E1A1C(target)) + return FALSE; + + if (!target->is_visible) + return FALSE; + + if (target->type == ENTITY_MONSTER) + { + if (user->type == ENTITY_MONSTER) + { + if (!CanSeeInvisibleMonsters(user) && GetEntInfo(target)->invisible_class_status.status == STATUS_INVISIBLE_INVISIBLE) + return FALSE; + + if (IsBlinded(user, TRUE)) + return FALSE; + } + else if (GetEntInfo(target)->invisible_class_status.status == STATUS_INVISIBLE_INVISIBLE) + return FALSE; + } + return IsPositionInSight(&user->pos, &target->pos, HasDropeyeStatus(user)); +}