From d8535c4d03071c6b75d04fb324770e208a8f9ecc Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 24 Sep 2023 22:29:58 -0400 Subject: [PATCH] Better turns for units pathfinding near blocks --- core/src/mindustry/ai/ControlPathfinder.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/ai/ControlPathfinder.java b/core/src/mindustry/ai/ControlPathfinder.java index 2b404e5671..bfa26cda89 100644 --- a/core/src/mindustry/ai/ControlPathfinder.java +++ b/core/src/mindustry/ai/ControlPathfinder.java @@ -257,6 +257,10 @@ public class ControlPathfinder{ float dst = unit.dst2(tile); //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(avoid(req.team, req.cost, items[i + 1])){ + range = 0.5f; + } + req.pathIndex = Math.max(dst <= range * range ? i + 1 : i, req.pathIndex); 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)){ 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){ - 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 y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1; 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){ - 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 y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1; int err = dx - dy;