Search in sources :

Example 1 with Tile

use of org.powerbot.bot.rt4.client.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)

Example 2 with Tile

use of org.powerbot.bot.rt4.client.Tile in project powerbot by powerbot.

the class Game method tileHeight.

/**
 * Returns the tile height of the relative 2-dimensional tile. The
 * 3-dimensional axis is flipped to represent the X axis being horizontal,
 * Y axis being Vertical, and Z axis to be depth.
 *
 * @param relativeX The x-axis value relative to the origin
 * @param relativeZ The z-axis value relative to the origin
 * @return The tile height
 */
public int tileHeight(final int relativeX, final int relativeZ) {
    final Client client = ctx.client();
    if (client == null) {
        return 0;
    }
    int floor = client.getFloor();
    int x = relativeX >> 7;
    int y = relativeZ >> 7;
    if (x < 0 || y < 0 || x > 103 || y > 103 || floor < 0 || floor > 3) {
        return 0;
    }
    final byte[][][] meta = client.getLandscapeMeta();
    final int[][][] heights = client.getTileHeights();
    if (meta == null) {
        return 0;
    }
    if (floor < 3 && (meta[1][x][y] & 0x2) == 2) {
        floor++;
    }
    x &= 0x7f;
    y &= 0x7f;
    final int heightStart = x * heights[floor][1 + x][y] + heights[floor][x][y] * (128 - x) >> 7;
    final int heightEnd = (128 - x) * heights[floor][x][1 + y] + x * heights[floor][1 + x][y + 1] >> 7;
    return y * heightEnd + heightStart * (128 - y) >> 7;
}
Also used : Client(org.powerbot.bot.rt4.client.Client)

Example 3 with Tile

use of org.powerbot.bot.rt4.client.Tile in project powerbot by powerbot.

the class Game method tileToMap.

/**
 * Converts the 3-dimensional tile to a 2-dimensional point on the mini-map component.
 *
 * @param tile The tile to convert
 * @return The point on screen of where the tile would be.
 */
public Point tileToMap(final Tile tile) {
    final Client client = ctx.client();
    if (client == null) {
        return new Point(-1, -1);
    }
    final int rel = ctx.players.local().relative();
    final int angle = client.getMinimapAngle() & 0x7ff;
    final int[] d = { tile.x(), tile.y(), ARRAY_SIN[angle], ARRAY_COS[angle], -1, -1 };
    d[0] = (d[0] - client.getOffsetX()) * 4 + 2 - (rel >> 16) / 32;
    d[1] = (d[1] - client.getOffsetY()) * 4 + 2 - (rel & 0xffff) / 32;
    d[4] = d[1] * d[2] + d[3] * d[0] >> 16;
    d[5] = d[2] * d[0] - d[1] * d[3] >> 16;
    final Point centre = mapComponent().centerPoint();
    return new Point(centre.x + d[4], centre.y + d[5]);
}
Also used : Client(org.powerbot.bot.rt4.client.Client)

Example 4 with Tile

use of org.powerbot.bot.rt4.client.Tile in project powerbot by powerbot.

the class Objects method get.

