use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room 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++;
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RingBridgeRoom method paint.
@Override
public void paint(Level level) {
Painter.fill(level, this, 1, Terrain.CHASM);
super.paint(level);
for (Room r : neigbours) {
if (r instanceof BridgeRoom || r instanceof RingBridgeRoom || r instanceof WalkwayRoom) {
Rect i = intersect(r);
if (i.width() != 0) {
i.left++;
i.right--;
} else {
i.top++;
i.bottom--;
}
Painter.fill(level, i.left, i.top, i.width() + 1, i.height() + 1, Terrain.CHASM);
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class PrisonPainter method decorate.
@Override
protected void decorate(Level level, ArrayList<Room> rooms) {
for (Room r : rooms) {
if (r instanceof EntranceRoom) {
Wandmaker.Quest.spawnWandmaker(level, r);
break;
}
}
int w = level.width();
int l = level.length();
int[] map = level.map;
for (int i = w + 1; i < l - w - 1; i++) {
if (map[i] == Terrain.EMPTY) {
float c = 0.05f;
if (map[i + 1] == Terrain.WALL && map[i + w] == Terrain.WALL) {
c += 0.2f;
}
if (map[i - 1] == Terrain.WALL && map[i + w] == Terrain.WALL) {
c += 0.2f;
}
if (map[i + 1] == Terrain.WALL && map[i - w] == Terrain.WALL) {
c += 0.2f;
}
if (map[i - 1] == Terrain.WALL && map[i - w] == Terrain.WALL) {
c += 0.2f;
}
if (Random.Float() < c) {
map[i] = Terrain.EMPTY_DECO;
}
}
}
for (int i = 0; i < w; i++) {
if (map[i] == Terrain.WALL && (map[i + w] == Terrain.EMPTY || map[i + w] == Terrain.EMPTY_SP) && Random.Int(6) == 0) {
map[i] = Terrain.WALL_DECO;
}
}
for (int i = w; i < l - w; i++) {
if (map[i] == Terrain.WALL && map[i - w] == Terrain.WALL && (map[i + w] == Terrain.EMPTY || map[i + w] == Terrain.EMPTY_SP) && Random.Int(3) == 0) {
map[i] = Terrain.WALL_DECO;
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularPainter method placeDoors.
private void placeDoors(Room r) {
for (Room n : r.connected.keySet()) {
Room.Door door = r.connected.get(n);
if (door == null) {
Rect i = r.intersect(n);
ArrayList<Point> doorSpots = new ArrayList<>();
for (Point p : i.getPoints()) {
if (r.canConnect(p) && n.canConnect(p))
doorSpots.add(p);
}
if (doorSpots.isEmpty()) {
ShatteredPixelDungeon.reportException(new RuntimeException("Could not place a door! " + "r=" + r.getClass().getSimpleName() + " n=" + n.getClass().getSimpleName()));
continue;
}
door = new Room.Door(Random.element(doorSpots));
r.connected.put(n, door);
n.connected.put(r, door);
}
}
}
use of com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularPainter method paintTraps.
protected void paintTraps(Level l, ArrayList<Room> rooms) {
ArrayList<Integer> validCells = new ArrayList<>();
if (!rooms.isEmpty()) {
for (Room r : rooms) {
for (Point p : r.trapPlaceablePoints()) {
int i = l.pointToCell(p);
if (l.map[i] == Terrain.EMPTY) {
validCells.add(i);
}
}
}
} else {
for (int i = 0; i < l.length(); i++) {
if (l.map[i] == Terrain.EMPTY) {
validCells.add(i);
}
}
}
// no more than one trap every 5 valid tiles.
nTraps = Math.min(nTraps, validCells.size() / 5);
for (int i = 0; i < nTraps; i++) {
Integer trapPos = Random.element(validCells);
// removes the integer object, not at the index
validCells.remove(trapPos);
try {
Trap trap = trapClasses[Random.chances(trapChances)].newInstance().hide();
l.setTrap(trap, trapPos);
// some traps will not be hidden
l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Aggregations