Exemplo n.º 1
0
    /// <summary>
    /// Checks if 2 docks can be connected by moving the shuttle directly onto docks.
    /// </summary>
    private bool CanDock(
        DockingComponent shuttleDock,
        TransformComponent shuttleXform,
        DockingComponent gridDock,
        TransformComponent gridXform,
        Vector2 targetGridRotation,
        Box2 shuttleAABB,
        IMapGridComponent grid,
        [NotNullWhen(true)] out Box2?shuttleDockedAABB,
        out Matrix3 matty,
        out Vector2 gridRotation)
    {
        gridRotation      = Vector2.Zero;
        matty             = Matrix3.Identity;
        shuttleDockedAABB = null;

        if (shuttleDock.Docked ||
            gridDock.Docked ||
            !shuttleXform.Anchored ||
            !gridXform.Anchored)
        {
            return(false);
        }

        // First, get the station dock's position relative to the shuttle, this is where we rotate it around
        var stationDockPos = shuttleXform.LocalPosition +
                             shuttleXform.LocalRotation.RotateVec(new Vector2(0f, -1f));

        var stationDockMatrix = Matrix3.CreateInverseTransform(stationDockPos, -shuttleXform.LocalRotation);
        var gridXformMatrix   = Matrix3.CreateTransform(gridXform.LocalPosition, gridXform.LocalRotation);

        Matrix3.Multiply(in stationDockMatrix, in gridXformMatrix, out matty);
        shuttleDockedAABB = matty.TransformBox(shuttleAABB);

        if (!ValidSpawn(grid, shuttleDockedAABB.Value))
        {
            return(false);
        }

        gridRotation = matty.Transform(targetGridRotation);
        return(true);
    }
Exemplo n.º 2
0
 /// <summary>
 /// Checks whether the emergency shuttle can warp to the specified position.
 /// </summary>
 private bool ValidSpawn(IMapGridComponent grid, Box2 area)
 {
     return(!grid.Grid.GetLocalTilesIntersecting(area).Any());
 }