Skip to content

Commit

Permalink
fix: line of sight & walk now checks for BLOCK_PLAYERS flag
Browse files Browse the repository at this point in the history
update version to 2.4.5
  • Loading branch information
Z-Kris committed Dec 25, 2023
1 parent 52e7658 commit 4962060
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kotlin.code.style=official
group=io.blurite
version=2.4.4
version=2.4.5
56 changes: 39 additions & 17 deletions src/main/kotlin/org/rsmod/pathfinder/LineValidator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.rsmod.pathfinder

import org.rsmod.pathfinder.flag.CollisionFlag
import org.rsmod.pathfinder.flag.CollisionFlag.BLOCK_PLAYERS
import org.rsmod.pathfinder.flag.CollisionFlag.OBJECT_PROJECTILE_BLOCKER
import org.rsmod.pathfinder.flag.CollisionFlag.WALL_EAST_PROJECTILE_BLOCKER
import org.rsmod.pathfinder.flag.CollisionFlag.WALL_NORTH_PROJECTILE_BLOCKER
Expand Down Expand Up @@ -148,15 +149,15 @@ public class LineValidator(
currX += offsetX
val currY = scaleDown(scaledY)

if (los && currX == endX && currY == endY) xFlags = xFlags and OBJECT_PROJECTILE_BLOCKER.inv()
if (los && currX == endX && currY == endY) xFlags = xFlags and LAST_TILE_EXCLUDED_FLAGS.inv()
if (flags.isFlagged(baseX, baseY, currX, currY, z, xFlags)) {
return FAILED_ROUTE
}

scaledY += tangent

val nextY = scaleDown(scaledY)
if (los && currX == endX && nextY == endY) yFlags = yFlags and OBJECT_PROJECTILE_BLOCKER.inv()
if (los && currX == endX && nextY == endY) yFlags = yFlags and LAST_TILE_EXCLUDED_FLAGS.inv()
if (nextY != currY && flags.isFlagged(baseX, baseY, currX, nextY, z, yFlags)) {
return FAILED_ROUTE
}
Expand All @@ -172,15 +173,15 @@ public class LineValidator(
while (currY != endY) {
currY += offsetY
val currX = scaleDown(scaledX)
if (los && currX == endX && currY == endY) yFlags = yFlags and OBJECT_PROJECTILE_BLOCKER.inv()
if (los && currX == endX && currY == endY) yFlags = yFlags and LAST_TILE_EXCLUDED_FLAGS.inv()
if (flags.isFlagged(baseX, baseY, currX, currY, z, yFlags)) {
return FAILED_ROUTE
}

scaledX += tangent

val nextX = scaleDown(scaledX)
if (los && nextX == endX && currY == endY) xFlags = xFlags and OBJECT_PROJECTILE_BLOCKER.inv()
if (los && nextX == endX && currY == endY) xFlags = xFlags and LAST_TILE_EXCLUDED_FLAGS.inv()
if (nextX != currX && flags.isFlagged(baseX, baseY, nextX, currY, z, xFlags)) {
return FAILED_ROUTE
}
Expand Down Expand Up @@ -231,19 +232,40 @@ public class LineValidator(
private companion object {
private val FAILED_ROUTE = Route(ArrayDeque(), alternative = false, success = false)
private val SUCCESSFUL_ROUTE = Route(ArrayDeque(), alternative = false, success = true)
private const val SIGHT_BLOCKED_NORTH = OBJECT_PROJECTILE_BLOCKER or WALL_NORTH_PROJECTILE_BLOCKER
private const val SIGHT_BLOCKED_EAST = OBJECT_PROJECTILE_BLOCKER or WALL_EAST_PROJECTILE_BLOCKER
private const val SIGHT_BLOCKED_SOUTH = OBJECT_PROJECTILE_BLOCKER or WALL_SOUTH_PROJECTILE_BLOCKER
private const val SIGHT_BLOCKED_WEST = OBJECT_PROJECTILE_BLOCKER or WALL_WEST_PROJECTILE_BLOCKER

private const val WALK_BLOCKED_NORTH =
CollisionFlag.WALL_NORTH or CollisionFlag.OBJECT or CollisionFlag.FLOOR_DECORATION or CollisionFlag.FLOOR
private const val WALK_BLOCKED_EAST =
CollisionFlag.WALL_EAST or CollisionFlag.OBJECT or CollisionFlag.FLOOR_DECORATION or CollisionFlag.FLOOR
private const val WALK_BLOCKED_SOUTH =
CollisionFlag.WALL_SOUTH or CollisionFlag.OBJECT or CollisionFlag.FLOOR_DECORATION or CollisionFlag.FLOOR
private const val WALK_BLOCKED_WEST =
CollisionFlag.WALL_WEST or CollisionFlag.OBJECT or CollisionFlag.FLOOR_DECORATION or CollisionFlag.FLOOR
private const val LAST_TILE_EXCLUDED_FLAGS = OBJECT_PROJECTILE_BLOCKER or BLOCK_PLAYERS
private const val SIGHT_BLOCKED_NORTH = OBJECT_PROJECTILE_BLOCKER
.or(WALL_NORTH_PROJECTILE_BLOCKER)
.or(BLOCK_PLAYERS)
private const val SIGHT_BLOCKED_EAST = OBJECT_PROJECTILE_BLOCKER
.or(WALL_EAST_PROJECTILE_BLOCKER)
.or(BLOCK_PLAYERS)
private const val SIGHT_BLOCKED_SOUTH = OBJECT_PROJECTILE_BLOCKER
.or(WALL_SOUTH_PROJECTILE_BLOCKER)
.or(BLOCK_PLAYERS)
private const val SIGHT_BLOCKED_WEST = OBJECT_PROJECTILE_BLOCKER
.or(WALL_WEST_PROJECTILE_BLOCKER)
.or(BLOCK_PLAYERS)

private const val WALK_BLOCKED_NORTH = CollisionFlag.WALL_NORTH
.or(CollisionFlag.OBJECT)
.or(CollisionFlag.FLOOR_DECORATION)
.or(CollisionFlag.FLOOR)
.or(BLOCK_PLAYERS)
private const val WALK_BLOCKED_EAST = CollisionFlag.WALL_EAST
.or(CollisionFlag.OBJECT)
.or(CollisionFlag.FLOOR_DECORATION)
.or(CollisionFlag.FLOOR)
.or(BLOCK_PLAYERS)
private const val WALK_BLOCKED_SOUTH = CollisionFlag.WALL_SOUTH
.or(CollisionFlag.OBJECT)
.or(CollisionFlag.FLOOR_DECORATION)
.or(CollisionFlag.FLOOR)
.or(BLOCK_PLAYERS)
private const val WALK_BLOCKED_WEST = CollisionFlag.WALL_WEST
.or(CollisionFlag.OBJECT)
.or(CollisionFlag.FLOOR_DECORATION)
.or(CollisionFlag.FLOOR)
.or(BLOCK_PLAYERS)

private const val SCALE = 16
private val HALF_TILE = scaleUp(tiles = 1) / 2
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/org/rsmod/pathfinder/flag/CollisionFlag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public object CollisionFlag {

/**
* Custom flag dedicated to blocking NPCs.
* It should be noted that this is a custom flag, and you do not need to use this.
* The pathfinder takes the flag as a custom option, so you may use any other flag, this just defines
* a reliable constant to use
*/
public const val BLOCK_NPCS: Int = 0x80000

Expand Down

0 comments on commit 4962060

Please sign in to comment.