Add missing collision constant usage

This commit is contained in:
GriffinR 2022-01-29 21:13:46 -05:00
parent e30b16f0fd
commit 1ff0b0efa9
2 changed files with 8 additions and 9 deletions

View File

@ -4630,7 +4630,7 @@ u8 GetCollisionAtCoords(struct ObjectEvent *objectEvent, s16 x, s16 y, u32 dir)
u8 direction = dir; u8 direction = dir;
if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y)) if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y))
return COLLISION_OUTSIDE_RANGE; 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; return COLLISION_IMPASSABLE;
else if (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction)) else if (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction))
return COLLISION_IMPASSABLE; return COLLISION_IMPASSABLE;
@ -4646,13 +4646,13 @@ u8 GetCollisionFlagsAtCoords(struct ObjectEvent *objectEvent, s16 x, s16 y, u8 d
u8 flags = 0; u8 flags = 0;
if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y)) if (IsCoordOutsideObjectEventMovementRange(objectEvent, x, y))
flags |= 1; flags |= 1 << (COLLISION_OUTSIDE_RANGE - 1);
if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction) || (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction))) if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == CONNECTION_INVALID || IsMetatileDirectionallyImpassable(objectEvent, x, y, direction) || (objectEvent->trackedByCamera && !CanCameraMoveInDirection(direction)))
flags |= 2; flags |= 1 << (COLLISION_IMPASSABLE - 1);
if (IsElevationMismatchAt(objectEvent->currentElevation, x, y)) if (IsElevationMismatchAt(objectEvent->currentElevation, x, y))
flags |= 4; flags |= 1 << (COLLISION_ELEVATION_MISMATCH - 1);
if (DoesObjectCollideWithObjectAt(objectEvent, x, y)) if (DoesObjectCollideWithObjectAt(objectEvent, x, y))
flags |= 8; flags |= 1 << (COLLISION_OBJECT_EVENT - 1);
return flags; return flags;
} }

View File

@ -367,8 +367,6 @@ static u8 GetTrainerApproachDistanceEast(struct ObjectEvent *trainerObj, s16 ran
return 0; return 0;
} }
#define COLLISION_MASK (~1)
static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 approachDistance, u8 direction) static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 approachDistance, u8 direction)
{ {
s16 x, y; s16 x, y;
@ -385,8 +383,9 @@ static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 ap
MoveCoords(direction, &x, &y); MoveCoords(direction, &x, &y);
for (i = 0; i < approachDistance - 1; i++, 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); collision = GetCollisionFlagsAtCoords(trainerObj, x, y, direction);
if (collision != 0 && (collision & COLLISION_MASK)) if (collision != 0 && (collision & ~(1 << (COLLISION_OUTSIDE_RANGE - 1))))
return 0; return 0;
} }