Fix nearest beacon messages reporting the opposite direction (#28869)

* Fix nearest beacon messages reporting the opposite direction

* Lets document that method, shall we?
This commit is contained in:
Tayrtahn
2024-07-05 20:26:23 +02:00
committed by null
parent 1c1d1e074a
commit bee3ac504c
+12 -2
View File
@@ -431,6 +431,10 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
return beacon != null;
}
/// <summary>
/// Returns a string describing the rough distance and direction
/// to the position of <paramref name="ent"/> from the nearest beacon.
/// </summary>
[PublicAPI]
public string GetNearestBeaconString(Entity<TransformComponent?> ent)
{
@@ -440,6 +444,11 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
return GetNearestBeaconString(_transformSystem.GetMapCoordinates(ent, ent.Comp));
}
/// <summary>
/// Returns a string describing the rough distance and direction
/// to <paramref name="coordinates"/> from the nearest beacon.
/// </summary>
public string GetNearestBeaconString(MapCoordinates coordinates)
{
if (!TryGetNearestBeacon(coordinates, out var beacon, out var pos))
@@ -451,10 +460,11 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
// get the angle between the two positions, adjusted for the grid rotation so that
// we properly preserve north in relation to the grid.
var dir = (pos.Value.Position - coordinates.Position).ToWorldAngle();
var offset = coordinates.Position - pos.Value.Position;
var dir = offset.ToWorldAngle();
var adjustedDir = (dir - gridOffset).GetDir();
var length = (pos.Value.Position - coordinates.Position).Length();
var length = offset.Length();
if (length < CloseDistance)
{
return Loc.GetString("nav-beacon-pos-format",