From d09026c89c17ef520db0ad227ec5d2113933b9be Mon Sep 17 00:00:00 2001
From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Thu, 1 Jun 2023 10:48:44 +1000
Subject: [PATCH] Fix some docking configs (#17012)
---
Content.Server/Shuttles/DockingConfig.cs | 5 +++
.../Shuttles/Systems/DockingSystem.Shuttle.cs | 31 ++++++++++---------
.../Systems/EmergencyShuttleSystem.cs | 2 +-
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/Content.Server/Shuttles/DockingConfig.cs b/Content.Server/Shuttles/DockingConfig.cs
index c89250cdce..58d2878514 100644
--- a/Content.Server/Shuttles/DockingConfig.cs
+++ b/Content.Server/Shuttles/DockingConfig.cs
@@ -18,6 +18,11 @@ public sealed class DockingConfig
///
public EntityUid TargetGrid;
+ ///
+ /// This is used for debugging.
+ ///
+ public Box2 Area;
+
public EntityCoordinates Coordinates;
public Angle Angle;
}
diff --git a/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs b/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs
index b11a084615..d75e65143f 100644
--- a/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs
+++ b/Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs
@@ -15,6 +15,8 @@ public sealed partial class DockingSystem
* Handles the shuttle side of FTL docking.
*/
+ private const int DockRoundingDigits = 2;
+
public Angle GetAngle(EntityUid uid, TransformComponent xform, EntityUid targetUid, TransformComponent targetXform, EntityQuery xformQuery)
{
var (shuttlePos, shuttleRot) = _transform.GetWorldPositionRotation(xform, xformQuery);
@@ -44,10 +46,10 @@ public sealed partial class DockingSystem
FixturesComponent shuttleFixtures,
MapGridComponent grid,
out Matrix3 matty,
- [NotNullWhen(true)] out Box2? shuttleDockedAABB,
+ out Box2 shuttleDockedAABB,
out Angle gridRotation)
{
- shuttleDockedAABB = null;
+ shuttleDockedAABB = Box2.UnitCentered;
gridRotation = Angle.Zero;
matty = Matrix3.Identity;
@@ -132,7 +134,6 @@ public sealed partial class DockingSystem
var targetGridAngle = _transform.GetWorldRotation(targetGridXform).Reduced();
var shuttleFixturesComp = Comp(shuttleUid);
var shuttleAABB = Comp(shuttleUid).LocalAABB;
- var foundDocks = new HashSet();
var validDockConfigs = new List();
if (shuttleDocks.Count > 0)
@@ -140,9 +141,6 @@ public sealed partial class DockingSystem
// We'll try all combinations of shuttle docks and see which one is most suitable
foreach (var (dockUid, shuttleDock) in shuttleDocks)
{
- if (foundDocks.Contains(dockUid))
- continue;
-
var shuttleDockXform = xformQuery.GetComponent(dockUid);
foreach (var (gridDockUid, gridDock) in gridDocks)
@@ -186,9 +184,11 @@ public sealed partial class DockingSystem
(dockUid, gridDockUid, shuttleDock, gridDock),
};
+ dockedAABB = dockedAABB.Rounded(DockRoundingDigits);
+
foreach (var (otherUid, other) in shuttleDocks)
{
- if (other == shuttleDock || foundDocks.Contains(otherUid))
+ if (other == shuttleDock)
continue;
foreach (var (otherGridUid, otherGrid) in gridDocks)
@@ -206,8 +206,15 @@ public sealed partial class DockingSystem
shuttleFixturesComp, targetGridGrid,
out _,
out var otherdockedAABB,
- out var otherTargetAngle) ||
- !targetAngle.Equals(otherTargetAngle) ||
+ out var otherTargetAngle))
+ {
+ continue;
+ }
+
+ otherdockedAABB = otherdockedAABB.Rounded(DockRoundingDigits);
+
+ // Different setup.
+ if (!targetAngle.Equals(otherTargetAngle) ||
!dockedAABB.Equals(otherdockedAABB))
{
continue;
@@ -221,13 +228,9 @@ public sealed partial class DockingSystem
{
Docks = dockedPorts,
Coordinates = spawnPosition,
+ Area = dockedAABB,
Angle = targetAngle,
});
-
- foreach (var dock in dockedPorts)
- {
- foundDocks.Add(dock.DockAUid);
- }
}
}
}
diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs
index 6b100cf508..adc97dd9fb 100644
--- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs
+++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs
@@ -162,7 +162,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
RaiseNetworkEvent(new EmergencyShuttlePositionMessage()
{
StationUid = targetGrid,
- Position = Comp(stationShuttle.EmergencyShuttle.Value).LocalAABB.Translated(config.Coordinates.Position)
+ Position = config.Area,
});
}