Fix docking configs (#13256)
* Fix docking configs * fixes * fucking rouny * a
This commit is contained in:
@@ -126,7 +126,6 @@ public sealed partial class ShuttleSystem
|
|||||||
var targetGridGrid = Comp<MapGridComponent>(targetGrid);
|
var targetGridGrid = Comp<MapGridComponent>(targetGrid);
|
||||||
var targetGridXform = xformQuery.GetComponent(targetGrid);
|
var targetGridXform = xformQuery.GetComponent(targetGrid);
|
||||||
var targetGridAngle = targetGridXform.WorldRotation.Reduced();
|
var targetGridAngle = targetGridXform.WorldRotation.Reduced();
|
||||||
var targetGridRotation = targetGridAngle.ToVec();
|
|
||||||
|
|
||||||
var shuttleDocks = GetDocks(component.Owner);
|
var shuttleDocks = GetDocks(component.Owner);
|
||||||
var shuttleAABB = Comp<MapGridComponent>(component.Owner).LocalAABB;
|
var shuttleAABB = Comp<MapGridComponent>(component.Owner).LocalAABB;
|
||||||
@@ -147,7 +146,7 @@ public sealed partial class ShuttleSystem
|
|||||||
if (!CanDock(
|
if (!CanDock(
|
||||||
shuttleDock, shuttleDockXform,
|
shuttleDock, shuttleDockXform,
|
||||||
gridDock, gridXform,
|
gridDock, gridXform,
|
||||||
targetGridRotation,
|
targetGridAngle,
|
||||||
shuttleAABB,
|
shuttleAABB,
|
||||||
targetGridGrid,
|
targetGridGrid,
|
||||||
out var dockedAABB,
|
out var dockedAABB,
|
||||||
@@ -191,7 +190,7 @@ public sealed partial class ShuttleSystem
|
|||||||
xformQuery.GetComponent(other.Owner),
|
xformQuery.GetComponent(other.Owner),
|
||||||
otherGrid,
|
otherGrid,
|
||||||
xformQuery.GetComponent(otherGrid.Owner),
|
xformQuery.GetComponent(otherGrid.Owner),
|
||||||
targetGridRotation,
|
targetGridAngle,
|
||||||
shuttleAABB, targetGridGrid,
|
shuttleAABB, targetGridGrid,
|
||||||
out var otherDockedAABB,
|
out var otherDockedAABB,
|
||||||
out _,
|
out _,
|
||||||
@@ -203,16 +202,12 @@ public sealed partial class ShuttleSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var spawnRotation = shuttleDockXform.LocalRotation +
|
|
||||||
gridXform.LocalRotation +
|
|
||||||
targetGridXform.LocalRotation;
|
|
||||||
|
|
||||||
validDockConfigs.Add(new DockingConfig()
|
validDockConfigs.Add(new DockingConfig()
|
||||||
{
|
{
|
||||||
Docks = dockedPorts,
|
Docks = dockedPorts,
|
||||||
Area = dockedAABB.Value,
|
Area = dockedAABB.Value,
|
||||||
Coordinates = spawnPosition,
|
Coordinates = spawnPosition,
|
||||||
Angle = spawnRotation,
|
Angle = targetAngle,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,40 +299,46 @@ public sealed partial class ShuttleSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private bool CanDock(
|
private bool CanDock(
|
||||||
DockingComponent shuttleDock,
|
DockingComponent shuttleDock,
|
||||||
TransformComponent shuttleXform,
|
TransformComponent shuttleDockXform,
|
||||||
DockingComponent gridDock,
|
DockingComponent gridDock,
|
||||||
TransformComponent gridXform,
|
TransformComponent gridDockXform,
|
||||||
Vector2 targetGridRotation,
|
Angle targetGridRotation,
|
||||||
Box2 shuttleAABB,
|
Box2 shuttleAABB,
|
||||||
MapGridComponent grid,
|
MapGridComponent grid,
|
||||||
[NotNullWhen(true)] out Box2? shuttleDockedAABB,
|
[NotNullWhen(true)] out Box2? shuttleDockedAABB,
|
||||||
out Matrix3 matty,
|
out Matrix3 matty,
|
||||||
out Vector2 gridRotation)
|
out Angle gridRotation)
|
||||||
{
|
{
|
||||||
gridRotation = Vector2.Zero;
|
gridRotation = Angle.Zero;
|
||||||
matty = Matrix3.Identity;
|
matty = Matrix3.Identity;
|
||||||
shuttleDockedAABB = null;
|
shuttleDockedAABB = null;
|
||||||
|
|
||||||
if (shuttleDock.Docked ||
|
if (shuttleDock.Docked ||
|
||||||
gridDock.Docked ||
|
gridDock.Docked ||
|
||||||
!shuttleXform.Anchored ||
|
!shuttleDockXform.Anchored ||
|
||||||
!gridXform.Anchored)
|
!gridDockXform.Anchored)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, get the station dock's position relative to the shuttle, this is where we rotate it around
|
// First, get the station dock's position relative to the shuttle, this is where we rotate it around
|
||||||
var stationDockPos = shuttleXform.LocalPosition +
|
var stationDockPos = shuttleDockXform.LocalPosition +
|
||||||
shuttleXform.LocalRotation.RotateVec(new Vector2(0f, -1f));
|
shuttleDockXform.LocalRotation.RotateVec(new Vector2(0f, -1f));
|
||||||
|
|
||||||
var stationDockMatrix = Matrix3.CreateInverseTransform(stationDockPos, -shuttleXform.LocalRotation);
|
// Need to invert the grid's angle.
|
||||||
var gridXformMatrix = Matrix3.CreateTransform(gridXform.LocalPosition, gridXform.LocalRotation);
|
var shuttleDockAngle = shuttleDockXform.LocalRotation;
|
||||||
|
var gridDockAngle = gridDockXform.LocalRotation.Opposite();
|
||||||
|
|
||||||
|
var stationDockMatrix = Matrix3.CreateInverseTransform(stationDockPos, shuttleDockAngle);
|
||||||
|
var gridXformMatrix = Matrix3.CreateTransform(gridDockXform.LocalPosition, gridDockAngle);
|
||||||
Matrix3.Multiply(in stationDockMatrix, in gridXformMatrix, out matty);
|
Matrix3.Multiply(in stationDockMatrix, in gridXformMatrix, out matty);
|
||||||
shuttleDockedAABB = matty.TransformBox(shuttleAABB);
|
shuttleDockedAABB = matty.TransformBox(shuttleAABB);
|
||||||
|
// Rounding moment
|
||||||
|
shuttleDockedAABB = shuttleDockedAABB.Value.Enlarged(-0.01f);
|
||||||
|
|
||||||
if (!ValidSpawn(grid, shuttleDockedAABB.Value)) return false;
|
if (!ValidSpawn(grid, shuttleDockedAABB.Value)) return false;
|
||||||
|
|
||||||
gridRotation = matty.Transform(targetGridRotation);
|
gridRotation = targetGridRotation + gridDockAngle - shuttleDockAngle;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user