v0.9.1: fixed rare errors resulting from v0.9.0 AI changes

This commit is contained in:
Evan Debenham 2020-11-03 15:25:01 -05:00
parent 61372291ca
commit 22036628d3

View File

@ -879,6 +879,9 @@ public abstract class Mob extends Char {
public static final String TAG = "HUNTING";
//prevents rare infinite loop cases
private boolean recursing = false;
@Override
public boolean act( boolean enemyInFOV, boolean justAlerted ) {
enemySeen = enemyInFOV;
@ -906,11 +909,16 @@ public abstract class Mob extends Char {
} else {
//if moving towards an enemy isn't possible, try to switch targets to another enemy that is closer
Char newEnemy = chooseEnemy();
if (newEnemy != null && enemy != newEnemy){
enemy = newEnemy;
spend( TICK );
return true;
//unless we have already done that and still can't move toward them, then move on.
if (!recursing) {
Char newEnemy = chooseEnemy();
if (newEnemy != null && enemy != newEnemy) {
enemy = newEnemy;
recursing = true;
boolean result = act(enemyInFOV, justAlerted);
recursing = false;
return result;
}
}
spend( TICK );