protected List<GameObject> get(final Locatable l, int radius) {
    radius = Math.min(radius, 110);
    final List<GameObject> items = new ArrayList<GameObject>();
    final Client client = ctx.client();
    if (client == null) {
        return items;
    }
    final Tile[][][] grounds = client.getWorld().getLandscape().getTiles();
    final int floor = ctx.game.floor();
    if (floor < 0 || floor >= grounds.length) {
        return items;
    }
    final Set<GameObject> set = new HashSet<GameObject>();
    final Tile[][] rows = grounds[floor];
    int start_x = 0, end_x = Integer.MAX_VALUE, start_y = 0, end_y = Integer.MAX_VALUE;
    if (radius >= 0) {
        final org.powerbot.script.Tile mo = ctx.game.mapOffset(), lp = l.tile();
        if (mo != org.powerbot.script.Tile.NIL && lp != org.powerbot.script.Tile.NIL) {
            final org.powerbot.script.Tile t = lp.derive(-mo.x(), -mo.y());
            start_x = t.x() - radius;
            end_x = t.x() + radius;
            start_y = t.y() - radius;
            end_y = t.y() + radius;
        }
    }
    for (int x = Math.max(0, start_x); x <= Math.min(end_x, rows.length - 1); x++) {
        final Tile[] col = rows[x];
        for (int y = Math.max(0, start_y); y <= Math.min(end_y, col.length - 1); y++) {
            final Tile tile = col[y];
            if (tile.isNull()) {
                continue;
            }
            for (RenderableNode node = tile.getInteractives(); !node.isNull(); node = node.getNext()) {
                final RenderableEntity r = node.getEntity();
                if (r.isNull()) {
                    continue;
                }
                if (r.isTypeOf(org.powerbot.bot.rt6.client.GameObject.class)) {
                    final org.powerbot.bot.rt6.client.GameObject o = new org.powerbot.bot.rt6.client.GameObject(r.reflector, r);
                    if (o.getId() != -1) {
                        set.add(new GameObject(ctx, new BasicObject(o, floor), GameObject.Type.INTERACTIVE));
                    }
                } else if (r.isTypeOf(DynamicGameObject.class)) {
                    final DynamicGameObject o = new DynamicGameObject(r.reflector, r);
                    if (o.getBridge().getId() != -1) {
                        set.add(new GameObject(ctx, new BasicObject(o, floor), GameObject.Type.INTERACTIVE));
                    }
                }
            }
            final Object[] objs = { tile.getBoundary1(), tile.getBoundary2(), tile.getFloorDecoration(), tile.getWallDecoration1(), tile.getWallDecoration2() };
            for (int i = 0; i < objs.length; i++) {
                if (objs[i] == null) {
                    continue;
                }
                Class<?> type = null;
                for (final Class<?> e : o_types[i]) {
                    @SuppressWarnings("unchecked") final Class<? extends ReflectProxy> c = (Class<? extends ReflectProxy>) e;
                    if (c != null && tile.reflector.isTypeOf(objs[i], c)) {
                        type = c;
                        break;
                    }
                }
                if (type == null) {
                    continue;
                }
                try {
                    items.add(new GameObject(ctx, new BasicObject((RenderableEntity) type.getConstructor(Reflector.class, Object.class).newInstance(tile.reflector, objs[i]), floor), types[i]));
                } catch (final InstantiationException ignored) {
                } catch (final IllegalAccessException ignored) {
                } catch (final InvocationTargetException ignored) {
                } catch (final NoSuchMethodException ignored) {
                }
            }
        }
    }
    items.addAll(set);
    set.clear();
    return items;
}
Also used : RenderableEntity(org.powerbot.bot.rt6.client.RenderableEntity) Reflector(org.powerbot.bot.Reflector) ArrayList(java.util.ArrayList) DynamicGameObject(org.powerbot.bot.rt6.client.DynamicGameObject) Client(org.powerbot.bot.rt6.client.Client) HashSet(java.util.HashSet) ReflectProxy(org.powerbot.bot.ReflectProxy) Tile(org.powerbot.bot.rt6.client.Tile) InvocationTargetException(java.lang.reflect.InvocationTargetException) DynamicGameObject(org.powerbot.bot.rt6.client.DynamicGameObject) DynamicGameObject(org.powerbot.bot.rt6.client.DynamicGameObject) DynamicBoundaryObject(org.powerbot.bot.rt6.client.DynamicBoundaryObject) BoundaryObject(org.powerbot.bot.rt6.client.BoundaryObject) FloorObject(org.powerbot.bot.rt6.client.FloorObject) DynamicFloorObject(org.powerbot.bot.rt6.client.DynamicFloorObject) DynamicWallObject(org.powerbot.bot.rt6.client.DynamicWallObject) WallObject(org.powerbot.bot.rt6.client.WallObject) RenderableNode(org.powerbot.bot.rt6.client.RenderableNode)

Example 5 with Tile

use of org.powerbot.bot.rt4.client.Tile in project powerbot by powerbot.

the class LocalPath method getCosts.

static double[][] getCosts(final ClientContext ctx, final int w, final int h) {
    final Client client = ctx.client();
    final Landscape landscape = client.getLandscape();
    final org.powerbot.bot.rt4.client.Tile[][][] tiles;
    final int floor = client.getFloor();
    final org.powerbot.bot.rt4.client.Tile[][] rows;
    if (landscape == null || (tiles = landscape.getTiles()) == null || floor < 0 || floor > tiles.length || (rows = tiles[floor]) == null) {
        return new double[0][0];
    }
    final double[][] arr = new double[w][h];
    for (int x = 0; x < Math.min(w, rows.length); x++) {
        final org.powerbot.bot.rt4.client.Tile[] row = rows[x];
        if (row == null) {
            continue;
        }
        final int h2 = row.length;
        for (int y = 0; y < Math.min(h, h2); y++) {
            final org.powerbot.bot.rt4.client.Tile tile = row[y];
            if (tile == null) {
                continue;
            }
            if (tile.getGameObjectLength() > 0 || tile.getBoundaryObject() != null || tile.getWallObject() != null) {
                for (int dx = Math.max(0, x - 1); dx <= Math.min(w - 1, x + 1); dx++) {
                    for (int dy = Math.max(0, y - 1); dy <= Math.min(h - 1, y + 1); dy++) {
                        arr[dx][dy] += Random.nextDouble();
                    }
                }
            }
        }
    }
    return arr;
}
Also used : Landscape(org.powerbot.bot.rt4.client.Landscape) Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt4.client.Client)

Aggregations

Client (org.powerbot.bot.rt4.client.Client)9 Tile (org.powerbot.script.Tile)5 Point (java.awt.Point)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ReflectProxy (org.powerbot.bot.ReflectProxy)2 NodeDeque (org.powerbot.bot.rt4.client.NodeDeque)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedList (java.util.LinkedList)1 Reflector (org.powerbot.bot.Reflector)1 ItemNode (org.powerbot.bot.rt4.client.ItemNode)1 Landscape (org.powerbot.bot.rt4.client.Landscape)1 Tile (org.powerbot.bot.rt4.client.Tile)1 BoundaryObject (org.powerbot.bot.rt6.client.BoundaryObject)1 Client (org.powerbot.bot.rt6.client.Client)1 DynamicBoundaryObject (org.powerbot.bot.rt6.client.DynamicBoundaryObject)1 DynamicFloorObject (org.powerbot.bot.rt6.client.DynamicFloorObject)1 DynamicGameObject (org.powerbot.bot.rt6.client.DynamicGameObject)1 DynamicWallObject (org.powerbot.bot.rt6.client.DynamicWallObject)1