Regarding Clipping planes and tiles

Recommended Posts

Dunno if this is in the right section, but posting in regards of a bunch of noob questions and general information.

So I was snooping around and found this thread

Khaleesi posted a nice solution for the given problem

```static final int UNWALKABLE = 256 | 0x200000 | 0x40000;

public static boolean isWalkable(int flag) {
return (flag & (UNWALKABLE)) == 0;
}

XClippingPlane[] clippingPlanes = script.client.accessor.getClippingPlanes();
int[][] map = clippingPlanes[script.myPlayer().getZ()].getTileFlags();

for(int i = 0; i < map.length;i++){
for(int j = 0; j < map[i].length; j++){
if(isWalkable(map[i][j]))
//store in list?
}
}```

I tried playing around with this, but didn't succeed in the end.

My extremely nooby questions would be (spare the flame ):

1) What the hell are these clipping planes and how can I use the given information for my benefit?

2) What are tile/clipping plane flags?

3) What are tiles exactly in OSRS (in depth). A  NxN size polygon of points?

4) In the given code above there's a comment "//store in list?". First thing that comes to mind is to store each tile POSITION and there you have - you know where you can walk and where you can't. Didn't suceed in this.

5) How does a tile map to a position exactly?

Edited by nosepicker
Share on other sites

6 hours ago, nosepicker said:

Dunno if this is in the right section, but posting in regards of a bunch of noob questions and general information.

So I was snooping around and found this thread

Khaleesi posted a nice solution for the given problem

```
static final int UNWALKABLE = 256 | 0x200000 | 0x40000;

public static boolean isWalkable(int flag) {
return (flag & (UNWALKABLE)) == 0;
}

XClippingPlane[] clippingPlanes = script.client.accessor.getClippingPlanes();
int[][] map = clippingPlanes[script.myPlayer().getZ()].getTileFlags();

for(int i = 0; i < map.length;i++){
for(int j = 0; j < map[i].length; j++){
if(isWalkable(map[i][j]))
//store in list?
}
}```

I tried playing around with this, but didn't succeed in the end.

My extremely nooby questions would be (spare the flame ):

1) What the hell are these clipping planes and how can I use the given information for my benefit?

2) What are tile/clipping plane flags?

3) What are tiles exactly in OSRS (in depth). A  NxN size polygon of points?

4) In the given code above there's a comment "//store in list?". First thing that comes to mind is to store each tile POSITION and there you have - you know where you can walk and where you can't. Didn't suceed in this.

5) How does a tile map to a position exactly?

I'm interested in this as well, though wouldn't it make more sense in the Scripting Help section?

Share on other sites

Great question, I’m also interested in this, haven’t sen anything like it before.

as Jca said it is probably better suited in scripting help.

Share on other sites

These flags are what the client uses to calculate pathing. Basically, getTileFlags() returns a int[104][104] that contains the local regions "collision" data. Since OSRS is tile based, its pretty simple in the fact a tile is either blocked via walls or is blocked entirely (solid objects). You can also check if you can cast a spell or shoot a projectile through a wall. Lets look at an example "flag":

Now it is an int, but to understand how it works we need the binary representation. 10000000 is the binary representation of 128, but we are looking at the "flags", aka a single bit. This flag has the 8th bit as 1, which we can compare with Region Flags. WALL_WEST is 0x80 in hex form which is 128, so this is our match. But what if multiple flags are flipped? This is where we use the bitwise AND operator:

`flags[localX][localY] & 128 == 0`

What this does is takes the first integer, and 0's out all bits that are not 1 in the second integer (and only the 8th bit is 1 for 128). So this check tests if the 8th bit is 1 (it'll return 128, not 1) or 0 (which returns 0 because all other bits are 0'd). From here we can do this for all the different flags, which you can find using the link in the previous paragraph. Once you can test if there is a wall between nodes, you can connect them. Note that there are no walls surrounding solid objects, so you also need to test if that tile is walkable.

This shows a generated "web" of tiles in game, generated from the tile flags. You'll notice there is a bunch of "web" in the open air space too, as this web is just generated by going through every tile and connecting it to its neighbors. All those tiles are not marked "UNWALKABLE" as in your example, and therefore would incorrectly return as reachable. For this use getMap().canReach(Position), which basically does a flood fill of the local region to see what you can get to from the current position.

Edited by Lemons
Share on other sites

@Lemons thanks a lot! Checking your Quantum API atm to see how it's done form A to Z and honestly, I'm getting wet just by reading your code. Awesome.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.