v2.5.1: added safety checks to other potentially small entry/exit rooms

This commit is contained in:
Evan Debenham
2024-09-15 15:03:26 -04:00
parent 63c36166eb
commit f162999669
3 changed files with 45 additions and 3 deletions

View File

@@ -56,10 +56,24 @@ public class CaveEntranceRoom extends CaveRoom {
super.paint(level);
int entrance;
int tries = 30;
boolean valid;
do {
entrance = level.pointToCell(random(2));
} while (level.map[entrance] == Terrain.WALL || level.findMob(entrance) != null);
//need extra logic here as these rooms can spawn small and cramped in very rare cases
if (tries-- > 0){
valid = level.map[entrance] != Terrain.WALL && level.findMob(entrance) == null;
} else {
valid = false;
for (int i : PathFinder.NEIGHBOURS4){
if (level.map[entrance+i] != Terrain.WALL){
valid = true;
}
}
valid = valid && level.findMob(entrance) == null;
}
} while (!valid);
Painter.set( level, entrance, Terrain.ENTRANCE );
for (int i : PathFinder.NEIGHBOURS8){

View File

@@ -55,10 +55,24 @@ public class ChasmEntranceRoom extends ChasmRoom {
super.paint(level);
int entrance;
int tries = 30;
boolean valid;
do {
entrance = level.pointToCell(random(2));
} while (level.map[entrance] == Terrain.CHASM || level.findMob(entrance) != null);
//need extra logic here as these rooms can spawn small and cramped in very rare cases
if (tries-- > 0){
valid = level.map[entrance] != Terrain.CHASM && level.findMob(entrance) == null;
} else {
valid = false;
for (int i : PathFinder.NEIGHBOURS4){
if (level.map[entrance+i] != Terrain.CHASM){
valid = true;
}
}
valid = valid && level.findMob(entrance) == null;
}
} while (!valid);
Painter.set( level, entrance, Terrain.ENTRANCE );
for (int i : PathFinder.NEIGHBOURS8){

View File

@@ -55,10 +55,24 @@ public class ChasmExitRoom extends ChasmRoom {
super.paint(level);
int exit;
int tries = 30;
boolean valid;
do {
exit = level.pointToCell(random(2));
} while (level.map[exit] == Terrain.CHASM || level.findMob(exit) != null);
//need extra logic here as these rooms can spawn small and cramped in very rare cases
if (tries-- > 0){
valid = level.map[exit] != Terrain.CHASM && level.findMob(exit) == null;
} else {
valid = false;
for (int i : PathFinder.NEIGHBOURS4){
if (level.map[exit+i] != Terrain.CHASM){
valid = true;
}
}
valid = valid && level.findMob(exit) == null;
}
} while (!valid);
Painter.set( level, exit, Terrain.EXIT );
for (int i : PathFinder.NEIGHBOURS8){