From a6a5bfa6973666fd30f8f751b1419225df21d540 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 27 Jun 2022 03:48:49 +1000 Subject: [PATCH] Fix emergency shuttle docking causing grid overlap (#9197) --- .../Systems/ShuttleSystem.EmergencyShuttle.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs index 0d02309dd9..2e20b2f954 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs @@ -104,7 +104,9 @@ public sealed partial class ShuttleSystem var xformQuery = GetEntityQuery(); var targetGridGrid = Comp(targetGrid.Value); var targetGridXform = xformQuery.GetComponent(targetGrid.Value); - var targetGridRotation = targetGridXform.WorldRotation.ToVec(); + var targetGridMatrix = targetGridXform.WorldMatrix; + var targetGridAngle = targetGridXform.WorldRotation.Reduced(); + var targetGridRotation = targetGridAngle.ToVec(); var shuttleDocks = GetDocks(dataComponent.EmergencyShuttle.Value); var shuttleAABB = Comp(dataComponent.EmergencyShuttle.Value).Grid.LocalAABB; @@ -137,6 +139,19 @@ public sealed partial class ShuttleSystem out var matty, out var targetAngle)) continue; + // Can't just use the AABB as we want to get bounds as tight as possible. + var spawnPosition = new EntityCoordinates(targetGrid.Value, matty.Transform(Vector2.Zero)); + spawnPosition = new EntityCoordinates(targetGridXform.MapUid!.Value, spawnPosition.ToMapPos(EntityManager)); + + var dockedBounds = new Box2Rotated(shuttleAABB.Translated(spawnPosition.Position), targetGridAngle, spawnPosition.Position); + + // Check if there's no intersecting grids (AKA oh god it's docking at cargo). + if (_mapManager.FindGridsIntersecting(targetGridXform.MapID, + dockedBounds).Any(o => o.GridEntityId != targetGrid)) + { + break; + } + // Alright well the spawn is valid now to check how many we can connect // Get the matrix for each shuttle dock and test it against the grid docks to see // if the connected position / direction matches. @@ -173,8 +188,6 @@ public sealed partial class ShuttleSystem } } - var spawnPosition = new EntityCoordinates(targetGrid.Value, matty.Transform(Vector2.Zero)); - spawnPosition = new EntityCoordinates(targetGridXform.MapUid!.Value, spawnPosition.ToMapPos(EntityManager)); var spawnRotation = shuttleDockXform.LocalRotation + gridXform.LocalRotation + targetGridXform.LocalRotation; @@ -192,8 +205,6 @@ public sealed partial class ShuttleSystem if (validDockConfigs.Count <= 0) return null; - var targetGridAngle = targetGridXform.WorldRotation.Reduced(); - // Prioritise by priority docks, then by maximum connected ports, then by most similar angle. validDockConfigs = validDockConfigs .OrderByDescending(x => x.Docks.Any(docks => HasComp(docks.DockB.Owner)))