From 2785a51916aef6e313ec5ca0e33968cec8ef0100 Mon Sep 17 00:00:00 2001
From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Sun, 22 May 2022 12:51:05 +1000
Subject: [PATCH] Don't pathfind on deleted grid (#8300)
---
Content.Server/AI/Pathfinding/Accessible/BFSPathfinder.cs | 2 +-
.../AI/Pathfinding/Pathfinders/AStarPathfindingJob.cs | 8 +++++++-
Content.Server/AI/Pathfinding/PathfindingSystem.cs | 2 +-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/Content.Server/AI/Pathfinding/Accessible/BFSPathfinder.cs b/Content.Server/AI/Pathfinding/Accessible/BFSPathfinder.cs
index a2fc77ef57..b7a8345aad 100644
--- a/Content.Server/AI/Pathfinding/Accessible/BFSPathfinder.cs
+++ b/Content.Server/AI/Pathfinding/Accessible/BFSPathfinder.cs
@@ -11,7 +11,7 @@ namespace Content.Server.AI.Pathfinding.Accessible
///
/// Gets all of the tiles in range that can we access
///
- /// 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
///
///
diff --git a/Content.Server/AI/Pathfinding/Pathfinders/AStarPathfindingJob.cs b/Content.Server/AI/Pathfinding/Pathfinders/AStarPathfindingJob.cs
index 59679fb8fd..6107c0c4ec 100644
--- a/Content.Server/AI/Pathfinding/Pathfinders/AStarPathfindingJob.cs
+++ b/Content.Server/AI/Pathfinding/Pathfinders/AStarPathfindingJob.cs
@@ -16,17 +16,20 @@ namespace Content.Server.AI.Pathfinding.Pathfinders
private readonly PathfindingNode? _startNode;
private PathfindingNode? _endNode;
private readonly PathfindingArgs _pathfindingArgs;
+ private readonly IEntityManager _entityManager;
public AStarPathfindingJob(
double maxTime,
PathfindingNode startNode,
PathfindingNode endNode,
PathfindingArgs pathfindingArgs,
- CancellationToken cancellationToken) : base(maxTime, cancellationToken)
+ CancellationToken cancellationToken,
+ IEntityManager entityManager) : base(maxTime, cancellationToken)
{
_startNode = startNode;
_endNode = endNode;
_pathfindingArgs = pathfindingArgs;
+ _entityManager = entityManager;
}
protected override async Task?> Process()
@@ -44,6 +47,9 @@ namespace Content.Server.AI.Pathfinding.Pathfinders
return null;
}
+ if (_entityManager.Deleted(_pathfindingArgs.Start.GridIndex))
+ return null;
+
var frontier = new PriorityQueue>(new PathfindingComparer());
var costSoFar = new Dictionary();
var cameFrom = new Dictionary();
diff --git a/Content.Server/AI/Pathfinding/PathfindingSystem.cs b/Content.Server/AI/Pathfinding/PathfindingSystem.cs
index e02066638f..37bd2438ff 100644
--- a/Content.Server/AI/Pathfinding/PathfindingSystem.cs
+++ b/Content.Server/AI/Pathfinding/PathfindingSystem.cs
@@ -36,7 +36,7 @@ namespace Content.Server.AI.Pathfinding
{
var startNode = GetNode(pathfindingArgs.Start);
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);
return job;