use of org.powerbot.script.Tile in project powerbot by powerbot.
the class TMapBase method draw.
public int draw(int idx, final Graphics render) {
final Tile t = ctx.game.mapOffset();
drawLine(render, idx++, "Map base: " + (t != null ? t.toString() : ""));
return idx;
}
use of org.powerbot.script.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.script.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.script.Tile in project powerbot by powerbot.
the class LocalPath method valid.
@Override
public boolean valid() {
Tile end = destination.tile();
if (end == null || end == Tile.NIL) {
return false;
}
if (end.equals(tile) && tilePath != null) {
return true;
}
tile = end;
Tile start = ctx.players.local().tile();
final Tile base = ctx.game.mapOffset();
if (base == Tile.NIL || start == Tile.NIL || end == Tile.NIL || start.floor() != end.floor()) {
return false;
}
start = start.derive(-base.x(), -base.y());
end = end.derive(-base.x(), -base.y());
final Map.Node[] path = map.getPath(start.x(), start.y(), end.x(), end.y(), ctx.game.floor());
if (path.length > 0) {
final Tile[] arr = new Tile[path.length];
for (int i = 0; i < path.length; i++) {
arr[i] = base.derive(path[i].x, path[i].y);
}
tilePath = ctx.movement.newTilePath(arr);
return true;
}
return false;
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class Movement method reachable.
/**
* Determines if the the end position is reachable from the start position.
*
* @param _start the start position
* @param _end the end position
* @return {@code true} if the end is reachable; otherwise {@code false}
*/
public boolean reachable(final Locatable _start, final Locatable _end) {
Tile start, end;
if (_start == null || _end == null) {
return false;
}
start = _start.tile();
end = _end.tile();
if (start.floor() != end.floor()) {
return false;
}
final Tile base = ctx.game.mapOffset();
if (base == Tile.NIL || start == Tile.NIL || end == Tile.NIL) {
return false;
}
start = start.derive(-base.x(), -base.y());
end = end.derive(-base.x(), -base.y());
final int startX = start.x();
final int startY = start.y();
final int endX = end.x();
final int endY = end.y();
return ctx.map.getPath(startX, startY, endX, endY, ctx.game.floor()).length > 0;
}
Aggregations