Search in sources :

Example 1 with Location

use of net.runelite.cache.region.Location in project runelite by runelite.

the class MapImageDumper method drawObjects.

private void drawObjects(BufferedImage image, int drawBaseX, int drawBaseY, Region region, int z) {
    Graphics2D graphics = image.createGraphics();
    for (Location location : region.getLocations()) {
        int rotation = location.getOrientation();
        int type = location.getType();
        int localX = location.getPosition().getX() - region.getBaseX();
        int localY = location.getPosition().getY() - region.getBaseY();
        boolean isBridge = (region.getTileSetting(1, localX, localY) & 2) != 0;
        if (location.getPosition().getZ() == z + 1) {
            if (!isBridge) {
                continue;
            }
        } else if (location.getPosition().getZ() == z) {
            if (isBridge) {
                continue;
            }
            if ((region.getTileSetting(z, localX, localY) & 24) != 0) {
                continue;
            }
        } else {
            continue;
        }
        ObjectDefinition object = findObject(location.getId());
        int drawX = (drawBaseX + localX) * MAP_SCALE;
        int drawY = (drawBaseY + (Region.Y - 1 - localY)) * MAP_SCALE;
        if (type >= 0 && type <= 3) {
            // this is a wall
            int hash = (localY << 7) + localX + (location.getId() << 14) + 0x4000_0000;
            if (object.getAnInt2088() == 0) {
                hash -= Integer.MIN_VALUE;
            }
            int rgb = wallColor;
            if (hash > 0) {
                rgb = doorColor;
            }
            if (object.getMapSceneID() != -1) {
                Image spriteImage = scaledMapIcons.get(object.getMapSceneID());
                graphics.drawImage(spriteImage, drawX * MAP_SCALE, drawY * MAP_SCALE, null);
            } else {
                if (type == 0 || type == 2) {
                    if (rotation == 0) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 0, drawY + 1, rgb);
                        image.setRGB(drawX + 0, drawY + 2, rgb);
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                    } else if (rotation == 1) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 1, drawY + 0, rgb);
                        image.setRGB(drawX + 2, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                    } else if (rotation == 2) {
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 1, rgb);
                        image.setRGB(drawX + 3, drawY + 2, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    } else if (rotation == 3) {
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                        image.setRGB(drawX + 1, drawY + 3, rgb);
                        image.setRGB(drawX + 2, drawY + 3, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    }
                }
                if (type == 3) {
                    if (rotation == 0) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                    } else if (rotation == 1) {
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                    } else if (rotation == 2) {
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    } else if (rotation == 3) {
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                    }
                }
                if (type == 2) {
                    if (rotation == 3) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 0, drawY + 1, rgb);
                        image.setRGB(drawX + 0, drawY + 2, rgb);
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                    } else if (rotation == 0) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 1, drawY + 0, rgb);
                        image.setRGB(drawX + 2, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                    } else if (rotation == 1) {
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 1, rgb);
                        image.setRGB(drawX + 3, drawY + 2, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    } else if (rotation == 2) {
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                        image.setRGB(drawX + 1, drawY + 3, rgb);
                        image.setRGB(drawX + 2, drawY + 3, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    }
                }
            }
        } else if (type == 9) {
            if (object.getMapSceneID() != -1) {
                Image spriteImage = scaledMapIcons.get(object.getMapSceneID());
                graphics.drawImage(spriteImage, drawX, drawY, null);
                continue;
            }
            int hash = (localY << 7) + localX + (location.getId() << 14) + 0x4000_0000;
            if (object.getAnInt2088() == 0) {
                hash -= Integer.MIN_VALUE;
            }
            if ((hash >> 29 & 3) != 2) {
                continue;
            }
            int rgb = 0xEE_EEEE;
            if (hash > 0) {
                rgb = 0xEE_0000;
            }
            if (rotation != 0 && rotation != 2) {
                image.setRGB(drawX + 0, drawY + 0, rgb);
                image.setRGB(drawX + 1, drawY + 1, rgb);
                image.setRGB(drawX + 2, drawY + 2, rgb);
                image.setRGB(drawX + 3, drawY + 3, rgb);
            } else {
                image.setRGB(drawX + 0, drawY + 3, rgb);
                image.setRGB(drawX + 1, drawY + 2, rgb);
                image.setRGB(drawX + 2, drawY + 1, rgb);
                image.setRGB(drawX + 3, drawY + 0, rgb);
            }
        } else if (type == 22 || (type >= 9 && type <= 11)) {
            // ground object
            if (object.getMapSceneID() != -1) {
                Image spriteImage = scaledMapIcons.get(object.getMapSceneID());
                graphics.drawImage(spriteImage, drawX, drawY, null);
            }
        }
    }
    graphics.dispose();
}
Also used : ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Location(net.runelite.cache.region.Location)

Example 2 with Location

use of net.runelite.cache.region.Location in project runelite by runelite.

the class LocationsLoader method loadLocations.

private void loadLocations(LocationsDefinition loc, byte[] b) {
    InputStream buf = new InputStream(b);
    int id = -1;
    int idOffset;
    while ((idOffset = buf.readUnsignedShortSmart()) != 0) {
        id += idOffset;
        int position = 0;
        int positionOffset;
        while ((positionOffset = buf.readUnsignedShortSmart()) != 0) {
            position += positionOffset - 1;
            int localY = position & 0x3F;
            int localX = position >> 6 & 0x3F;
            int height = position >> 12 & 0x3;
            int attributes = buf.readUnsignedByte();
            int type = attributes >> 2;
            int orientation = attributes & 0x3;
            loc.getLocations().add(new Location(id, type, orientation, new Position(localX, localY, height)));
        }
    }
}
Also used : Position(net.runelite.cache.region.Position) InputStream(net.runelite.cache.io.InputStream) Location(net.runelite.cache.region.Location)

