v0.6.0: standardized calculations relating to room dimensions

This commit is contained in:
Evan Debenham 2017-03-13 19:45:50 -04:00
parent 0a5e33a5af
commit 4c75de1bfa
19 changed files with 74 additions and 56 deletions

View File

@ -284,7 +284,7 @@ public class Blacksmith extends NPC {
Room blacksmith;
for (Room r : rooms) {
if (r instanceof StandardRoom && r.width() > 4 && r.height() > 4) {
if (r instanceof StandardRoom && r.width() >= 6 && r.height() >= 6) {
blacksmith = new BlacksmithRoom().set(r);
rooms.set(rooms.indexOf(r), blacksmith);

View File

@ -295,7 +295,7 @@ public class Wandmaker extends NPC {
//we don't re-roll the quest, it will try to assign itself to that new level with the same type.
Room questRoom = null;
for (Room r : rooms){
if (r instanceof StandardRoom && r.width() > 5 && r.height() > 5){
if (r instanceof StandardRoom && r.width() >= 7 && r.height() >= 7){
if (type == 2 || r.connected.size() == 1){
questRoom = r;
break;

View File

@ -106,7 +106,7 @@ public class CavesLevel extends RegularLevel {
continue;
}
if (room.width() <= 3 || room.height() <= 3) {
if (room.width() <= 4 || room.height() <= 4) {
continue;
}

View File

@ -22,9 +22,9 @@
package com.shatteredpixel.shatteredpixeldungeon.levels;
import android.opengl.GLES20;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.shatteredpixel.shatteredpixeldungeon.items.Torch;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.BlazingTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.CursingTrap;
@ -46,6 +46,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.VenomTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WarpingTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WeakeningTrap;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.particles.PixelParticle;
@ -58,7 +59,7 @@ import javax.microedition.khronos.opengles.GL10;
public class HallsLevel extends RegularLevel {
{
minRoomSize = 6;
minRoomSize = 7;
viewDistance = Math.max( 25 - Dungeon.depth, 1 );

View File

@ -52,15 +52,15 @@ public class Painter {
}
public static void fill( Level level, Rect rect, int value ) {
fill( level, rect.left, rect.top, rect.width() + 1, rect.height() + 1, value );
fill( level, rect.left, rect.top, rect.width(), rect.height(), value );
}
public static void fill( Level level, Rect rect, int m, int value ) {
fill( level, rect.left + m, rect.top + m, rect.width() + 1 - m*2, rect.height() + 1 - m*2, value );
fill( level, rect.left + m, rect.top + m, rect.width() - m*2, rect.height() - m*2, value );
}
public static void fill( Level level, Rect rect, int l, int t, int r, int b, int value ) {
fill( level, rect.left + l, rect.top + t, rect.width() + 1 - (l + r), rect.height() + 1 - (t + b), value );
fill( level, rect.left + l, rect.top + t, rect.width() - (l + r), rect.height() - (t + b), value );
}
public static Point drawInside( Level level, Room room, Point from, int n, int value ) {

View File

@ -201,8 +201,8 @@ public abstract class RegularLevel extends Level {
return new float[]{1};
}
protected int minRoomSize = 7;
protected int maxRoomSize = 9;
protected int minRoomSize = 8;
protected int maxRoomSize = 10;
protected boolean paint() {

View File

@ -102,7 +102,7 @@ public class SewerBossLevel extends RegularLevel {
@Override
protected void decorate() {
int start = roomExit.top * width() + roomExit.left + 1;
int end = start + roomExit.width() - 1;
int end = start + roomExit.width() - 2;
for (int i=start; i < end; i++) {
if (i != exit && map[i] == Terrain.WALL) {
map[i] = Terrain.WALL_DECO;

View File

@ -90,11 +90,11 @@ public class LegacyBuilder extends Builder {
do {
do {
roomEntrance = Random.element( rooms );
} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
} while (roomEntrance.width() <= 4 || roomEntrance.height() <= 4);
do {
roomExit = Random.element( rooms );
} while (roomExit == roomEntrance || roomExit.width() < 4 || roomExit.height() < 4);
} while (roomExit == roomEntrance || roomExit.width() <= 4 || roomExit.height() <= 4);
Graph.buildDistanceMap( rooms, roomExit );
distance = roomEntrance.distance();
@ -153,7 +153,7 @@ public class LegacyBuilder extends Builder {
if (Dungeon.shopOnLevel()) {
Room shop = null;
for (Room r : roomEntrance.connected.keySet()) {
if (r.connected.size() == 1 && ((r.width()-1)*(r.height()-1) >= ShopRoom.spaceNeeded())) {
if (r.connected.size() == 1 && ((r.width()-2)*(r.height()-2) >= ShopRoom.spaceNeeded())) {
shop = r;
break;
}
@ -163,7 +163,7 @@ public class LegacyBuilder extends Builder {
return null;
} else {
temp = shop;
shop = new LaboratoryRoom().set(temp);
shop = new ShopRoom().set(temp);
rooms.set(rooms.indexOf(temp), shop);
}
}
@ -213,7 +213,7 @@ public class LegacyBuilder extends Builder {
return null;
}
roomEntrance = Random.element( rooms );
} while (roomEntrance.width() != 8 || roomEntrance.height() < 5 || roomEntrance.top == 0 || roomEntrance.top >= 8);
} while (roomEntrance.width() != 9 || roomEntrance.height() < 6 || roomEntrance.top == 0 || roomEntrance.top >= 8);
Room temp = roomEntrance;
roomEntrance = new EntranceRoom().set(temp);
@ -322,7 +322,7 @@ public class LegacyBuilder extends Builder {
return null;
}
roomEntrance = Random.element( rooms );
} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
} while (roomEntrance.width() <= 4 || roomEntrance.height() <= 4);
innerRetry = 0;
do {
@ -330,7 +330,7 @@ public class LegacyBuilder extends Builder {
return null;
}
roomExit = Random.element( rooms );
} while (roomExit == roomEntrance || roomExit.width() < 6 || roomExit.height() < 6 || roomExit.top == 0);
} while (roomExit == roomEntrance || roomExit.width() <= 6 || roomExit.height() <= 6 || roomExit.top == 0);
Graph.buildDistanceMap( rooms, roomExit );
distance = Graph.buildPath( rooms, roomEntrance, roomExit ).size();
@ -413,8 +413,9 @@ public class LegacyBuilder extends Builder {
private void split( Rect rect ) {
int w = rect.width();
int h = rect.height();
//To match with rooms
int w = rect.width()+1;
int h = rect.height()+1;
if (w > maxRoomSize && h < minRoomSize) {
@ -462,7 +463,7 @@ public class LegacyBuilder extends Builder {
r.connected.size() == 1) {
if (specials.size() > 0 &&
r.width() > 3 && r.height() > 3 &&
r.width() > 4 && r.height() > 4 &&
Random.Int( specialRooms * specialRooms + 2 ) == 0) {
if (Level.pitRoomNeeded && !pitMade) {

View File

@ -45,7 +45,7 @@ public class LibraryRoom extends Room {
Point a = null;
Point b = null;
Painter.fill( level, room.left + 1, room.top+1, room.width() - 1, 1 , Terrain.BOOKSHELF );
Painter.fill( level, room.left + 1, room.top+1, room.width() - 2, 1 , Terrain.BOOKSHELF );
if (entrance.y == room.top){
Painter.set( level, entrance.x, entrance.y + 1, Terrain.EMPTY_SP );
}

View File

@ -52,7 +52,7 @@ public class MassGraveRoom extends Room {
Bones b = new Bones();
b.setRect(room.left+1, room.top, room.width()-1, room.height());
b.setRect(room.left+1, room.top, room.width()-2, room.height()-1);
level.customTiles.add(b);
//50% 1 skeleton, 50% 2 skeletons

View File

@ -32,7 +32,7 @@ public class MazeRoom extends Room {
Painter.fill(level, room, 1, Terrain.EMPTY);
//true = space, false = wall
boolean[][] maze = new boolean[room.width() + 1][room.height() + 1];
boolean[][] maze = new boolean[room.width()][room.height()];
for (int x = 0; x < maze.length; x++) {
for (int y = 0; y < maze[0].length; y++) {

View File

@ -35,8 +35,8 @@ public class PassageRoom extends Room {
public void paint( Level level, Room room ) {
pasWidth = room.width() - 2;
pasHeight = room.height() - 2;
pasWidth = room.width() - 3;
pasHeight = room.height() - 3;
int floor = level.tunnelTile();

View File

@ -66,6 +66,22 @@ public class Room extends Rect implements Graph.Node, Bundlable {
return this;
}
//Width and height are increased by 1 because rooms are inclusive to their right and bottom sides
@Override
public int width() {
return super.width()+1;
}
@Override
public int height() {
return super.height()+1;
}
@Override
public int square() {
return width()*height();
}
public void paint(Level level){
paint(level, this);
}

View File

@ -59,7 +59,7 @@ public class RotGardenRoom extends Room {
placePlant(level, heartX + heartY * level.width(), new RotHeart());
int lashers = ((room.right-room.left-1)*(room.bottom-room.top-1))/8;
int lashers = ((room.width()-2)*(room.height()-2))/8;
for (int i = 1; i <= lashers; i++){
int pos;

View File

@ -90,8 +90,8 @@ public class ShopRoom extends Room {
Painter.fill( level, room, Terrain.WALL );
Painter.fill( level, room, 1, Terrain.EMPTY_SP );
pasWidth = room.width() - 2;
pasHeight = room.height() - 2;
pasWidth = room.width() - 3;
pasHeight = room.height() - 3;
int per = pasWidth * 2 + pasHeight * 2;
if (itemsToSpawn == null)

View File

@ -46,7 +46,7 @@ public class StandardRoom extends Room {
switch (Random.Int( 6 )) {
case 0:
if (level.feeling != Level.Feeling.GRASS) {
if (Math.min( room.width(), room.height() ) >= 4 && Math.max( room.width(), room.height() ) >= 6) {
if (Math.min( room.width(), room.height() ) > 4 && Math.max( room.width(), room.height() ) > 6) {
paintGraveyard( level, room );
return;
}
@ -61,20 +61,20 @@ public class StandardRoom extends Room {
}
break;
case 2:
if (Math.max( room.width(), room.height() ) >= 4) {
if (Math.max( room.width(), room.height() ) > 4) {
paintStriped( level, room );
return;
}
break;
case 3:
if (room.width() >= 6 && room.height() >= 6) {
if (room.width() > 6 && room.height() > 6) {
paintStudy( level, room );
return;
}
break;
case 4:
if (level.feeling != Level.Feeling.WATER) {
if (room.connected.size() == 2 && room.width() >= 4 && room.height() >= 4) {
if (room.connected.size() == 2 && room.width() > 4 && room.height() > 4) {
paintBridge( level, room );
return;
}
@ -84,7 +84,7 @@ public class StandardRoom extends Room {
}
case 5:
if (!Dungeon.bossLevel() && !Dungeon.bossLevel( Dungeon.depth + 1 ) &&
Math.min( room.width(), room.height() ) >= 5) {
Math.min( room.width(), room.height() ) > 5) {
paintFissure( level, room );
return;
}
@ -125,10 +125,10 @@ public class StandardRoom extends Room {
}
private static void paintGraveyard( Level level, Room room ) {
Painter.fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 , Terrain.GRASS );
Painter.fill( level, room , 1 , Terrain.GRASS );
int w = room.width() - 1;
int h = room.height() - 1;
int w = room.width() - 2;
int h = room.height() - 2;
int nGraves = Math.max( w, h ) / 2;
int index = Random.Int( nGraves );
@ -143,23 +143,23 @@ public class StandardRoom extends Room {
}
private static void paintStriped( Level level, Room room ) {
Painter.fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 , Terrain.EMPTY_SP );
Painter.fill( level, room, 1 , Terrain.EMPTY_SP );
if (room.width() > room.height()) {
for (int i=room.left + 2; i < room.right; i += 2) {
Painter.fill( level, i, room.top + 1, 1, room.height() - 1, Terrain.HIGH_GRASS );
Painter.fill( level, i, room.top + 1, 1, room.height() - 2, Terrain.HIGH_GRASS );
}
} else {
for (int i=room.top + 2; i < room.bottom; i += 2) {
Painter.fill( level, room.left + 1, i, room.width() - 1, 1, Terrain.HIGH_GRASS );
Painter.fill( level, room.left + 1, i, room.width() - 2, 1, Terrain.HIGH_GRASS );
}
}
}
//TODO: this is almost a special room type now, consider moving this into its own painter if/when you address room gen significantly.
private static void paintStudy( Level level, Room room ) {
Painter.fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 , Terrain.BOOKSHELF );
Painter.fill( level, room.left + 2, room.top + 2, room.width() - 3, room.height() - 3 , Terrain.EMPTY_SP );
Painter.fill( level, room, 1 , Terrain.BOOKSHELF );
Painter.fill( level, room, 2 , Terrain.EMPTY_SP );
for (Point door : room.connected.values()) {
if (door.x == room.left) {
@ -189,7 +189,7 @@ public class StandardRoom extends Room {
private static void paintBridge( Level level, Room room ) {
Painter.fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 ,
Painter.fill( level, room, 1,
!Dungeon.bossLevel() && !Dungeon.bossLevel( Dungeon.depth + 1 ) && Random.Int( 3 ) == 0 ?
Terrain.CHASM :
Terrain.WATER );
@ -249,7 +249,7 @@ public class StandardRoom extends Room {
}
private static void paintFissure( Level level, Room room ) {
Painter.fill( level, room.left + 1, room.top + 1, room.width() - 1, room.height() - 1 ,Terrain.EMPTY );
Painter.fill( level, room, 1, Terrain.EMPTY );
for (int i=room.top + 2; i < room.bottom - 1; i++) {
for (int j=room.left + 2; j < room.right - 1; j++) {

View File

@ -47,22 +47,22 @@ public class StatueRoom extends Room {
if (door.x == room.left) {
Painter.fill( level, room.right - 1, room.top + 1, 1, room.height() - 1 , Terrain.STATUE );
Painter.fill( level, room.right - 1, room.top + 1, 1, room.height() - 2 , Terrain.STATUE );
cx = room.right - 2;
} else if (door.x == room.right) {
Painter.fill( level, room.left + 1, room.top + 1, 1, room.height() - 1 , Terrain.STATUE );
Painter.fill( level, room.left + 1, room.top + 1, 1, room.height() - 2 , Terrain.STATUE );
cx = room.left + 2;
} else if (door.y == room.top) {
Painter.fill( level, room.left + 1, room.bottom - 1, room.width() - 1, 1 , Terrain.STATUE );
Painter.fill( level, room.left + 1, room.bottom - 1, room.width() - 2, 1 , Terrain.STATUE );
cy = room.bottom - 2;
} else if (door.y == room.bottom) {
Painter.fill( level, room.left + 1, room.top + 1, room.width() - 1, 1 , Terrain.STATUE );
Painter.fill( level, room.left + 1, room.top + 1, room.width() - 2, 1 , Terrain.STATUE );
cy = room.top + 2;
}

View File

@ -83,19 +83,19 @@ public class TrapsRoom extends Room {
if (door.x == room.left) {
x = room.right - 1;
y = room.top + room.height() / 2;
Painter.fill( level, x, room.top + 1, 1, room.height() - 1 , lastRow );
Painter.fill( level, x, room.top + 1, 1, room.height() - 2 , lastRow );
} else if (door.x == room.right) {
x = room.left + 1;
y = room.top + room.height() / 2;
Painter.fill( level, x, room.top + 1, 1, room.height() - 1 , lastRow );
Painter.fill( level, x, room.top + 1, 1, room.height() - 2 , lastRow );
} else if (door.y == room.top) {
x = room.left + room.width() / 2;
y = room.bottom - 1;
Painter.fill( level, room.left + 1, y, room.width() - 1, 1 , lastRow );
Painter.fill( level, room.left + 1, y, room.width() - 2, 1 , lastRow );
} else if (door.y == room.bottom) {
x = room.left + room.width() / 2;
y = room.top + 1;
Painter.fill( level, room.left + 1, y, room.width() - 1, 1 , lastRow );
Painter.fill( level, room.left + 1, y, room.width() - 2, 1 , lastRow );
}
for(Point p : room.getPoints()) {

View File

@ -43,19 +43,19 @@ public class WeakFloorRoom extends Room {
if (door.x == room.left) {
for (int i=room.top + 1; i < room.bottom; i++) {
Painter.drawInside( level, room, new Point( room.left, i ), Random.IntRange( 1, room.width() - 2 ), Terrain.EMPTY_SP );
Painter.drawInside( level, room, new Point( room.left, i ), Random.IntRange( 1, room.width() - 3 ), Terrain.EMPTY_SP );
}
} else if (door.x == room.right) {
for (int i=room.top + 1; i < room.bottom; i++) {
Painter.drawInside( level, room, new Point( room.right, i ), Random.IntRange( 1, room.width() - 2 ), Terrain.EMPTY_SP );
Painter.drawInside( level, room, new Point( room.right, i ), Random.IntRange( 1, room.width() - 3 ), Terrain.EMPTY_SP );
}
} else if (door.y == room.top) {
for (int i=room.left + 1; i < room.right; i++) {
Painter.drawInside( level, room, new Point( i, room.top ), Random.IntRange( 1, room.height() - 2 ), Terrain.EMPTY_SP );
Painter.drawInside( level, room, new Point( i, room.top ), Random.IntRange( 1, room.height() - 3 ), Terrain.EMPTY_SP );
}
} else if (door.y == room.bottom) {
for (int i=room.left + 1; i < room.right; i++) {
Painter.drawInside( level, room, new Point( i, room.bottom ), Random.IntRange( 1, room.height() - 2 ), Terrain.EMPTY_SP );
Painter.drawInside( level, room, new Point( i, room.bottom ), Random.IntRange( 1, room.height() - 3 ), Terrain.EMPTY_SP );
}
}