use of org.powerbot.bot.rt6.client.Tile in project powerbot by powerbot.
the class Game method tileToMap.
/**
* Calculates a point on the mini-map.
*
* @param locatable the {@link org.powerbot.script.Locatable} to convert to map point
* @return the map {@link Point}
*/
public Point tileToMap(final Locatable locatable) {
final Point bad = new Point(-1, -1);
final Client client = ctx.client();
final Tile b = ctx.game.mapOffset();
final Tile t = locatable.tile().derive(-b.x(), -b.y());
final int tx = t.x();
final int ty = t.y();
if (client == null || tx < 1 || tx > 103 || ty < 1 || ty > 103) {
return bad;
}
final RelativeLocation r = ctx.players.local().relative();
final float offX = (tx * 4 - r.x() / 128) + 2;
final float offY = (ty * 4 - r.z() / 128) + 2;
final int d = (int) Math.round(Math.sqrt(Math.pow(offX, 2) + Math.pow(offY, 2)));
final Component component = mapComponent();
final int w = component.scrollWidth();
final int h = component.scrollHeight();
final int radius = Math.max(w / 2, h / 2) + 10;
if (d >= radius) /*|| component.contentType() != 1338*/
{
return bad;
}
final boolean f = client.getMinimapSettings() == client.reflector.getConstant("V_MINIMAP_SCALE_ON_VALUE");
final double a = ctx.camera.rotation() * 16384d / (Math.PI * 2d);
int i = 0x3fff & (int) a;
if (!f) {
i = 0x3fff & client.getMinimapOffset() + (int) a;
}
int sin = SIN_TABLE[i], cos = COS_TABLE[i];
if (!f) {
final int scale = 256 + client.getMinimapScale();
sin = 256 * sin / scale;
cos = 256 * cos / scale;
}
int rotX = (int) (cos * offX + sin * offY) >> 14;
int rotY = (int) (cos * offY - sin * offX) >> 14;
rotX += w / 2;
rotY *= -1;
rotY += h / 2;
if (rotX > 4 && rotX < w - 4 && rotY > 4 && rotY < h - 4) {
final Point basePoint = component.screenPoint();
final int sX = rotX + (int) basePoint.getX();
final int sY = rotY + (int) basePoint.getY();
final Point p = new Point(sX, sY);
if (ctx.hud.legacy()) {
final Point mid = new Point(basePoint.x + component.width() / 2, basePoint.y + component.height() / 2);
if (Math.pow(mid.x - p.x, 2) + Math.pow(mid.y - p.y, 2) >= Math.pow(68, 2)) {
return bad;
}
} else {
// entire tile and a half sized 'buffer' area
final Rectangle rbuffer = new Rectangle(p.x - 6, p.y - 6, 12, 12);
for (final Component blocking : mapBlockingComponents()) {
if (blocking.viewportRect().intersects(rbuffer)) {
return bad;
}
}
}
return p;
}
return bad;
}
use of org.powerbot.bot.rt6.client.Tile in project powerbot by powerbot.
the class Game method tileHeight.
/**
* Determines the tile height at the provided point in the game region.
*
* @param rX the relative x
* @param rY the relative y
* @param plane the plane
* @return the height at the given point
*/
public int tileHeight(final int rX, final int rY, int plane) {
final Client c = ctx.client();
if (c == null) {
return 0;
}
if (plane == -1) {
plane = c.getFloor();
}
final int x = rX >> 9, y = rY >> 9;
final byte[][][] configs = c.getWorld().getFloorSettings().getBytes();
if (x < 0 || x > 103 || y < 0 || y > 103) {
return 0;
}
if (plane < 3 && (configs[1][x][y] & 2) != 0) {
++plane;
}
final Floor[] landscape = c.getWorld().getLandscape().getFloors();
if (plane < 0 || plane >= landscape.length) {
return 0;
}
try {
final int[][] heights = landscape[plane].getHeights();
final int aX = rX & 0x1ff;
final int aY = rY & 0x1ff;
final int start_h = heights[x][y] * (512 - aX) + heights[x + 1][y] * aX >> 9;
final int end_h = heights[x][1 + y] * (512 - aX) + heights[x + 1][y + 1] * aX >> 9;
return start_h * (512 - aY) + end_h * aY >> 9;
} catch (final Exception ignored) {
}
return 0;
}
use of org.powerbot.bot.rt6.client.Tile in project powerbot by powerbot.
the class Game method mapOffset.
/**
* Determines the base of the loaded region.
*
* @return the {@link Tile} of the base
*/
public Tile mapOffset() {
final Client client = ctx.client();
if (client == null) {
return Tile.NIL;
}
final MapOffset b = client.getWorld().getMapOffset();
if (b.isNull()) {
return Tile.NIL;
}
return new Tile(b.getX(), b.getY(), client.getFloor());
}
use of org.powerbot.bot.rt6.client.Tile in project powerbot by powerbot.
the class Movement method destination.
/**
* Determines the current destination of the player.
*
* @return the {@link Tile} destination; or {@link Tile#NIL} if there is no destination
*/
public Tile destination() {
final Client client = ctx.client();
if (client == null) {
return Tile.NIL;
}
final int dX = client.getDestinationX(), dY = client.getDestinationY();
if (dX == -1 || dY == -1) {
return Tile.NIL;
}
return ctx.game.mapOffset().derive(dX, dY);
}
use of org.powerbot.bot.rt6.client.Tile in project powerbot by powerbot.
the class GroundItems method get.
protected List<GroundItem> get(int radius) {
if (radius < 1) {
radius = 110;
}
final List<GroundItem> items = new ArrayList<GroundItem>();
final Client client = ctx.client();
if (client == null) {
return items;
}
final HashTable table = client.getItemTable();
if (table.isNull()) {
return items;
}
final int plane = client.getFloor();
long id;
NodeListCache cache;
final Tile base = ctx.game.mapOffset();
final Tile player = ctx.players.local().tile();
if (base == Tile.NIL || player == Tile.NIL || !player.matrix(ctx).valid()) {
return items;
}
final int bx = base.x(), mx = bx + 103, by = base.y(), my = by + 103;
for (int x = Math.max(bx, player.x() - radius); x <= Math.min(mx, player.x() + radius); x++) {
for (int y = Math.max(by, player.y() - radius); y <= Math.min(my, player.y() + radius); y++) {
id = x | y << 14 | plane << 28;
cache = org.powerbot.bot.rt6.HashTable.lookup(table, id, NodeListCache.class);
if (cache.isNull()) {
continue;
}
for (final ItemNode item : NodeQueue.get(cache.getDeque(), ItemNode.class)) {
items.add(new GroundItem(ctx, new Tile(x, y, plane), item));
}
}
}
return items;
}
Aggregations