v1.4.0: improved logic for limiting char and item spawn placement

This commit is contained in:
Evan Debenham
2022-09-15 17:09:24 -04:00
parent 0ef89d3c20
commit c3ab4f60fc
2 changed files with 22 additions and 1 deletions

View File

@@ -231,7 +231,11 @@ public abstract class RegularLevel extends Level {
do {
mob.pos = pointToCell(roomToSpawn.random());
tries--;
} while (tries >= 0 && (findMob(mob.pos) != null || !passable[mob.pos] || solid[mob.pos] || mob.pos == exit()
} while (tries >= 0 && (findMob(mob.pos) != null
|| !passable[mob.pos]
|| solid[mob.pos]
|| !roomToSpawn.canPlaceCharacter(cellToPoint(mob.pos), this)
|| mob.pos == exit()
|| (!openSpace[mob.pos] && mob.properties().contains(Char.Property.LARGE))));
if (tries >= 0) {
@@ -598,6 +602,7 @@ public abstract class RegularLevel extends Level {
if (passable[pos] && !solid[pos]
&& pos != exit()
&& heaps.get(pos) == null
&& room.canPlaceItem(cellToPoint(pos), this)
&& findMob(pos) == null) {
Trap t = traps.get(pos);

View File

@@ -334,6 +334,22 @@ public abstract class Room extends Rect implements Graph.Node, Bundlable {
}
return points;
}
//whether or not an item can be placed here (usually via randomDropCell)
public boolean canPlaceItem(Point p, Level l){
return inside(p);
}
public final ArrayList<Point> itemPlaceablePoints(Level l){
ArrayList<Point> points = new ArrayList<>();
for (int i = left; i <= right; i++) {
for (int j = top; j <= bottom; j++) {
Point p = new Point(i, j);
if (canPlaceItem(p, l)) points.add(p);
}
}
return points;
}
//whether or not a character can be placed here (usually via spawn, tele, or wander)
public boolean canPlaceCharacter(Point p, Level l){