Fix emergency shuttle docking causing grid overlap (#9197)
This commit is contained in:
@@ -104,7 +104,9 @@ public sealed partial class ShuttleSystem
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var targetGridGrid = Comp<IMapGridComponent>(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<IMapGridComponent>(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<EmergencyDockComponent>(docks.DockB.Owner)))
|
||||
|
||||
Reference in New Issue
Block a user