Search in sources :

Example 6 with Tile

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;
}
Also used : Tile(org.powerbot.script.Tile)

Example 7 with Tile

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;
}
Also used : Rectangle(java.awt.Rectangle) Tile(org.powerbot.script.Tile) Point(java.awt.Point) Client(org.powerbot.bot.rt6.client.Client) Point(java.awt.Point)

Example 8 with Tile

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());
}
Also used : MapOffset(org.powerbot.bot.rt6.client.MapOffset) Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt6.client.Client)

Example 9 with Tile

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;
}
Also used : Tile(org.powerbot.script.Tile)

Example 10 with Tile

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;
}
Also used : Tile(org.powerbot.script.Tile) Point(java.awt.Point)

Aggregations

Tile (org.powerbot.script.Tile)40 Point (java.awt.Point)16 ArrayList (java.util.ArrayList)5 Client (org.powerbot.bot.rt4.client.Client)5 FontMetrics (java.awt.FontMetrics)4 Condition (org.powerbot.script.Condition)4 Rectangle (java.awt.Rectangle)3 Client (org.powerbot.bot.rt6.client.Client)3 Player (org.powerbot.script.rt4.Player)3 Player (org.powerbot.script.rt6.Player)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NodeDeque (org.powerbot.bot.rt4.client.NodeDeque)2 Filter (org.powerbot.script.Filter)2 Locatable (org.powerbot.script.Locatable)2 Targetable (org.powerbot.script.Targetable)2 TileMatrix (org.powerbot.script.rt6.TileMatrix)2 LinkedList (java.util.LinkedList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ItemNode (org.powerbot.bot.rt4.client.ItemNode)1