Jump to content

Mapping walkable tiles


Recommended Posts

Posted (edited)

You can get a 2d array of tile flags by

 

XClippingPlane[] planes = getMap().getRegion().getClippingPlanes();

each plane has a getTileFlags() getter for the int[][] array of flags (index by local coordinates).

 

I'm not sure what the flag values are, but it should be fairly simple to debug

Edited by FrostBug
  • Like 1
Posted

You can get a 2d array of tile flags by

 

XClippingPlane[] planes = getMap().getRegion().getClippingPlanes();

each plane has a getTileFlags() getter for the int[][] array of flags (index by local coordinates).

 

I'm not sure what the flag values are, but it should be fairly simple to debug

 

 

You can do this but it wont be totally accurate.

Some tiles will say they are not walkable when they actually are, because some of the flags are shared on walkable tiles and non walkable tiles.

(If I remember correctly)

 

It will almost work, but you will end up missing some tiles ultimately.

  • Like 1
Posted

You can get a 2d array of tile flags by

 

XClippingPlane[] planes = getMap().getRegion().getClippingPlanes();

each plane has a getTileFlags() getter for the int[][] array of flags (index by local coordinates).

 

I'm not sure what the flag values are, but it should be fairly simple to debug

For now I just need walkable tiles on plane 0 (surface). 

 

So planes will contain both x and y value?

 

If I was to use getRegion().getTiles(), would it return non walkable tiles aswell?

You can do this but it wont be totally accurate.

Some tiles will say they are not walkable when they actually are, because some of the flags are shared on walkable tiles and non walkable tiles.

(If I remember correctly)

 

It will almost work, but you will end up missing some tiles ultimately.

Well, as for trying this for the first time, missing some tiles will not be a big issue.

Posted

For now I just need walkable tiles on plane 0 (surface). 

 

So planes will contain both x and y value?

 

If I was to use getRegion().getTiles(), would it return non walkable tiles aswell?

Well, as for trying this for the first time, missing some tiles will not be a big issue.

 

It will be if you are making a web.

Consider a tile that contains a door. When that door is closed, the tile is not walkable. That means that using clipping flags, you will see that tile as non walkable.

 

You could argue that you can check objects on the tile, see if they are something that can be overcome, and yes you could do that.

 

But objects such as doors, gates, etc. are not the only things that behave in that way.

Flags are a bit wonky. I suggest just using clipping flags to paint the different tiles values/type and you can see for yourself how clipping behaves.

Posted

It will be if you are making a web.

Consider a tile that contains a door. When that door is closed, the tile is not walkable. That means that using clipping flags, you will see that tile as non walkable.

 

You could argue that you can check objects on the tile, see if they are something that can be overcome, and yes you could do that.

 

But objects such as doors, gates, etc. are not the only things that behave in that way.

Flags are a bit wonky. I suggest just using clipping flags to paint the different tiles values/type and you can see for yourself how clipping behaves.

I see your point.

 

As for the painting, how do you paint nodes and print the world map, like this:

5d1a3da966218ed42f52d834e2fe9b8a.png

Posted (edited)

Here:

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();

Now just loop through all tiles and check them smile.png

 

Khaleesi


You can do this but it wont be totally accurate.

Some tiles will say they are not walkable when they actually are, because some of the flags are shared on walkable tiles and non walkable tiles.

(If I remember correctly)

 

It will almost work, but you will end up missing some tiles ultimately.

 

Not true, if you use the right values the shared flags won't matter.

 

A tile where a door is on is always walkable. but you'll have to check other flags if you can pass from 1 tile to another.

Example fence:

you can stand on both tiles, 1 tile will hold info if the tile is blocked north,east,south,west. :)

 

Khaleesi

 

Edited by Khaleesi
Posted

I see your point.

 

As for the painting, how do you paint nodes and print the world map, like this:

5d1a3da966218ed42f52d834e2fe9b8a.png

 

 

Havent worked on mine in a long time but this is what mine looks like: 

 

9539550156765c8828c0d2e33b8ebd64.png

 

 

That is just using java gui basics.

You just need an image of the map and your web data to draw on top of the map. I used a scroll pane to fit the map in a smaller gui.

 

Dont worry about drawing it yet, i would suggest that you learn one thing at a time. Once you understand it and think you have it how you want it, then move on to the next task.

 

Drawing the map wasnt a priority for me, I didnt do it for a long time. :p

Here:

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();

Now just loop through all tiles and check them smile.png

 

Khaleesi

 

