Search in sources :

Example 1 with SecretRoom

use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom 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)

Aggregations

Room (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)1 ConnectionRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)1 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 EntranceRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom)1 ExitRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom)1 StandardRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom)1 ArrayList (java.util.ArrayList)1