Don't pathfind on deleted grid (#8300)

This commit is contained in:
metalgearsloth
2022-05-22 12:51:05 +10:00
committed by GitHub
parent b4d5f5f091
commit 2785a51916
3 changed files with 9 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ namespace Content.Server.AI.Pathfinding.Accessible
/// <summary> /// <summary>
/// Gets all of the tiles in range that can we access /// Gets all of the tiles in range that can we access
/// </summary> /// </summary>
/// If you want Dikstra then add distances. /// If you want Dijkstra then add distances.
/// Doesn't use the JobQueue as it will generally be encapsulated by other jobs /// Doesn't use the JobQueue as it will generally be encapsulated by other jobs
/// <param name="pathfindingArgs"></param> /// <param name="pathfindingArgs"></param>
/// <param name="range"></param> /// <param name="range"></param>

View File

@@ -16,17 +16,20 @@ namespace Content.Server.AI.Pathfinding.Pathfinders
private readonly PathfindingNode? _startNode; private readonly PathfindingNode? _startNode;
private PathfindingNode? _endNode; private PathfindingNode? _endNode;
private readonly PathfindingArgs _pathfindingArgs; private readonly PathfindingArgs _pathfindingArgs;
private readonly IEntityManager _entityManager;
public AStarPathfindingJob( public AStarPathfindingJob(
double maxTime, double maxTime,
PathfindingNode startNode, PathfindingNode startNode,
PathfindingNode endNode, PathfindingNode endNode,
PathfindingArgs pathfindingArgs, PathfindingArgs pathfindingArgs,
CancellationToken cancellationToken) : base(maxTime, cancellationToken) CancellationToken cancellationToken,
IEntityManager entityManager) : base(maxTime, cancellationToken)
{ {
_startNode = startNode; _startNode = startNode;
_endNode = endNode; _endNode = endNode;
_pathfindingArgs = pathfindingArgs; _pathfindingArgs = pathfindingArgs;
_entityManager = entityManager;
} }
protected override async Task<Queue<TileRef>?> Process() protected override async Task<Queue<TileRef>?> Process()
@@ -44,6 +47,9 @@ namespace Content.Server.AI.Pathfinding.Pathfinders
return null; return null;
} }
if (_entityManager.Deleted(_pathfindingArgs.Start.GridIndex))
return null;
var frontier = new PriorityQueue<ValueTuple<float, PathfindingNode>>(new PathfindingComparer()); var frontier = new PriorityQueue<ValueTuple<float, PathfindingNode>>(new PathfindingComparer());
var costSoFar = new Dictionary<PathfindingNode, float>(); var costSoFar = new Dictionary<PathfindingNode, float>();
var cameFrom = new Dictionary<PathfindingNode, PathfindingNode>(); var cameFrom = new Dictionary<PathfindingNode, PathfindingNode>();

View File

@@ -36,7 +36,7 @@ namespace Content.Server.AI.Pathfinding
{ {
var startNode = GetNode(pathfindingArgs.Start); var startNode = GetNode(pathfindingArgs.Start);
var endNode = GetNode(pathfindingArgs.End); var endNode = GetNode(pathfindingArgs.End);
var job = new AStarPathfindingJob(0.003, startNode, endNode, pathfindingArgs, cancellationToken); var job = new AStarPathfindingJob(0.003, startNode, endNode, pathfindingArgs, cancellationToken, EntityManager);
_pathfindingQueue.EnqueueJob(job); _pathfindingQueue.EnqueueJob(job);
return job; return job;