Search in sources :

Example 11 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class Movement method distance.

/**
 * Gets the distance between two places in the loaded game region.
 *
 * @param _start the start position
 * @param _end   the end position
 * @return the computed path distance
 */
public int distance(final Locatable _start, final Locatable _end) {
    Tile start, end;
    if (_start == null || _end == null) {
        return -1;
    }
    start = _start.tile();
    end = _end.tile();
    if (start.floor() != end.floor()) {
        return -1;
    }
    final Tile base = ctx.game.mapOffset();
    if (base == Tile.NIL || start == Tile.NIL || end == Tile.NIL) {
        return -1;
    }
    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.getDistance(startX, startY, endX, endY, ctx.game.floor());
}
Also used : Tile(org.powerbot.script.Tile) Point(java.awt.Point)

Example 12 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class TileMatrix method valid.

@Override
public boolean valid() {
    final Tile t = ctx.game.mapOffset();
    if (t == null || tile == Tile.NIL) {
        return false;
    }
    final int x = tile.x() - t.x(), y = tile.y() - t.y();
    return x >= 0 && y >= 0 && x < 104 && y < 104;
}
Also used : Tile(org.powerbot.script.Tile) Point(java.awt.Point)

Example 13 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class TilePath method next.

@Override
public Tile next() {
    /* Wait for map not to be loading */
    final int state = ctx.game.clientState();
    if (state == Constants.GAME_MAP_LOADING) {
        Condition.wait(new Condition.Check() {

            @Override
            public boolean poll() {
                return ctx.game.clientState() != Constants.GAME_MAP_LOADING;
            }
        });
        return next();
    }
    if (state != Constants.GAME_MAP_LOADED) {
        return null;
    }
    /* Get current destination */
    final Tile dest = ctx.movement.destination();
    /* Label main loop for continuing purposes */
    out: /* Iterate over all tiles but the first tile (0) starting with the last (length - 1). */
    for (int i = tiles.length - 1; i > 0; --i) {
        /* The tiles not in view, go to the next. */
        if (!tiles[i].matrix(ctx).valid() || !tiles[i].matrix(ctx).onMap()) {
            continue;
        }
        /* LARGELY SPACED PATH SUPPORT: If the current destination is the tile on the map, return that tile
			 * as the next one will be coming soon (we hope/assume this, as short spaced paths should never experience
			 * this condition as one will be on map before it reaches the current target). */
        if (dest == Tile.NIL) {
            if (tiles[i].matrix(ctx).reachable()) {
                return tiles[i];
            }
            continue;
        } else if (tiles[i].distanceTo(dest) < 3d) {
            return tiles[i];
        }
        /* Tile is on map and isn't currently "targeted" (dest), let's check it out.
			 * Iterate over all tiles succeeding it. */
        for (int a = i - 1; a >= 0; --a) {
            /* The tile before the tile on map isn't on map.  Break out to the next tile.
				 * Explanation: Path wraps around something and must be followed.
				 * We cannot suddenly click out of a "pathable" region (104x104).
				 * In these cases, we can assume a better tile will become available. */
            if (!tiles[a].matrix(ctx).valid() || !tiles[a].matrix(ctx).onMap()) {
                continue out;
            }
            /* If a tile (successor) is currently targeted, return the tile that was the "best"
				 * on the map for getNext as we can safely assume we're following our path. */
            if (tiles[a].distanceTo(dest) < 3d) {
                return tiles[i];
            }
        }
    }
    /* Well, we've made it this far.  Return the first tile if nothing else is on our map.
		* CLICKING BACK AND FORTH PREVENTION: check for dest not to be null if we're just starting
		 * our path.  If our destination isn't null and we somehow got to our first tile then
		 * we can safely assume lag is being experienced and return null until next call of getNext.
		 * TELEPORTATION SUPPORT: If destination is set but but we're not moving, assume
		 * invalid destination tile from teleportation reset and return first tile. */
    final Player p = ctx.players.local();
    if (p != null && !p.inMotion() && dest != Tile.NIL) {
        for (int i = tiles.length - 1; i >= 0; --i) {
            if (tiles[i].matrix(ctx).onMap()) {
                return tiles[i];
            }
        }
    }
    if (tiles.length == 0 || !tiles[0].matrix(ctx).onMap()) {
        return null;
    }
    return tiles[0];
}
Also used : Condition(org.powerbot.script.Condition) Tile(org.powerbot.script.Tile)

Example 14 with Tile

use of org.powerbot.script.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;
}
Also used : ItemNode(org.powerbot.bot.rt6.client.ItemNode) HashTable(org.powerbot.bot.rt6.client.HashTable) ArrayList(java.util.ArrayList) NodeListCache(org.powerbot.bot.rt6.client.NodeListCache) Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt6.client.Client)

Example 15 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class Actor method tile.

@Override
public Tile tile() {
    final Client client = ctx.client();
    final org.powerbot.bot.rt4.client.Actor actor = getActor();
    if (client != null && actor != null) {
        return new Tile(client.getOffsetX() + (actor.getX() >> 7), client.getOffsetY() + (actor.getZ() >> 7), client.getFloor());
    }
    return Tile.NIL;
}
Also used : Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt4.client.Client)

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