Not true, if you use the right values the shared flags won't matter.

Check above wink.png, this will be 100% accurate smile.png

 

I am not sure, like I said it has been a long time since I really messed with it. I made that thing over a year ago.

 

Once the client comes back up I will see if I can find my old project that painted the flags. 

  • Like 1
Posted

Here:

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();

Now just loop through all tiles and check them smile.png

 

Khaleesi

I might be dumb, but what do you mean with "just loop through all tiles and check them"  

Posted (edited)

I might be dumb, but what do you mean with "just loop through all tiles and check them"  

 

Here:

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?
   }
}

Could be typos in it, typed quickly in here.

That's what you wanted to do right?

 

Khaleesi

Edited by Khaleesi
Posted

Here:

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?
   }
}

Could be typos in it, typed quickly in here.

That's what you wanted to do right?

 

Khaleesi

 

 

Oh now I remember the main reason that I didnt just use clipping flags.

 

A tile can be walkable but not reachable. I cant remember what I did exactly but I think I made a web cleaner that went through and checked for isolated sections in my web that were generated, but cant actually be reached from other parts of the web and it would delete them.

  • Like 1
Posted

Here:

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?
   }
}

Could be typos in it, typed quickly in here.

That's what you wanted to do right?

 

Khaleesi

Oh yea.. Now I get it. Thank you!

  • Like 1
Posted (edited)

Here:

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?
   }
}

Could be typos in it, typed quickly in here.

That's what you wanted to do right?

 

Khaleesi

This is what I have

ArrayList<Integer> walkableTiles = new ArrayList<Integer>();

@Override
	public int onLoop() throws InterruptedException {

		XClippingPlane[] planes = map.getRegion().getClippingPlanes();
		int[][] map = planes[myPlayer().getZ()].getTileFlags();

		for(int x = 0; x < map.length; x++) {
			for(int y = 0; y < map[x].length; y++) {
				if(isWalkable(map[x][y])) {
					walkableTiles.add(map[x][y]);
				}
			}
		}
		return 5000;
	}

public void onExit() {
		try {
			BufferedWriter writer = new BufferedWriter ( new FileWriter(".\\positions.txt"));

			for(int i = 0; i < walkableTiles.size(); i++) {
				writer.write(""+walkableTiles.get(i));
				writer.newLine();
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

When I look at the text file, there are mostly zeros and some other values that doesn't look like tile positions...

3c25ae0384b21f3a1ca14b53e9cbb967.png

 

I've tested some other methods and experimented with it, but I get the same all the time. What's wrong?

Edited by Woody
Posted (edited)

This is what I have

ArrayList<Integer> walkableTiles = new ArrayList<Integer>();

@Override
	public int onLoop() throws InterruptedException {

		XClippingPlane[] planes = map.getRegion().getClippingPlanes();
		int[][] map = planes[myPlayer().getZ()].getTileFlags();

		for(int x = 0; x < map.length; x++) {
			for(int y = 0; y < map[x].length; y++) {
				if(isWalkable(map[x][y])) {
					walkableTiles.add(map[x][y]);
				}
			}
		}
		return 5000;
	}

public void onExit() {
		try {
			BufferedWriter writer = new BufferedWriter ( new FileWriter(".\\positions.txt"));

			for(int i = 0; i < walkableTiles.size(); i++) {
				writer.write(""+walkableTiles.get(i));
				writer.newLine();
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

When I look at the text file, there are mostly zeros and some other values that doesn't look like tile positions...

 

 

I've tested some other methods and experimented with it, but I get the same all the time. What's wrong?

 

You are saving the flags of the tiles.

Not even the tile itself...

 

This adds a flag of a tile to the list.

walkableTiles.add(map[x][y])

basicly pointless, since you don't even know which tile it is afterwards.

 

You want to save the tiles itself.

ArrayList<Position> walkableTiles = new ArrayList<Position>();

Try to figure out how to get the global x and y yourself out of the locals x and y wink.png

 

Khaleesi

Edited by Khaleesi
Posted

You are saving the flags of the tiles.

Not even the tile itself...

 

This adds a flag of a tile to the list.

walkableTiles.add(map[x][y])

basicly pointless, since you don't even know which tile it is afterwards.

 

You want to save the tiles itself.

ArrayList<Position> walkableTiles = new ArrayList<Position>();

Try to figure out how to get the global x and y yourself out of the locals x and y wink.png

 

Khaleesi

Lol, shame on me... 

 

So with map[x][y] I can find the flag's tile? 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...