diff options
author | GriffinR <griffin.g.richards@gmail.com> | 2022-01-30 23:00:05 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-30 23:00:05 -0500 |
commit | f494238a9d1f8f486891845a43983e187dbeadf0 (patch) | |
tree | 44fd088cf6f9cb867276f8347a6e035073a5d9ec | |
parent | e30b16f0fd1c5e7b81e5ca62064869fa036e5a58 (diff) | |
parent | 1ff0b0efa96180a774273a4c222a805237e6e7c6 (diff) |
Merge pull request #1621 from GriffinRichards/constants-collision
Add missing collision constant usage
-rw-r--r-- | src/event_object_movement.c | 12 | ||||
-rw-r--r-- | 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; } |