From d407144e28f8862ecb554a1d53e7a5f401924961 Mon Sep 17 00:00:00 2001
From: Evan Debenham <Evan@ShatteredPixel.com>
Date: Sat, 29 Jul 2017 14:44:07 -0400
Subject: [PATCH] v0.6.1: further improved imp spawning logic, reverted changes
 to regular spawning logic

---
 .../shatteredpixeldungeon/actors/mobs/npcs/Imp.java    | 10 +++++++++-
 .../shatteredpixeldungeon/levels/RegularLevel.java     |  9 ++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java
index fe5ddf396..8189078f7 100644
--- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java
+++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java
@@ -32,12 +32,14 @@ import com.shatteredpixel.shatteredpixeldungeon.items.quest.DwarfToken;
 import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
 import com.shatteredpixel.shatteredpixeldungeon.journal.Notes;
 import com.shatteredpixel.shatteredpixeldungeon.levels.CityLevel;
+import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
 import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
 import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
 import com.shatteredpixel.shatteredpixeldungeon.sprites.ImpSprite;
 import com.shatteredpixel.shatteredpixeldungeon.windows.WndImp;
 import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest;
 import com.watabou.utils.Bundle;
+import com.watabou.utils.PathFinder;
 import com.watabou.utils.Random;
 
 public class Imp extends NPC {
@@ -184,7 +186,13 @@ public class Imp extends NPC {
 				Imp npc = new Imp();
 				do {
 					npc.pos = level.randomRespawnCell();
-				} while (npc.pos == -1 || level.heaps.get( npc.pos ) != null || level.findMob( npc.pos ) != null);
+				} while (
+						npc.pos == -1 ||
+						level.heaps.get( npc.pos ) != null ||
+						level.findMob( npc.pos ) != null ||
+						//The imp doesn't move, so he cannot obstruct a passageway
+						!(Level.passable[npc.pos + PathFinder.CIRCLE4[0]] && Level.passable[npc.pos + PathFinder.CIRCLE4[2]]) ||
+						!(Level.passable[npc.pos + PathFinder.CIRCLE4[1]] && Level.passable[npc.pos + PathFinder.CIRCLE4[3]]));
 				level.mobs.add( npc );
 				
 				spawned = true;
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 da96d8bae..a7be6e3f7 100644
--- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java
+++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java
@@ -255,13 +255,8 @@ public abstract class RegularLevel extends Level {
 			if (room == null || room == roomEntrance) {
 				continue;
 			}
-			
-			//if we can avoid it, don't place along the perimiter
-			if (room.width() >= 6 && room.height() >= 6) {
-				cell = pointToCell(room.random(2));
-			} else {
-				cell = pointToCell(room.random(1));
-			}
+
+			cell = pointToCell(room.random(1));
 			if (!Dungeon.visible[cell]
 					&& Actor.findChar( cell ) == null
 					&& Level.passable[cell]