From 1ff0b0efa96180a774273a4c222a805237e6e7c6 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 29 Jan 2022 21:13:46 -0500 Subject: [PATCH] Add missing collision constant usage --- src/event_object_movement.c | 12 ++++++------ src/trainer_see.c | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 4bd8d5603..df79a1d62 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -4630,7 +4630,7 @@ u8 GetCollisionAtCoords(struct ObjectEvent *objectEvent, s16 x, s16 y, u32 dir) u8 direction = dir; if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y)) return COLLISION_OUTSIDE_RANGE; - else if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction)) + else if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == CONNECTION_INVALID || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction)) return COLLISION_IMPASSABLE; else if (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction)) return COLLISION_IMPASSABLE; @@ -4646,13 +4646,13 @@ u8 GetCollisionFlagsAtCoords(struct ObjectEvent *objectEvent, s16 x, s16 y, u8 d u8 flags = 0; if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y)) - flags |= 1; - if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction) || (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction))) - flags |= 2; + flags |= 1 << (COLLISION_OUTSIDE_RANGE - 1); + if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == CONNECTION_INVALID || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction) || (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction))) + flags |= 1 << (COLLISION_IMPASSABLE - 1); if (IsElevationMismatchAt(objectEvent->currentElevation, x, y)) - flags |= 4; + flags |= 1 << (COLLISION_ELEVATION_MISMATCH - 1); if (DoesObjectCollideWithObjectAt(objectEvent, x, y)) - flags |= 8; + flags |= 1 << (COLLISION_OBJECT_EVENT - 1); return flags; } diff --git a/src/trainer_see.c b/src/trainer_see.c index 07021a316..dc6c3b917 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -367,8 +367,6 @@ static u8 GetTrainerApproachDistanceEast(struct ObjectEvent *trainerObj, s16 ran return 0; } -#define COLLISION_MASK (~1) - static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 approachDistance, u8 direction) { s16 x, y; @@ -385,8 +383,9 @@ static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 ap MoveCoords(direction, &x, &y); for (i = 0; i < approachDistance - 1; i++, MoveCoords(direction, &x, &y)) { + // Check for collisions on approach, ignoring the "out of range" collision for regular movement collision = GetCollisionFlagsAtCoords(trainerObj, x, y, direction); - if (collision != 0 && (collision & COLLISION_MASK)) + if (collision != 0 && (collision & ~(1 << (COLLISION_OUTSIDE_RANGE - 1)))) return 0; }