From 7f13e1cefac4a887354500fd3521b33d73e8f314 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 28 Aug 2019 21:20:21 -0400 Subject: [PATCH] v0.7.5: refactored room selection logic for mob spawning --- .../levels/RegularLevel.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java index cd5e62bad..189072d60 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java @@ -195,27 +195,30 @@ public abstract class RegularLevel extends Level { Iterator stdRoomIter = stdRooms.iterator(); while (mobsToSpawn > 0) { - if (!stdRoomIter.hasNext()) - stdRoomIter = stdRooms.iterator(); - Room roomToSpawn = stdRoomIter.next(); - Mob mob = createMob(); - mob.pos = pointToCell(roomToSpawn.random()); + Room roomToSpawn; + + if (!stdRoomIter.hasNext()) { + stdRoomIter = stdRooms.iterator(); + } + roomToSpawn = stdRoomIter.next(); + + do { + mob.pos = pointToCell(roomToSpawn.random()); + } while (findMob(mob.pos) != null || !passable[mob.pos] || mob.pos == exit); + + mobsToSpawn--; + mobs.add(mob); + + if (mobsToSpawn > 0 && Random.Int(4) == 0){ + mob = createMob(); + + do { + mob.pos = pointToCell(roomToSpawn.random()); + } while (findMob(mob.pos) != null || !passable[mob.pos] || mob.pos == exit); - if (findMob(mob.pos) == null && passable[mob.pos] && mob.pos != exit) { mobsToSpawn--; mobs.add(mob); - - //TODO: perhaps externalize this logic into a method. Do I want to make mobs more likely to clump deeper down? - if (mobsToSpawn > 0 && Random.Int(4) == 0){ - mob = createMob(); - mob.pos = pointToCell(roomToSpawn.random()); - - if (findMob(mob.pos) == null && passable[mob.pos] && mob.pos != exit) { - mobsToSpawn--; - mobs.add(mob); - } - } } }