Fix some docking configs (#17012)

This commit is contained in:
metalgearsloth
2023-06-01 10:48:44 +10:00
committed by GitHub
parent 9931a6b2f2
commit d09026c89c
3 changed files with 23 additions and 15 deletions

View File

@@ -18,6 +18,11 @@ public sealed class DockingConfig
/// </summary> /// </summary>
public EntityUid TargetGrid; public EntityUid TargetGrid;
/// <summary>
/// This is used for debugging.
/// </summary>
public Box2 Area;
public EntityCoordinates Coordinates; public EntityCoordinates Coordinates;
public Angle Angle; public Angle Angle;
} }

View File

@@ -15,6 +15,8 @@ public sealed partial class DockingSystem
* Handles the shuttle side of FTL docking. * Handles the shuttle side of FTL docking.
*/ */
private const int DockRoundingDigits = 2;
public Angle GetAngle(EntityUid uid, TransformComponent xform, EntityUid targetUid, TransformComponent targetXform, EntityQuery<TransformComponent> xformQuery) public Angle GetAngle(EntityUid uid, TransformComponent xform, EntityUid targetUid, TransformComponent targetXform, EntityQuery<TransformComponent> xformQuery)
{ {
var (shuttlePos, shuttleRot) = _transform.GetWorldPositionRotation(xform, xformQuery); var (shuttlePos, shuttleRot) = _transform.GetWorldPositionRotation(xform, xformQuery);
@@ -44,10 +46,10 @@ public sealed partial class DockingSystem
FixturesComponent shuttleFixtures, FixturesComponent shuttleFixtures,
MapGridComponent grid, MapGridComponent grid,
out Matrix3 matty, out Matrix3 matty,
[NotNullWhen(true)] out Box2? shuttleDockedAABB, out Box2 shuttleDockedAABB,
out Angle gridRotation) out Angle gridRotation)
{ {
shuttleDockedAABB = null; shuttleDockedAABB = Box2.UnitCentered;
gridRotation = Angle.Zero; gridRotation = Angle.Zero;
matty = Matrix3.Identity; matty = Matrix3.Identity;
@@ -132,7 +134,6 @@ public sealed partial class DockingSystem
var targetGridAngle = _transform.GetWorldRotation(targetGridXform).Reduced(); var targetGridAngle = _transform.GetWorldRotation(targetGridXform).Reduced();
var shuttleFixturesComp = Comp<FixturesComponent>(shuttleUid); var shuttleFixturesComp = Comp<FixturesComponent>(shuttleUid);
var shuttleAABB = Comp<MapGridComponent>(shuttleUid).LocalAABB; var shuttleAABB = Comp<MapGridComponent>(shuttleUid).LocalAABB;
var foundDocks = new HashSet<EntityUid>();
var validDockConfigs = new List<DockingConfig>(); var validDockConfigs = new List<DockingConfig>();
if (shuttleDocks.Count > 0) 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 // We'll try all combinations of shuttle docks and see which one is most suitable
foreach (var (dockUid, shuttleDock) in shuttleDocks) foreach (var (dockUid, shuttleDock) in shuttleDocks)
{ {
if (foundDocks.Contains(dockUid))
continue;
var shuttleDockXform = xformQuery.GetComponent(dockUid); var shuttleDockXform = xformQuery.GetComponent(dockUid);
foreach (var (gridDockUid, gridDock) in gridDocks) foreach (var (gridDockUid, gridDock) in gridDocks)
@@ -186,9 +184,11 @@ public sealed partial class DockingSystem
(dockUid, gridDockUid, shuttleDock, gridDock), (dockUid, gridDockUid, shuttleDock, gridDock),
}; };
dockedAABB = dockedAABB.Rounded(DockRoundingDigits);
foreach (var (otherUid, other) in shuttleDocks) foreach (var (otherUid, other) in shuttleDocks)
{ {
if (other == shuttleDock || foundDocks.Contains(otherUid)) if (other == shuttleDock)
continue; continue;
foreach (var (otherGridUid, otherGrid) in gridDocks) foreach (var (otherGridUid, otherGrid) in gridDocks)
@@ -206,8 +206,15 @@ public sealed partial class DockingSystem
shuttleFixturesComp, targetGridGrid, shuttleFixturesComp, targetGridGrid,
out _, out _,
out var otherdockedAABB, out var otherdockedAABB,
out var otherTargetAngle) || out var otherTargetAngle))
!targetAngle.Equals(otherTargetAngle) || {
continue;
}
otherdockedAABB = otherdockedAABB.Rounded(DockRoundingDigits);
// Different setup.
if (!targetAngle.Equals(otherTargetAngle) ||
!dockedAABB.Equals(otherdockedAABB)) !dockedAABB.Equals(otherdockedAABB))
{ {
continue; continue;
@@ -221,13 +228,9 @@ public sealed partial class DockingSystem
{ {
Docks = dockedPorts, Docks = dockedPorts,
Coordinates = spawnPosition, Coordinates = spawnPosition,
Area = dockedAABB,
Angle = targetAngle, Angle = targetAngle,
}); });
foreach (var dock in dockedPorts)
{
foundDocks.Add(dock.DockAUid);
}
} }
} }
} }

View File

@@ -162,7 +162,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
RaiseNetworkEvent(new EmergencyShuttlePositionMessage() RaiseNetworkEvent(new EmergencyShuttlePositionMessage()
{ {
StationUid = targetGrid, StationUid = targetGrid,
Position = Comp<MapGridComponent>(stationShuttle.EmergencyShuttle.Value).LocalAABB.Translated(config.Coordinates.Position) Position = config.Area,
}); });
} }