From 95609a90be0e2d7a38c73bc60cde9889a273b425 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 25 Sep 2023 12:48:55 -0400 Subject: [PATCH] More misc pathfinding improvements --- core/src/mindustry/ai/ControlPathfinder.java | 2 ++ core/src/mindustry/ai/types/CommandAI.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/ai/ControlPathfinder.java b/core/src/mindustry/ai/ControlPathfinder.java index 141b68a5f1..cabb297270 100644 --- a/core/src/mindustry/ai/ControlPathfinder.java +++ b/core/src/mindustry/ai/ControlPathfinder.java @@ -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); } } diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index 9f65c61217..be468ebf14 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -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);