Search in sources :

Example 1 with ConnectionRoom

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom in project shattered-pixel-dungeon-gdx by 00-Evan.

the class RegularBuilder method createBranches.

// places the rooms in roomsToBranch into branches from rooms in branchable.
// note that the three arrays should be separate, they may contain the same rooms however
protected void createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable, ArrayList<Room> roomsToBranch, float[] connChances) {
    int i = 0;
    float angle;
    int tries;
    Room curr;
    ArrayList<Room> connectingRoomsThisBranch = new ArrayList<>();
    float[] connectionChances = connChances.clone();
    while (i < roomsToBranch.size()) {
        Room r = roomsToBranch.get(i);
        connectingRoomsThisBranch.clear();
        do {
            curr = Random.element(branchable);
        } while (r instanceof SecretRoom && curr instanceof ConnectionRoom);
        int connectingRooms = Random.chances(connectionChances);
        if (connectingRooms == -1) {
            connectionChances = connChances.clone();
            connectingRooms = Random.chances(connectionChances);
        }
        connectionChances[connectingRooms]--;
        for (int j = 0; j < connectingRooms; j++) {
            ConnectionRoom t = r instanceof SecretRoom ? new MazeConnectionRoom() : ConnectionRoom.createRoom();
            tries = 3;
            do {
                angle = placeRoom(rooms, curr, t, randomBranchAngle(curr));
                tries--;
            } while (angle == -1 && tries > 0);
            if (angle == -1) {
                for (Room c : connectingRoomsThisBranch) {
                    c.clearConnections();
                    rooms.remove(c);
                }
                connectingRoomsThisBranch.clear();
                break;
            } else {
                connectingRoomsThisBranch.add(t);
                rooms.add(t);
            }
            curr = t;
        }
        if (connectingRoomsThisBranch.size() != connectingRooms) {
            continue;
        }
        tries = 10;
        do {
            angle = placeRoom(rooms, curr, r, randomBranchAngle(curr));
            tries--;
        } while (angle == -1 && tries > 0);
        if (angle == -1) {
            for (Room t : connectingRoomsThisBranch) {
                t.clearConnections();
                rooms.remove(t);
            }
            connectingRoomsThisBranch.clear();
            continue;
        }
        for (int j = 0; j < connectingRoomsThisBranch.size(); j++) {
            if (Random.Int(3) <= 1)
                branchable.add(connectingRoomsThisBranch.get(j));
        }
        if (r.maxConnections(Room.ALL) > 1 && Random.Int(3) == 0) {
            if (r instanceof StandardRoom) {
                for (int j = 0; j < ((StandardRoom) r).sizeCat.connectionWeight(); j++) {
                    branchable.add(r);
                }
            } else {
                branchable.add(r);
            }
        }
        i++;
    }
}
Also used : MazeConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) SecretRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom) MazeConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom) ArrayList(java.util.ArrayList) MazeConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) ShopRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) SecretRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom) EntranceRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom) ExitRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)

Example 2 with ConnectionRoom

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom in project shattered-pixel-dungeon-gdx by 00-Evan.

the class LineBuilder method build.

