diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index e7ec9c8fd..bc3da6236 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -1079,24 +1079,22 @@ public class Dungeon { return PathFinder.getStep( ch.pos, to, findPassable(ch, pass, visible, chars) ); } - + public static int flee( Char ch, int from, boolean[] pass, boolean[] visible, boolean chars ) { boolean[] passable = findPassable(ch, pass, visible, false, true); passable[ch.pos] = true; - //only consider other chars impassable if our retreat step may collide with them - if (chars) { - for (Char c : Actor.chars()) { - if (c.pos == from || Dungeon.level.adjacent(c.pos, ch.pos)) { - passable[c.pos] = false; - } - } - } - //chars affected by terror have a shorter lookahead and can't approach the fear source boolean canApproachFromPos = ch.buff(Terror.class) == null && ch.buff(Dread.class) == null; - return PathFinder.getStepBack( ch.pos, from, canApproachFromPos ? 8 : 4, passable, canApproachFromPos ); - + int step = PathFinder.getStepBack( ch.pos, from, canApproachFromPos ? 8 : 4, passable, canApproachFromPos ); + + //only consider chars impassable if our retreat step runs into them + while (step != -1 && Actor.findChar(step) != null && chars){ + passable[step] = false; + step = PathFinder.getStepBack( ch.pos, from, canApproachFromPos ? 8 : 4, passable, canApproachFromPos ); + } + return step; + } }