More misc pathfinding improvements

This commit is contained in:
Anuken 2023-09-25 12:48:55 -04:00
parent 7536bbfeb0
commit 95609a90be
2 changed files with 10 additions and 2 deletions

View File

@ -263,6 +263,8 @@ public class ControlPathfinder{
req.pathIndex = Math.max(dst <= range * range ? i + 1 : i, req.pathIndex);
minDst = Math.min(dst, minDst);
}else if(dst <= 1f){
req.pathIndex = Math.min(Math.max(i + 1, req.pathIndex), len - 1);
}
}

View File

@ -17,7 +17,7 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class CommandAI extends AIController{
protected static final int maxCommandQueueSize = 50, avoidInterval = 5;
protected static final int maxCommandQueueSize = 50, avoidInterval = 10;
protected static final Vec2 vecOut = new Vec2(), vecMovePos = new Vec2();
protected static final boolean[] noFound = {false};
@ -223,14 +223,20 @@ public class CommandAI extends AIController{
ControlPathfinder.isNearObstacle(unit, unit.tileX(), unit.tileY(), u.tileX(), u.tileY()));
}
float maxBlockTime = 60f * 5f;
if(blockingUnit){
timeSpentBlocked += Time.delta;
if(timeSpentBlocked >= maxBlockTime*2f){
timeSpentBlocked = 0f;
}
}else{
timeSpentBlocked = 0f;
}
//if you've spent 3 seconds stuck, something is wrong, move regardless
move = Vars.controlPath.getPathPosition(unit, pathId, vecMovePos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > 60f * 3f);
move = Vars.controlPath.getPathPosition(unit, pathId, vecMovePos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
//we've reached the final point if the returned coordinate is equal to the supplied input
isFinalPoint &= vecMovePos.epsilonEquals(vecOut, 4.1f);