@Override
public ArrayList<Room> build(ArrayList<Room> rooms) {
    setupRooms(rooms);
    if (entrance == null) {
        return null;
    }
    float direction = Random.Float(0, 360);
    ArrayList<Room> branchable = new ArrayList<>();
    entrance.setSize();
    entrance.setPos(0, 0);
    branchable.add(entrance);
    if (shop != null) {
        placeRoom(rooms, entrance, shop, direction + 180f);
    }
    int roomsOnPath = (int) (multiConnections.size() * pathLength) + Random.chances(pathLenJitterChances);
    roomsOnPath = Math.min(roomsOnPath, multiConnections.size());
    Room curr = entrance;
    float[] pathTunnels = pathTunnelChances.clone();
    for (int i = 0; i <= roomsOnPath; i++) {
        if (i == roomsOnPath && exit == null)
            continue;
        int tunnels = Random.chances(pathTunnels);
        if (tunnels == -1) {
            pathTunnels = pathTunnelChances.clone();
            tunnels = Random.chances(pathTunnels);
        }
        pathTunnels[tunnels]--;
        for (int j = 0; j < tunnels; j++) {
            ConnectionRoom t = ConnectionRoom.createRoom();
            placeRoom(rooms, curr, t, direction + Random.Float(-pathVariance, pathVariance));
            branchable.add(t);
            rooms.add(t);
            curr = t;
        }
        Room r = (i == roomsOnPath ? exit : multiConnections.get(i));
        placeRoom(rooms, curr, r, direction + Random.Float(-pathVariance, pathVariance));
        branchable.add(r);
        curr = r;
    }
    ArrayList<Room> roomsToBranch = new ArrayList<>();
    for (int i = roomsOnPath; i < multiConnections.size(); i++) {
        roomsToBranch.add(multiConnections.get(i));
    }
    roomsToBranch.addAll(singleConnections);
    weightRooms(branchable);
    createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
    findNeighbours(rooms);
    for (Room r : rooms) {
        for (Room n : r.neigbours) {
            if (!n.connected.containsKey(r) && Random.Float() < extraConnectionChance) {
                r.connect(n);
            }
        }
    }
    return rooms;
}
Also used : ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)

Example 3 with ConnectionRoom

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom in project shattered-pixel-dungeon-gdx by 00-Evan.

the class LoopBuilder method build.

@Override
public ArrayList<Room> build(ArrayList<Room> rooms) {
    setupRooms(rooms);
    if (entrance == null) {
        return null;
    }
    entrance.setSize();
    entrance.setPos(0, 0);
    float startAngle = Random.Float(0, 360);
    ArrayList<Room> loop = new ArrayList<>();
    int roomsOnLoop = (int) (multiConnections.size() * pathLength) + Random.chances(pathLenJitterChances);
    roomsOnLoop = Math.min(roomsOnLoop, multiConnections.size());
    roomsOnLoop++;
    float[] pathTunnels = pathTunnelChances.clone();
    for (int i = 0; i < roomsOnLoop; i++) {
        if (i == 0)
            loop.add(entrance);
        else
            loop.add(multiConnections.remove(0));
        int tunnels = Random.chances(pathTunnels);
        if (tunnels == -1) {
            pathTunnels = pathTunnelChances.clone();
            tunnels = Random.chances(pathTunnels);
        }
        pathTunnels[tunnels]--;
        for (int j = 0; j < tunnels; j++) {
            loop.add(ConnectionRoom.createRoom());
        }
    }
    if (exit != null)
        loop.add((loop.size() + 1) / 2, exit);
    Room prev = entrance;
    float targetAngle;
    for (int i = 1; i < loop.size(); i++) {
        Room r = loop.get(i);
        targetAngle = startAngle + targetAngle(i / (float) loop.size());
        if (placeRoom(rooms, prev, r, targetAngle) != -1) {
            prev = r;
            if (!rooms.contains(prev))
                rooms.add(prev);
        } else {
            // FIXME this is lazy, there are ways to do this without relying on chance
            return null;
        }
    }
    // should just write a general function for stitching two rooms together in builder
    while (!prev.connect(entrance)) {
        ConnectionRoom c = ConnectionRoom.createRoom();
        if (placeRoom(loop, prev, c, angleBetweenRooms(prev, entrance)) == -1) {
            return null;
        }
        loop.add(c);
        rooms.add(c);
        prev = c;
    }
    loopCenter = new PointF();
    for (Room r : loop) {
        loopCenter.x += (r.left + r.right) / 2f;
        loopCenter.y += (r.top + r.bottom) / 2f;
    }
    loopCenter.x /= loop.size();
    loopCenter.y /= loop.size();
    if (shop != null) {
        float angle;
        int tries = 10;
        do {
            angle = placeRoom(loop, entrance, shop, Random.Float(360f));
            tries--;
        } while (angle == -1 && tries >= 0);
        if (angle == -1)
            return null;
    }
    ArrayList<Room> branchable = new ArrayList<>(loop);
    ArrayList<Room> roomsToBranch = new ArrayList<>();
    roomsToBranch.addAll(multiConnections);
    roomsToBranch.addAll(singleConnections);
    weightRooms(branchable);
    createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
    findNeighbours(rooms);
    for (Room r : rooms) {
        for (Room n : r.neigbours) {
            if (!n.connected.containsKey(r) && Random.Float() < extraConnectionChance) {
                r.connect(n);
            }
        }
    }
    return rooms;
}
Also used : ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) PointF(com.watabou.utils.PointF) ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)

