Files
tbd-station-14/Content.Server/NPC/Components/NPCSteeringComponent.cs
metalgearsloth 0286b88388 NPC refactor (#10122)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
2022-09-06 00:28:23 +10:00

61 lines
1.7 KiB
C#

using System.Threading;
using Content.Server.CPUJob.JobQueues;
using Robust.Shared.Map;
namespace Content.Server.NPC.Components;
/// <summary>
/// Added to NPCs that are moving.
/// </summary>
[RegisterComponent]
public sealed class NPCSteeringComponent : Component
{
[ViewVariables] public Job<Queue<TileRef>>? Pathfind = null;
[ViewVariables] public CancellationTokenSource? PathfindToken = null;
/// <summary>
/// Current path we're following to our coordinates.
/// </summary>
[ViewVariables] public Queue<TileRef> CurrentPath = new();
/// <summary>
/// End target that we're trying to move to.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] public EntityCoordinates Coordinates;
/// <summary>
/// Target that we're trying to move to. If we have a path then this will be the first node on the path.
/// </summary>
[ViewVariables] public EntityCoordinates CurrentTarget;
/// <summary>
/// How close are we trying to get to the coordinates before being considered in range.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] public float Range = 0.2f;
/// <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.5f;
[ViewVariables] public SteeringStatus Status = SteeringStatus.Moving;
}
public enum SteeringStatus : byte
{
/// <summary>
/// If we can't reach the target (e.g. different map).
/// </summary>
NoPath,
/// <summary>
/// Are we moving towards our target
/// </summary>
Moving,
/// <summary>
/// Are we currently in range of our target.
/// </summary>
InRange,
}