mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-06 08:57:45 +07:00
Better turns for units pathfinding near blocks
This commit is contained in:
parent
2b12800123
commit
d8535c4d03
@ -257,6 +257,10 @@ public class ControlPathfinder{
|
|||||||
float dst = unit.dst2(tile);
|
float dst = unit.dst2(tile);
|
||||||
//TODO maybe put this on a timer since raycasts can be expensive?
|
//TODO maybe put this on a timer since raycasts can be expensive?
|
||||||
if(dst < minDst && !permissiveRaycast(team, costType, tileX, tileY, tile.x, tile.y)){
|
if(dst < minDst && !permissiveRaycast(team, costType, tileX, tileY, tile.x, tile.y)){
|
||||||
|
if(avoid(req.team, req.cost, items[i + 1])){
|
||||||
|
range = 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
req.pathIndex = Math.max(dst <= range * range ? i + 1 : i, req.pathIndex);
|
req.pathIndex = Math.max(dst <= range * range ? i + 1 : i, req.pathIndex);
|
||||||
minDst = Math.min(dst, minDst);
|
minDst = Math.min(dst, minDst);
|
||||||
}
|
}
|
||||||
@ -290,6 +294,10 @@ public class ControlPathfinder{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(avoid(req.team, req.cost, items[req.rayPathIndex])){
|
||||||
|
range = 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
if(unit.within(tile, range)){
|
if(unit.within(tile, range)){
|
||||||
req.pathIndex = req.rayPathIndex = Math.max(req.pathIndex, req.rayPathIndex + 1);
|
req.pathIndex = req.rayPathIndex = Math.max(req.pathIndex, req.rayPathIndex + 1);
|
||||||
}
|
}
|
||||||
@ -337,7 +345,7 @@ public class ControlPathfinder{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean raycast(int team, PathCost type, int x1, int y1, int x2, int y2){
|
private static boolean raycast(int team, PathCost type, int x1, int y1, int x2, int y2){
|
||||||
int ww = world.width(), wh = world.height();
|
int ww = wwidth, wh = wheight;
|
||||||
int x = x1, dx = Math.abs(x2 - x), sx = x < x2 ? 1 : -1;
|
int x = x1, dx = Math.abs(x2 - x), sx = x < x2 ? 1 : -1;
|
||||||
int y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1;
|
int y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1;
|
||||||
int e2, err = dx - dy;
|
int e2, err = dx - dy;
|
||||||
@ -375,7 +383,7 @@ public class ControlPathfinder{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean permissiveRaycast(int team, PathCost type, int x1, int y1, int x2, int y2){
|
private static boolean permissiveRaycast(int team, PathCost type, int x1, int y1, int x2, int y2){
|
||||||
int ww = world.width(), wh = world.height();
|
int ww = wwidth, wh = wheight;
|
||||||
int x = x1, dx = Math.abs(x2 - x), sx = x < x2 ? 1 : -1;
|
int x = x1, dx = Math.abs(x2 - x), sx = x < x2 ? 1 : -1;
|
||||||
int y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1;
|
int y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1;
|
||||||
int err = dx - dy;
|
int err = dx - dy;
|
||||||
|
Loading…
Reference in New Issue
Block a user