Unit avoiding re-enabled
This commit is contained in:
@@ -1021,13 +1021,17 @@ public class HierarchyPathFinder implements Runnable{
|
|||||||
|
|
||||||
PathRequest request = unitRequests.get(unit);
|
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;
|
int lastRaycastTile = request == null || world.tileChanges != request.lastWorldUpdate ? -1 : request.lastRaycastTile;
|
||||||
boolean raycastResult = request != null && request.lastRaycastResult;
|
boolean raycastResult = request != null && request.lastRaycastResult;
|
||||||
|
|
||||||
//cache raycast results to run every time the world updates, and every tile the unit crosses
|
//cache raycast results to run every time the world updates, and every tile the unit crosses
|
||||||
if(lastRaycastTile != packedPos){
|
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
|
//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){
|
if(request != null){
|
||||||
request.lastRaycastTile = packedPos;
|
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 maxIterations = 30; //TODO higher/lower number? is this still too slow?
|
||||||
int i = 0;
|
int i = 0;
|
||||||
boolean recalc = false;
|
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.
|
//TODO last pos can change if the flowfield changes.
|
||||||
if(initialTileOn.pos() != request.lastTile || request.lastTargetTile == null){
|
if(initialTileOn.pos() != request.lastTile || request.lastTargetTile == null){
|
||||||
@@ -1079,8 +1080,8 @@ public class HierarchyPathFinder implements Runnable{
|
|||||||
|
|
||||||
Tile current = null;
|
Tile current = null;
|
||||||
int minCost = 0;
|
int minCost = 0;
|
||||||
for(int dir = 0; dir < 8; dir ++){
|
for(int dir = 0; dir < 4; dir ++){
|
||||||
Point2 point = Geometry.d8[dir];
|
Point2 point = Geometry.d4[dir];
|
||||||
int dx = tileOn.x + point.x, dy = tileOn.y + point.y;
|
int dx = tileOn.x + point.x, dy = tileOn.y + point.y;
|
||||||
|
|
||||||
Tile other = world.tile(dx, dy);
|
Tile other = world.tile(dx, dy);
|
||||||
@@ -1094,13 +1095,7 @@ public class HierarchyPathFinder implements Runnable{
|
|||||||
anyNearSolid = true;
|
anyNearSolid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((value == 0 || otherCost < value) && otherCost != impassable && (otherCost != 0 || packed == destPos) && (current == null || otherCost < minCost) && passable(unit.team.id, cost, packed) &&
|
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))))
|
|
||||||
)
|
|
||||||
){
|
|
||||||
current = other;
|
current = other;
|
||||||
minCost = otherCost;
|
minCost = otherCost;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,8 +223,8 @@ public class CommandAI extends AIController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(unit.isGrounded() && stance != UnitStance.ram){
|
if(unit.isGrounded() && stance != UnitStance.ram){
|
||||||
//TODO: blocking is disabled, doesn't work well
|
//TODO: blocking enable or disable?
|
||||||
if(timer.get(timerTarget3, avoidInterval) && false){
|
if(timer.get(timerTarget3, avoidInterval)){
|
||||||
Vec2 dstPos = Tmp.v1.trns(unit.rotation, unit.hitSize/2f);
|
Vec2 dstPos = Tmp.v1.trns(unit.rotation, unit.hitSize/2f);
|
||||||
float max = unit.hitSize/2f;
|
float max = unit.hitSize/2f;
|
||||||
float radius = Math.max(7f, max);
|
float radius = Math.max(7f, max);
|
||||||
@@ -251,7 +251,6 @@ public class CommandAI extends AIController{
|
|||||||
timeSpentBlocked = 0f;
|
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);
|
move = hpath.getPathPosition(unit, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
|
||||||
//rare case where unit must be perfectly aligned (happens with 1-tile gaps)
|
//rare case where unit must be perfectly aligned (happens with 1-tile gaps)
|
||||||
alwaysArrive = vecOut.epsilonEquals(unit.tileX() * tilesize, unit.tileY() * tilesize);
|
alwaysArrive = vecOut.epsilonEquals(unit.tileX() * tilesize, unit.tileY() * tilesize);
|
||||||
|
|||||||
Reference in New Issue
Block a user