mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-05 21:10:53 +07:00
Unit avoiding re-enabled
This commit is contained in:
parent
5e22b093e6
commit
1ac1263aa4
@ -1021,13 +1021,17 @@ public class HierarchyPathFinder implements Runnable{
|
||||
|
||||
PathRequest request = unitRequests.get(unit);
|
||||
|
||||
unit.hitboxTile(Tmp.r3);
|
||||
//tile rect size has tile size factored in, since the ray cannot have thickness
|
||||
float tileRectSize = tilesize + Tmp.r3.height;
|
||||
|
||||
int lastRaycastTile = request == null || world.tileChanges != request.lastWorldUpdate ? -1 : request.lastRaycastTile;
|
||||
boolean raycastResult = request != null && request.lastRaycastResult;
|
||||
|
||||
//cache raycast results to run every time the world updates, and every tile the unit crosses
|
||||
if(lastRaycastTile != packedPos){
|
||||
//near the destination, standard raycasting tends to break down, so use the more permissive 'near' variant that doesn't take into account edges of walls
|
||||
raycastResult = unit.within(destination, tilesize * 2.5f) ? !raycastNear(team, cost, tileX, tileY, actualDestX, actualDestY) : !raycast(team, cost, tileX, tileY, actualDestX, actualDestY);
|
||||
raycastResult = unit.within(destination, tilesize * 2.5f) ? !raycastRect(unit.x, unit.y, destination.x, destination.y, team, cost, tileX, tileY, actualDestX, actualDestY, tileRectSize) : !raycast(team, cost, tileX, tileY, actualDestX, actualDestY);
|
||||
|
||||
if(request != null){
|
||||
request.lastRaycastTile = packedPos;
|
||||
@ -1065,9 +1069,6 @@ public class HierarchyPathFinder implements Runnable{
|
||||
int maxIterations = 30; //TODO higher/lower number? is this still too slow?
|
||||
int i = 0;
|
||||
boolean recalc = false;
|
||||
unit.hitboxTile(Tmp.r3);
|
||||
//tile rect size has tile size factored in, since the ray cannot have thickness
|
||||
float tileRectSize = tilesize + Tmp.r3.height;
|
||||
|
||||
//TODO last pos can change if the flowfield changes.
|
||||
if(initialTileOn.pos() != request.lastTile || request.lastTargetTile == null){
|
||||
@ -1079,8 +1080,8 @@ public class HierarchyPathFinder implements Runnable{
|
||||
|
||||
Tile current = null;
|
||||
int minCost = 0;
|
||||
for(int dir = 0; dir < 8; dir ++){
|
||||
Point2 point = Geometry.d8[dir];
|
||||
for(int dir = 0; dir < 4; dir ++){
|
||||
Point2 point = Geometry.d4[dir];
|
||||
int dx = tileOn.x + point.x, dy = tileOn.y + point.y;
|
||||
|
||||
Tile other = world.tile(dx, dy);
|
||||
@ -1094,13 +1095,7 @@ public class HierarchyPathFinder implements Runnable{
|
||||
anyNearSolid = true;
|
||||
}
|
||||
|
||||
if((value == 0 || otherCost < value) && otherCost != impassable && (otherCost != 0 || packed == destPos) && (current == null || otherCost < minCost) && passable(unit.team.id, cost, packed) &&
|
||||
//diagonal corner trap
|
||||
!(
|
||||
(!passable(team, cost, world.packArray(tileOn.x + point.x, tileOn.y)) ||
|
||||
(!passable(team, cost, world.packArray(tileOn.x, tileOn.y + point.y))))
|
||||
)
|
||||
){
|
||||
if((value == 0 || otherCost < value) && otherCost != impassable && (otherCost != 0 || packed == destPos) && (current == null || otherCost < minCost) && passable(unit.team.id, cost, packed)){
|
||||
current = other;
|
||||
minCost = otherCost;
|
||||
}
|
||||
|
@ -223,8 +223,8 @@ public class CommandAI extends AIController{
|
||||
}
|
||||
|
||||
if(unit.isGrounded() && stance != UnitStance.ram){
|
||||
//TODO: blocking is disabled, doesn't work well
|
||||
if(timer.get(timerTarget3, avoidInterval) && false){
|
||||
//TODO: blocking enable or disable?
|
||||
if(timer.get(timerTarget3, avoidInterval)){
|
||||
Vec2 dstPos = Tmp.v1.trns(unit.rotation, unit.hitSize/2f);
|
||||
float max = unit.hitSize/2f;
|
||||
float radius = Math.max(7f, max);
|
||||
@ -251,7 +251,6 @@ public class CommandAI extends AIController{
|
||||
timeSpentBlocked = 0f;
|
||||
}
|
||||
|
||||
//if you've spent 3 seconds stuck, something is wrong, move regardless
|
||||
move = hpath.getPathPosition(unit, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
|
||||
//rare case where unit must be perfectly aligned (happens with 1-tile gaps)
|
||||
alwaysArrive = vecOut.epsilonEquals(unit.tileX() * tilesize, unit.tileY() * tilesize);
|
||||
|
Loading…
Reference in New Issue
Block a user