From 035672551eda08f17466e2916db5bb0328963271 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 1 Oct 2016 22:20:58 -0400 Subject: [PATCH] v0.4.3: fixed mobs occasionally walking into eachother --- .../shatteredpixeldungeon/actors/hero/Hero.java | 8 +++++--- .../shatteredpixeldungeon/actors/mobs/Mob.java | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 7ebf4ad1a..99df99f7a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -110,6 +110,7 @@ import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; +import com.watabou.utils.GameMath; import com.watabou.utils.PathFinder; import com.watabou.utils.Random; @@ -1050,11 +1051,12 @@ public class Hero extends Char { else if (path.getLast() != target) newPath = true; else { - //checks 2 cells ahead for validity. + //looks ahead for path validity, up to length-1 or 2. //Note that this is shorter than for mobs, so that mobs usually yield to the hero - for (int i = 0; i < Math.min(path.size(), 2); i++){ + int lookAhead = (int) GameMath.gate(0, path.size()-1, 2); + for (int i = 0; i < lookAhead; i++){ int cell = path.get(i); - if (!Level.passable[cell] || ((i != path.size()-1) && Dungeon.visible[cell] && Actor.findChar(cell) != null)) { + if (!Level.passable[cell] || (Dungeon.visible[cell] && Actor.findChar(cell) != null)) { newPath = true; break; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 9cd7d8bb4..0de6158db 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -50,6 +50,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.utils.Bundle; +import com.watabou.utils.GameMath; import com.watabou.utils.Random; import java.util.HashSet; @@ -350,10 +351,11 @@ public abstract class Mob extends Char { if (!newPath) { - //checks the next 4 cells in the path for validity - for (int i = 0; i < Math.min(path.size(), 4); i++) { + //looks ahead for path validity, up to length-1 or 4, but always at least 1. + int lookAhead = (int)GameMath.gate(1, path.size()-1, 4); + for (int i = 0; i < lookAhead; i++) { int cell = path.get(i); - if (!Level.passable[cell] || ((i != path.size() - 1) && Dungeon.visible[cell] && Actor.findChar(cell) != null)) { + if (!Level.passable[cell] || ( Dungeon.visible[cell] && Actor.findChar(cell) != null)) { newPath = true; break; }