Disposals fixed under station rotation (#5067)

* Some sanity checks on disposals movement, fix the interpolator

* Technically fix disposal routing, but I'm not done here yet

* Remove disposals reliance on implicit direction sensing entirely.
This commit is contained in:
20kdc
2021-10-29 09:07:32 +01:00
committed by GitHub
parent 01d62baa64
commit 7cdb9dcf86
8 changed files with 64 additions and 55 deletions

View File

@@ -25,15 +25,14 @@ namespace Content.Server.Disposal.Tube.Components
public override Direction NextDirection(DisposalHolderComponent holder)
{
var directions = ConnectableDirections();
var previousTube = holder.PreviousTube;
var previousDF = holder.PreviousDirectionFrom;
if (previousTube == null)
if (previousDF == Direction.Invalid)
{
return directions[0];
}
var previousDirection = DirectionTo(previousTube);
return previousDirection == directions[0] ? directions[1] : directions[0];
return previousDF == directions[0] ? directions[1] : directions[0];
}
}
}

View File

@@ -57,7 +57,7 @@ namespace Content.Server.Disposal.Tube.Components
/// </summary>
public override Direction NextDirection(DisposalHolderComponent holder)
{
if (holder.PreviousTube != null && DirectionTo(holder.PreviousTube) == ConnectableDirections()[0])
if (holder.PreviousDirectionFrom != Direction.Invalid && holder.PreviousDirectionFrom == ConnectableDirections()[0])
{
var invalidDirections = new[] { ConnectableDirections()[0], Direction.Invalid };
var directions = Enum.GetValues(typeof(Direction))

View File

@@ -37,8 +37,8 @@ namespace Content.Server.Disposal.Tube.Components
var next = Owner.Transform.LocalRotation.GetDir();
var directions = ConnectableDirections().Skip(1).ToArray();
if (holder.PreviousTube == null ||
DirectionTo(holder.PreviousTube) == next)
if (holder.PreviousDirectionFrom == Direction.Invalid ||
holder.PreviousDirectionFrom == next)
{
return _random.Pick(directions);
}

View File

@@ -23,16 +23,16 @@ namespace Content.Server.Disposal.Tube.Components
public override Direction NextDirection(DisposalHolderComponent holder)
{
var directions = ConnectableDirections();
var previousTube = holder.PreviousTube;
var previousDF = holder.PreviousDirectionFrom;
var forward = directions[0];
if (previousTube == null)
if (previousDF == Direction.Invalid)
{
return forward;
}
var backward = directions[1];
return DirectionTo(previousTube) == forward ? backward : forward;
return previousDF == forward ? backward : forward;
}
}
}

View File

@@ -56,41 +56,6 @@ namespace Content.Server.Disposal.Tube.Components
return NextDirection(holder).ToVec();
}
protected Direction DirectionTo(IDisposalTubeComponent other)
{
return (other.Owner.Transform.WorldPosition - Owner.Transform.WorldPosition).GetDir();
}
public IDisposalTubeComponent? NextTube(DisposalHolderComponent holder)
{
var nextDirection = NextDirection(holder);
var oppositeDirection = new Angle(nextDirection.ToAngle().Theta + Math.PI).GetDir();
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var position = Owner.Transform.Coordinates;
foreach (var entity in grid.GetInDir(position, nextDirection))
{
if (!Owner.EntityManager.TryGetComponent(entity, out IDisposalTubeComponent? tube))
{
continue;
}
if (!tube.CanConnect(oppositeDirection, this))
{
continue;
}
if (!CanConnect(nextDirection, tube))
{
continue;
}
return tube;
}
return null;
}
public bool Remove(DisposalHolderComponent holder)
{
var removed = Contents.Remove(holder.Owner);

View File

@@ -11,7 +11,6 @@ namespace Content.Server.Disposal.Tube.Components
Direction NextDirection(DisposalHolderComponent holder);
Vector2 ExitVector(DisposalHolderComponent holder);
IDisposalTubeComponent? NextTube(DisposalHolderComponent holder);
bool Remove(DisposalHolderComponent holder);
bool TransferTo(DisposalHolderComponent holder, IDisposalTubeComponent to);
bool CanConnect(Direction direction, IDisposalTubeComponent with);