v0.4.3: fixed mobs occasionally walking into eachother

This commit is contained in:
Evan Debenham 2016-10-01 22:20:58 -04:00
parent e3b0720de9
commit 035672551e
2 changed files with 10 additions and 6 deletions

View File

@ -110,6 +110,7 @@ import com.watabou.noosa.Camera;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.GameMath;
import com.watabou.utils.PathFinder; import com.watabou.utils.PathFinder;
import com.watabou.utils.Random; import com.watabou.utils.Random;
@ -1050,11 +1051,12 @@ public class Hero extends Char {
else if (path.getLast() != target) else if (path.getLast() != target)
newPath = true; newPath = true;
else { 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 //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); 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; newPath = true;
break; break;
} }

View File

@ -50,6 +50,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.GameMath;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.HashSet; import java.util.HashSet;
@ -350,10 +351,11 @@ public abstract class Mob extends Char {
if (!newPath) { if (!newPath) {
//checks the next 4 cells in the path for validity //looks ahead for path validity, up to length-1 or 4, but always at least 1.
for (int i = 0; i < Math.min(path.size(), 4); i++) { int lookAhead = (int)GameMath.gate(1, path.size()-1, 4);
for (int i = 0; i < lookAhead; i++) {
int cell = path.get(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; newPath = true;
break; break;
} }