Pathfinder tweaks (#12848)

This commit is contained in:
metalgearsloth
2022-12-07 10:33:44 +11:00
committed by GitHub
parent 8f641137e8
commit dd384c55a0
7 changed files with 18 additions and 17 deletions

View File

@@ -36,7 +36,7 @@ public sealed class NPCSteeringComponent : Component
/// <summary>
/// How far does the last node in the path need to be before considering re-pathfinding.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] public float RepathRange = 1.2f;
[ViewVariables(VVAccess.ReadWrite)] public float RepathRange = 1.5f;
public const int FailedPathLimit = 3;

View File

@@ -85,7 +85,6 @@ public sealed class PickAccessibleComponentOperator : HTNOperator
{
var path = await _pathfinding.GetRandomPath(
owner,
1.4f,
maxRange,
cancelToken,
flags: _pathfinding.GetFlags(blackboard));

View File

@@ -45,7 +45,6 @@ public sealed class PickAccessibleOperator : HTNOperator
var path = await _pathfinding.GetRandomPath(
owner,
1.4f,
maxRange,
cancelToken,
flags: _pathfinding.GetFlags(blackboard));

View File

@@ -33,17 +33,15 @@ public abstract class PathRequest
#region Data
public readonly PathFlags Flags;
public readonly float Range;
public readonly int CollisionLayer;
public readonly int CollisionMask;
#endregion
public PathRequest(EntityCoordinates start, PathFlags flags, float range, int layer, int mask, CancellationToken cancelToken)
public PathRequest(EntityCoordinates start, PathFlags flags, int layer, int mask, CancellationToken cancelToken)
{
Start = start;
Flags = flags;
Range = range;
CollisionLayer = layer;
CollisionMask = mask;
Tcs = new TaskCompletionSource<PathResult>(cancelToken);
@@ -54,15 +52,21 @@ public sealed class AStarPathRequest : PathRequest
{
public EntityCoordinates End;
/// <summary>
/// How close we need to be to the end node to be considered as arrived.
/// </summary>
public float Distance;
public AStarPathRequest(
EntityCoordinates start,
EntityCoordinates end,
PathFlags flags,
float range,
float distance,
int layer,
int mask,
CancellationToken cancelToken) : base(start, flags, range, layer, mask, cancelToken)
CancellationToken cancelToken) : base(start, flags, layer, mask, cancelToken)
{
Distance = distance;
End = end;
}
}
@@ -84,10 +88,9 @@ public sealed class BFSPathRequest : PathRequest
int expansionLimit,
EntityCoordinates start,
PathFlags flags,
float range,
int layer,
int mask,
CancellationToken cancelToken) : base(start, flags, range, layer, mask, cancelToken)
CancellationToken cancelToken) : base(start, flags, layer, mask, cancelToken)
{
ExpansionRange = expansionRange;
ExpansionLimit = expansionLimit;

View File

@@ -82,10 +82,11 @@ public sealed partial class PathfindingSystem
// Actual pathfinding here
(_, currentNode) = request.Frontier.Take();
// TODO: Need this at some stage but need to fix some steering bugs first before it's useable.
if (currentNode.Equals(endNode))// ||
//(endNode.GraphUid == currentNode.GraphUid &&
//(endNode.Box.Center - currentNode.Box.Center).Length < request.Range))
// If we're inside the required distance OR we're at the end node.
if ((request.Distance > 0f &&
currentNode.Coordinates.TryDistance(EntityManager, request.End, out var distance) &&
distance <= request.Distance) ||
currentNode.Equals(endNode))
{
arrived = true;
break;

View File

@@ -11,7 +11,7 @@ public sealed partial class PathfindingSystem
/// <summary>
/// Maximum amount of nodes we're allowed to expand.
/// </summary>
private const int NodeLimit = 200;
private const int NodeLimit = 512;
private sealed class PathComparer : IComparer<ValueTuple<float, PathPoly>>
{

View File

@@ -228,7 +228,6 @@ namespace Content.Server.NPC.Pathfinding
public async Task<PathResultEvent> GetRandomPath(
EntityUid entity,
float range,
float maxRange,
CancellationToken cancelToken,
int limit = 40,
@@ -246,7 +245,7 @@ namespace Content.Server.NPC.Pathfinding
mask = body.CollisionMask;
}
var request = new BFSPathRequest(maxRange, limit, start.Coordinates, flags, range, layer, mask, cancelToken);
var request = new BFSPathRequest(maxRange, limit, start.Coordinates, flags, layer, mask, cancelToken);
var path = await GetPath(request);
if (path.Result != PathResult.Path)