Example 3 with Location

use of net.runelite.cache.region.Location in project runelite by runelite.

the class LocationSaver method save.

public byte[] save(LocationsDefinition locs) {
    Multimap<Integer, Location> locById = LinkedListMultimap.create();
    List<Location> sortedLocs = new ArrayList<>(locs.getLocations());
    sortedLocs.sort((l1, l2) -> Integer.compare(l1.getId(), l2.getId()));
    for (Location loc : sortedLocs) {
        locById.put(loc.getId(), loc);
    }
    OutputStream out = new OutputStream();
    int prevId = -1;
    for (Integer id : locById.keySet()) {
        int diffId = id - prevId;
        prevId = id;
        out.writeShortSmart(diffId);
        Collection<Location> locations = locById.get(id);
        int position = 0;
        for (Location loc : locations) {
            int packedPosition = (loc.getPosition().getZ() << 12) | (loc.getPosition().getX() << 6) | (loc.getPosition().getY());
            int diffPos = packedPosition - position;
            position = packedPosition;
            out.writeShortSmart(diffPos + 1);
            int packedAttributes = (loc.getType() << 2) | loc.getOrientation();
            out.writeByte(packedAttributes);
        }
        out.writeShortSmart(0);
    }
    out.writeShortSmart(0);
    return out.flip();
}
Also used : OutputStream(net.runelite.cache.io.OutputStream) ArrayList(java.util.ArrayList) Location(net.runelite.cache.region.Location)

Example 4 with Location

use of net.runelite.cache.region.Location in project runelite by runelite.

the class ModelViewer method drawLocations.

private static void drawLocations(Region region) {
    for (Location location : region.getLocations()) {
        int id = location.getId();
        ObjectDefinition object = getObject(id);
        if (object == null || object.getObjectModels() == null) {
            continue;
        }
        Position objectPos = location.getPosition();
        if (location.getPosition().getZ() != 0) {
            continue;
        }
        int regionX = objectPos.getX() - region.getBaseX();
        int regionY = objectPos.getY() - region.getBaseY();
        int height = -region.getTileHeight(objectPos.getZ(), regionX, regionY) / HEIGHT_MOD;
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        // TILE_SCALE/2 to draw the object from the center of the tile it is on
        GL11.glTranslatef(regionX * TILE_SCALE + (TILE_SCALE / 2), height, -regionY * TILE_SCALE - (TILE_SCALE / 2));
        for (int i = 0; i < object.getObjectModels().length; ++i) {
            ModelDefinition md = ModelManager.getModel(object.getObjectModels()[i], object, location);
            if (object.getObjectTypes() != null && object.getObjectTypes()[i] != location.getType()) {
                continue;
            }
            drawModel(md, object.getRecolorToFind(), object.getRecolorToReplace());
        }
        GL11.glTranslatef(-regionX * TILE_SCALE - (TILE_SCALE / 2), -height, regionY * TILE_SCALE + (TILE_SCALE / 2));
        GL11.glPopMatrix();
    }
}
Also used : Position(net.runelite.cache.region.Position) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) Location(net.runelite.cache.region.Location)

Example 5 with Location

use of net.runelite.cache.region.Location in project runelite by runelite.

the class MapImageDumper method drawMapIcons.

private void drawMapIcons(Graphics2D graphics, Region region, int z, int drawBaseX, int drawBaseY) {
    for (Location location : region.getLocations()) {
        int localZ = location.getPosition().getZ();
        if (z != 0 && localZ != z) {
            // draw all icons on z=0
            continue;
        }
        ObjectDefinition od = findObject(location.getId());
        assert od != null;
        int localX = location.getPosition().getX() - region.getBaseX();
        int localY = location.getPosition().getY() - region.getBaseY();
        int drawX = drawBaseX + localX;
        int drawY = drawBaseY + (Region.Y - 1 - localY);
        if (od.getMapAreaId() != -1) {
            AreaDefinition area = areas.getArea(od.getMapAreaId());
            assert area != null;
            int spriteId = area.spriteId;
            SpriteDefinition sprite = sprites.findSprite(spriteId, 0);
            assert sprite != null;
            BufferedImage iconImage = sprites.getSpriteImage(sprite);
            graphics.drawImage(iconImage, drawX * MAP_SCALE, drawY * MAP_SCALE, null);
        }
    }
}
Also used : AreaDefinition(net.runelite.cache.definitions.AreaDefinition) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) BufferedImage(java.awt.image.BufferedImage) Location(net.runelite.cache.region.Location)

Aggregations

Location (net.runelite.cache.region.Location)5 ObjectDefinition (net.runelite.cache.definitions.ObjectDefinition)3 BufferedImage (java.awt.image.BufferedImage)2 Position (net.runelite.cache.region.Position)2 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 ArrayList (java.util.ArrayList)1 AreaDefinition (net.runelite.cache.definitions.AreaDefinition)1 ModelDefinition (net.runelite.cache.definitions.ModelDefinition)1 SpriteDefinition (net.runelite.cache.definitions.SpriteDefinition)1 InputStream (net.runelite.cache.io.InputStream)1 OutputStream (net.runelite.cache.io.OutputStream)1