* Add data field for id card microwave behaviour (#28087) * Move replacement chance from ReplacementAccentComponent to ReplacementAccentPrototype (#28049) Move replacement chance to ReplacementAccentPrototype * Resolves Bible summon message being sent to all users (#28104) * Changed PopupEntity overload used to ensure message is only sent to user * Updated uid for PopupEntity call * Updating _popupSystem.PopupEntity call in AttemptSummon * Random book story generator refactor (#28082) * Randomized book overhaul * Fix prototype names * Improved setting paper content * Praise Ratvar * Fix activatable UI popup message spam (#28123) Fixed activatable UI popup message spam * Modify battery assert to avoid floating point errors (#28007) * Update component query benchmarks (#27967) * Add more component query benchmarks. * Rename benchmark * Use non-generic `TryComp()` for metadata & transform (#28133) * sleeper agent appear later into the round and only once (#28160) --------- Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: double_b <40827162+benjamin-burges@users.noreply.github.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: Killerqu00 <47712032+Killerqu00@users.noreply.github.com>
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System.Numerics;
|
|
using Content.Shared.NPC;
|
|
|
|
namespace Content.Server.NPC.Pathfinding;
|
|
|
|
public sealed partial class PathfindingSystem
|
|
{
|
|
public float EuclideanDistance(PathPoly start, PathPoly end)
|
|
{
|
|
var (dx, dy) = GetDiff(start, end);
|
|
return MathF.Sqrt((dx * dx + dy * dy));
|
|
}
|
|
|
|
public float ManhattanDistance(PathPoly start, PathPoly end)
|
|
{
|
|
var (dx, dy) = GetDiff(start, end);
|
|
return dx + dy;
|
|
}
|
|
|
|
public float OctileDistance(PathPoly start, PathPoly end)
|
|
{
|
|
var (dx, dy) = GetDiff(start, end);
|
|
return dx + dy + (1.41f - 2) * Math.Min(dx, dy);
|
|
}
|
|
|
|
private Vector2 GetDiff(PathPoly start, PathPoly end)
|
|
{
|
|
var startPos = start.Box.Center;
|
|
var endPos = end.Box.Center;
|
|
|
|
if (end.GraphUid != start.GraphUid)
|
|
{
|
|
if (!TryComp(start.GraphUid, out TransformComponent? startXform) ||
|
|
!TryComp(end.GraphUid, out TransformComponent? endXform))
|
|
{
|
|
return Vector2.Zero;
|
|
}
|
|
|
|
endPos = startXform.InvWorldMatrix.Transform(endXform.WorldMatrix.Transform(endPos));
|
|
}
|
|
|
|
// TODO: Numerics when we changeover.
|
|
var diff = startPos - endPos;
|
|
var ab = Vector2.Abs(diff);
|
|
return ab;
|
|
}
|
|
}
|