v0.4.2: fixed bugs with mob pathfinding

This commit is contained in:
Evan Debenham 2016-08-31 00:37:28 -04:00
parent 01aad4196c
commit 67f435319f

View File

@ -294,13 +294,25 @@ public abstract class Mob extends Char {
return false; return false;
} }
int step = -1;
if (Dungeon.level.adjacent( pos, target )) {
path = null;
if (Actor.findChar( target ) == null && Level.passable[target]) {
step = target;
}
} else {
boolean newPath = false; boolean newPath = false;
if (path == null || path.isEmpty()) if (path == null || path.isEmpty())
newPath = true; newPath = true;
else if (path.getLast() != target) { else if (path.getLast() != target) {
//if the new target is adjacent to the end of the path, adjust for that //if the new target is adjacent to the end of the path, adjust for that
//rather than scrapping the whole path //rather than scrapping the whole path
if (Dungeon.level.adjacent(target, path.getLast())){ if (Dungeon.level.adjacent(target, path.getLast())) {
int last = path.removeLast(); int last = path.removeLast();
if (path.isEmpty()) { if (path.isEmpty()) {
@ -314,12 +326,12 @@ public abstract class Mob extends Char {
path.add(target); path.add(target);
} }
} else if (!path.isEmpty()){ } else if (!path.isEmpty()) {
//if the new target is simply 1 earlier in the path shorten the path //if the new target is simply 1 earlier in the path shorten the path
if (path.getLast() == target) { if (path.getLast() == target) {
//if the new target is closer/same, need to modify end of path //if the new target is closer/same, need to modify end of path
} else if (Dungeon.level.adjacent(target, path.getLast())){ } else if (Dungeon.level.adjacent(target, path.getLast())) {
path.add(target); path.add(target);
//if the new target is further away, need to extend the path //if the new target is further away, need to extend the path
@ -335,11 +347,12 @@ public abstract class Mob extends Char {
} }
if (!newPath){
if (!newPath) {
//checks the next 4 cells in the path for validity //checks the next 4 cells in the path for validity
for (int i = 0; i < Math.min(path.size(), 4); i++){ for (int i = 0; i < Math.min(path.size(), 4); 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] || ((i != path.size() - 1) && Dungeon.visible[cell] && Actor.findChar(cell) != null)) {
newPath = true; newPath = true;
break; break;
} }
@ -355,7 +368,8 @@ public abstract class Mob extends Char {
if (path == null) if (path == null)
return false; return false;
int step = path.removeFirst(); step = path.removeFirst();
}
if (step != -1) { if (step != -1) {
move( step ); move( step );
return true; return true;