v0.9.2: added a safety check to ensure caves fissure rooms are pathable

This commit is contained in:
Evan Debenham 2021-01-25 23:22:19 -05:00
parent 6310fe09c8
commit 479096d10f

View File

@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Point;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
@ -59,6 +60,11 @@ public class CavesFissureRoom extends StandardRoom {
@Override
public void paint(Level level) {
boolean pathable = true;
PathFinder.setMapSize(width()-2, height()-2);
do {
Painter.fill(level, this, Terrain.WALL);
Painter.fill(level, this, 1, Terrain.EMPTY);
@ -143,7 +149,8 @@ public class CavesFissureRoom extends StandardRoom {
&& ((curr.x % 1 <= 0.5f) || sizeCat == SizeCategory.GIANT)) {
Painter.set(level, cell - 1, Terrain.CHASM);
}
if (level.map[cell] == Terrain.EMPTY) Painter.set(level, cell, Terrain.CHASM);
if (level.map[cell] == Terrain.EMPTY)
Painter.set(level, cell, Terrain.CHASM);
if (level.map[cell + 1] == Terrain.EMPTY
&& ((curr.x % 1 > 0.5f) || sizeCat == SizeCategory.GIANT)) {
Painter.set(level, cell + 1, Terrain.CHASM);
@ -153,7 +160,8 @@ public class CavesFissureRoom extends StandardRoom {
&& ((curr.y % 1 <= 0.5f) || sizeCat == SizeCategory.GIANT)) {
Painter.set(level, cell - level.width(), Terrain.CHASM);
}
if (level.map[cell] == Terrain.EMPTY) Painter.set(level, cell, Terrain.CHASM);
if (level.map[cell] == Terrain.EMPTY)
Painter.set(level, cell, Terrain.CHASM);
if (level.map[cell + level.width()] == Terrain.EMPTY
&& ((curr.y % 1 > 0.5f) || sizeCat == SizeCategory.GIANT)) {
Painter.set(level, cell + level.width(), Terrain.CHASM);
@ -185,17 +193,46 @@ public class CavesFissureRoom extends StandardRoom {
}
}
int doorPoint = 0;
for (Door door : connected.values()) {
Painter.drawInside(level, this, door, 1, Terrain.EMPTY);
if (door.x == left) doorPoint = xyToRoomCoords(door.x+1, door.y);
else if (door.x == right) doorPoint = xyToRoomCoords(door.x-1, door.y);
else if (door.y == top) doorPoint = xyToRoomCoords(door.x, door.y+1);
else if (door.y == bottom) doorPoint = xyToRoomCoords(door.x, door.y-1);
}
//ensures that there is always a path to any non-chasm tile
//TODO some copypasta from PatchRoom here, maybe standardize this as a static function in Room?
pathable = true;
boolean[] passable = new boolean[PathFinder.distance.length];
for (Point p : shrink().getPoints()){
int i = xyToRoomCoords(p.x, p.y);
passable[i] = level.map[level.pointToCell(p)] != Terrain.CHASM;
}
PathFinder.buildDistanceMap(doorPoint, passable);
for (Point p : shrink().getPoints()){
int i = xyToRoomCoords(p.x, p.y);
if (passable[i] && PathFinder.distance[i] == Integer.MAX_VALUE){
pathable = false;
break;
}
}
} while (!pathable);
PathFinder.setMapSize(level.width(), level.height());
}
private void buildBridge( Level level, float fisssureAngle, PointF center, int centerMargin){
float dX = (float)Math.cos(fisssureAngle/A - Math.PI/2.0);
float dY = (float)Math.sin(fisssureAngle/A - Math.PI/2.0);
int edgemargin = sizeCat == SizeCategory.NORMAL ? 3 : 2;
int edgemargin = 2;
//horizontal bridge
if (Math.abs(dY) >= Math.abs(dX)){
@ -268,4 +305,8 @@ public class CavesFissureRoom extends StandardRoom {
return angle;
}
protected int xyToRoomCoords(int x, int y){
return (x-left-1) + ((y-top-1) * (width()-2));
}
}