Skip to content

Commit

Permalink
feat: publish rsmod-pathfinder 4.2.5 - add route blocker flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraviolet-jordan committed Jan 21, 2024
1 parent f1f15d9 commit 1114386
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@2004scape/rsmod-pathfinder",
"version": "4.2.4",
"version": "4.2.5",
"description": "A breadth-first search path finder.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
15 changes: 12 additions & 3 deletions src/rsmod/collision/CollisionStrategies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Outdoors implements CollisionStrategy {
}

class LineOfSight implements CollisionStrategy {
static BLOCK_MOVEMENT: number =
private static readonly BLOCK_MOVEMENT: number =
CollisionFlag.WALL_NORTH_WEST |
CollisionFlag.WALL_NORTH |
CollisionFlag.WALL_NORTH_EAST |
Expand All @@ -38,11 +38,20 @@ class LineOfSight implements CollisionStrategy {
CollisionFlag.WALL_WEST |
CollisionFlag.LOC;

static BLOCK_ROUTE: number = CollisionFlag.PLAYER;
private static readonly BLOCK_ROUTE: number =
CollisionFlag.WALL_NORTH_WEST_ROUTE_BLOCKER |
CollisionFlag.WALL_NORTH_ROUTE_BLOCKER |
CollisionFlag.WALL_NORTH_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_WEST_ROUTE_BLOCKER |
CollisionFlag.WALL_WEST_ROUTE_BLOCKER |
CollisionFlag.LOC_ROUTE_BLOCKER;

canMove(tileFlag: number, blockFlag: number): boolean {
const movementFlags: number = (blockFlag & LineOfSight.BLOCK_MOVEMENT) << 9;
const routeFlags: number = LineOfSight.BLOCK_ROUTE;
const routeFlags: number = (blockFlag & LineOfSight.BLOCK_ROUTE) >> 13;
const finalBlockFlag: number = movementFlags | routeFlags;
return (tileFlag & finalBlockFlag) === CollisionFlag.OPEN;
}
Expand Down
58 changes: 51 additions & 7 deletions src/rsmod/flag/CollisionFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export default class CollisionFlag {
static readonly PLAYER: number = 0x100000;

static readonly FLOOR: number = 0x200000;
static readonly WALL_NORTH_WEST_ROUTE_BLOCKER: number = 0x400000;
static readonly WALL_NORTH_ROUTE_BLOCKER: number = 0x800000;
static readonly WALL_NORTH_EAST_ROUTE_BLOCKER: number = 0x1000000;
static readonly WALL_EAST_ROUTE_BLOCKER: number = 0x2000000;
static readonly WALL_SOUTH_EAST_ROUTE_BLOCKER: number = 0x4000000;
static readonly WALL_SOUTH_ROUTE_BLOCKER: number = 0x8000000;
static readonly WALL_SOUTH_WEST_ROUTE_BLOCKER: number = 0x10000000;
static readonly WALL_WEST_ROUTE_BLOCKER: number = 0x20000000;
static readonly LOC_ROUTE_BLOCKER: number = 0x40000000;

/**
* Roof flag, used to bind NPCs to not leave the buildings they spawn in. This is a custom flag.
Expand All @@ -56,18 +65,53 @@ export default class CollisionFlag {
static readonly BLOCK_NORTH: number = CollisionFlag.WALL_SOUTH | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_SOUTH_WEST: number = CollisionFlag.WALL_NORTH | CollisionFlag.WALL_NORTH_EAST | CollisionFlag.WALL_EAST | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_SOUTH_EAST: number = CollisionFlag.WALL_NORTH_WEST | CollisionFlag.WALL_NORTH | CollisionFlag.WALL_WEST | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_NORTH_WEST: number = CollisionFlag.WALL_EAST | CollisionFlag.WALL_SOUTH_EAST | CollisionFlag.WALL_SOUTH | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_NORTH_EAST: number = CollisionFlag.WALL_SOUTH | CollisionFlag.WALL_SOUTH_WEST | CollisionFlag.WALL_WEST | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_NORTH_AND_SOUTH_EAST: number = CollisionFlag.WALL_NORTH | CollisionFlag.WALL_NORTH_EAST | CollisionFlag.WALL_EAST | CollisionFlag.WALL_SOUTH_EAST | CollisionFlag.WALL_SOUTH | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_NORTH_AND_SOUTH_WEST: number = CollisionFlag.WALL_NORTH_WEST | CollisionFlag.WALL_NORTH | CollisionFlag.WALL_SOUTH | CollisionFlag.WALL_SOUTH_WEST | CollisionFlag.WALL_WEST | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_NORTH_EAST_AND_WEST: number = CollisionFlag.WALL_NORTH_WEST | CollisionFlag.WALL_NORTH | CollisionFlag.WALL_NORTH_EAST | CollisionFlag.WALL_EAST | CollisionFlag.WALL_WEST | CollisionFlag.WALK_BLOCKED;

static readonly BLOCK_SOUTH_EAST_AND_WEST: number = CollisionFlag.WALL_EAST | CollisionFlag.WALL_SOUTH_EAST | CollisionFlag.WALL_SOUTH | CollisionFlag.WALL_SOUTH_WEST | CollisionFlag.WALL_WEST | CollisionFlag.WALK_BLOCKED;

/* Route blocker flags. These are used in ~550+ clients to generate paths through bankers and such. */
static readonly BLOCK_WEST_ROUTE_BLOCKER: number = CollisionFlag.WALL_EAST_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_EAST_ROUTE_BLOCKER: number = CollisionFlag.WALL_WEST_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_SOUTH_ROUTE_BLOCKER: number = CollisionFlag.WALL_NORTH_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_NORTH_ROUTE_BLOCKER: number = CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_SOUTH_WEST_ROUTE_BLOCKER: number = CollisionFlag.WALL_NORTH_ROUTE_BLOCKER | CollisionFlag.WALL_NORTH_EAST_ROUTE_BLOCKER | CollisionFlag.WALL_EAST_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_SOUTH_EAST_ROUTE_BLOCKER: number = CollisionFlag.WALL_NORTH_WEST_ROUTE_BLOCKER | CollisionFlag.WALL_NORTH_ROUTE_BLOCKER | CollisionFlag.WALL_WEST_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_NORTH_WEST_ROUTE_BLOCKER: number = CollisionFlag.WALL_EAST_ROUTE_BLOCKER | CollisionFlag.WALL_SOUTH_EAST_ROUTE_BLOCKER | CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_NORTH_EAST_ROUTE_BLOCKER: number = CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER | CollisionFlag.WALL_SOUTH_WEST_ROUTE_BLOCKER | CollisionFlag.WALL_WEST_ROUTE_BLOCKER | CollisionFlag.LOC_ROUTE_BLOCKER | CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_NORTH_AND_SOUTH_EAST_ROUTE_BLOCKER: number =
CollisionFlag.WALL_NORTH_ROUTE_BLOCKER |
CollisionFlag.WALL_NORTH_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER |
CollisionFlag.LOC_ROUTE_BLOCKER |
CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_NORTH_AND_SOUTH_WEST_ROUTE_BLOCKER: number =
CollisionFlag.WALL_NORTH_WEST_ROUTE_BLOCKER |
CollisionFlag.WALL_NORTH_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_WEST_ROUTE_BLOCKER |
CollisionFlag.WALL_WEST_ROUTE_BLOCKER |
CollisionFlag.LOC_ROUTE_BLOCKER |
CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_NORTH_EAST_AND_WEST_ROUTE_BLOCKER: number =
CollisionFlag.WALL_NORTH_WEST_ROUTE_BLOCKER |
CollisionFlag.WALL_NORTH_ROUTE_BLOCKER |
CollisionFlag.WALL_NORTH_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_WEST_ROUTE_BLOCKER |
CollisionFlag.LOC_ROUTE_BLOCKER |
CollisionFlag.FLOOR_BLOCKED;
static readonly BLOCK_SOUTH_EAST_AND_WEST_ROUTE_BLOCKER: number =
CollisionFlag.WALL_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_EAST_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_ROUTE_BLOCKER |
CollisionFlag.WALL_SOUTH_WEST_ROUTE_BLOCKER |
CollisionFlag.WALL_WEST_ROUTE_BLOCKER |
CollisionFlag.LOC_ROUTE_BLOCKER |
CollisionFlag.FLOOR_BLOCKED;
}
2 changes: 1 addition & 1 deletion test/rsmod/StepValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('StepValidator', () => {
expect(validated).toBeTruthy();

const validated2 = stepValidator.canTravel(level, destX, destZ, dirX, dirZ, 1, 0, CollisionStrategies.LINE_OF_SIGHT);
expect(validated2).toBeFalsy();
expect(validated2).toBeTruthy();
}
}
});
Expand Down

0 comments on commit 1114386

Please sign in to comment.