Example 4 with ConnectionRoom

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom in project shattered-pixel-dungeon-gdx by 00-Evan.

the class CavesPainter method decorate.

@Override
protected void decorate(Level level, ArrayList<Room> rooms) {
    int w = level.width();
    int l = level.length();
    int[] map = level.map;
    for (Room room : rooms) {
        if (!(room instanceof EmptyRoom || room instanceof CaveRoom)) {
            continue;
        }
        if (room.width() <= 4 || room.height() <= 4) {
            continue;
        }
        int s = room.square();
        if (Random.Int(s) > 8) {
            int corner = (room.left + 1) + (room.top + 1) * w;
            if (map[corner - 1] == Terrain.WALL && map[corner - w] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
                level.traps.remove(corner);
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.right - 1) + (room.top + 1) * w;
            if (map[corner + 1] == Terrain.WALL && map[corner - w] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
                level.traps.remove(corner);
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.left + 1) + (room.bottom - 1) * w;
            if (map[corner - 1] == Terrain.WALL && map[corner + w] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
                level.traps.remove(corner);
            }
        }
        if (Random.Int(s) > 8) {
            int corner = (room.right - 1) + (room.bottom - 1) * w;
            if (map[corner + 1] == Terrain.WALL && map[corner + w] == Terrain.WALL) {
                map[corner] = Terrain.WALL;
                level.traps.remove(corner);
            }
        }
        for (Room n : room.connected.keySet()) {
            if ((n instanceof StandardRoom || n instanceof ConnectionRoom) && Random.Int(3) == 0) {
                Painter.set(level, room.connected.get(n), Terrain.EMPTY_DECO);
            }
        }
    }
    for (int i = w + 1; i < l - w; i++) {
        if (map[i] == Terrain.EMPTY) {
            int n = 0;
            if (map[i + 1] == Terrain.WALL) {
                n++;
            }
            if (map[i - 1] == Terrain.WALL) {
                n++;
            }
            if (map[i + w] == Terrain.WALL) {
                n++;
            }
            if (map[i - w] == Terrain.WALL) {
                n++;
            }
            if (Random.Int(6) <= n) {
                map[i] = Terrain.EMPTY_DECO;
            }
        }
    }
    for (int i = 0; i < l - w; i++) {
        if (map[i] == Terrain.WALL && DungeonTileSheet.floorTile(map[i + w]) && Random.Int(4) == 0) {
            map[i] = Terrain.WALL_DECO;
        }
    }
    for (Room r : rooms) {
        if (r instanceof EmptyRoom) {
            for (Room n : r.neigbours) {
                if (n instanceof EmptyRoom && !r.connected.containsKey(n)) {
                    Rect i = r.intersect(n);
                    if (i.left == i.right && i.bottom - i.top >= 5) {
                        i.top += 2;
                        i.bottom -= 1;
                        i.right++;
                        Painter.fill(level, i.left, i.top, 1, i.height(), Terrain.CHASM);
                    } else if (i.top == i.bottom && i.right - i.left >= 5) {
                        i.left += 2;
                        i.right -= 1;
                        i.bottom++;
                        Painter.fill(level, i.left, i.top, i.width(), 1, Terrain.CHASM);
                    }
                }
            }
        }
    }
}
Also used : ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) Rect(com.watabou.utils.Rect) CaveRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.CaveRoom) EmptyRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom) EmptyRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom) CaveRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.CaveRoom) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom) StandardRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)

Aggregations

Room (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)4 ConnectionRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)4 ArrayList (java.util.ArrayList)3 StandardRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)2 MazeConnectionRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.MazeConnectionRoom)1 SecretRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom)1 ShopRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom)1 CaveRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.CaveRoom)1 EmptyRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom)1 EntranceRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom)1 ExitRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom)1 PointF (com.watabou.utils.PointF)1 Rect (com.watabou.utils.Rect)1