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:
@@ -25,15 +25,14 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
public override Direction NextDirection(DisposalHolderComponent holder)
|
public override Direction NextDirection(DisposalHolderComponent holder)
|
||||||
{
|
{
|
||||||
var directions = ConnectableDirections();
|
var directions = ConnectableDirections();
|
||||||
var previousTube = holder.PreviousTube;
|
var previousDF = holder.PreviousDirectionFrom;
|
||||||
|
|
||||||
if (previousTube == null)
|
if (previousDF == Direction.Invalid)
|
||||||
{
|
{
|
||||||
return directions[0];
|
return directions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
var previousDirection = DirectionTo(previousTube);
|
return previousDF == directions[0] ? directions[1] : directions[0];
|
||||||
return previousDirection == directions[0] ? directions[1] : directions[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override Direction NextDirection(DisposalHolderComponent holder)
|
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 invalidDirections = new[] { ConnectableDirections()[0], Direction.Invalid };
|
||||||
var directions = Enum.GetValues(typeof(Direction))
|
var directions = Enum.GetValues(typeof(Direction))
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
var next = Owner.Transform.LocalRotation.GetDir();
|
var next = Owner.Transform.LocalRotation.GetDir();
|
||||||
var directions = ConnectableDirections().Skip(1).ToArray();
|
var directions = ConnectableDirections().Skip(1).ToArray();
|
||||||
|
|
||||||
if (holder.PreviousTube == null ||
|
if (holder.PreviousDirectionFrom == Direction.Invalid ||
|
||||||
DirectionTo(holder.PreviousTube) == next)
|
holder.PreviousDirectionFrom == next)
|
||||||
{
|
{
|
||||||
return _random.Pick(directions);
|
return _random.Pick(directions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,16 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
public override Direction NextDirection(DisposalHolderComponent holder)
|
public override Direction NextDirection(DisposalHolderComponent holder)
|
||||||
{
|
{
|
||||||
var directions = ConnectableDirections();
|
var directions = ConnectableDirections();
|
||||||
var previousTube = holder.PreviousTube;
|
var previousDF = holder.PreviousDirectionFrom;
|
||||||
var forward = directions[0];
|
var forward = directions[0];
|
||||||
|
|
||||||
if (previousTube == null)
|
if (previousDF == Direction.Invalid)
|
||||||
{
|
{
|
||||||
return forward;
|
return forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
var backward = directions[1];
|
var backward = directions[1];
|
||||||
return DirectionTo(previousTube) == forward ? backward : forward;
|
return previousDF == forward ? backward : forward;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,41 +56,6 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
return NextDirection(holder).ToVec();
|
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)
|
public bool Remove(DisposalHolderComponent holder)
|
||||||
{
|
{
|
||||||
var removed = Contents.Remove(holder.Owner);
|
var removed = Contents.Remove(holder.Owner);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ namespace Content.Server.Disposal.Tube.Components
|
|||||||
|
|
||||||
Direction NextDirection(DisposalHolderComponent holder);
|
Direction NextDirection(DisposalHolderComponent holder);
|
||||||
Vector2 ExitVector(DisposalHolderComponent holder);
|
Vector2 ExitVector(DisposalHolderComponent holder);
|
||||||
IDisposalTubeComponent? NextTube(DisposalHolderComponent holder);
|
|
||||||
bool Remove(DisposalHolderComponent holder);
|
bool Remove(DisposalHolderComponent holder);
|
||||||
bool TransferTo(DisposalHolderComponent holder, IDisposalTubeComponent to);
|
bool TransferTo(DisposalHolderComponent holder, IDisposalTubeComponent to);
|
||||||
bool CanConnect(Direction direction, IDisposalTubeComponent with);
|
bool CanConnect(Direction direction, IDisposalTubeComponent with);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ using Robust.Server.GameObjects;
|
|||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -14,6 +16,7 @@ namespace Content.Server.Disposal.Tube
|
|||||||
public sealed class DisposalTubeSystem : EntitySystem
|
public sealed class DisposalTubeSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -77,5 +80,36 @@ namespace Content.Server.Disposal.Tube
|
|||||||
{
|
{
|
||||||
component.AnchoredChanged();
|
component.AnchoredChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IDisposalTubeComponent? NextTubeFor(EntityUid target, Direction nextDirection, IDisposalTubeComponent? targetTube = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(target, ref targetTube))
|
||||||
|
return null;
|
||||||
|
var oppositeDirection = nextDirection.GetOpposite();
|
||||||
|
|
||||||
|
var grid = _mapManager.GetGrid(targetTube.Owner.Transform.GridID);
|
||||||
|
var position = targetTube.Owner.Transform.Coordinates;
|
||||||
|
foreach (var entity in grid.GetInDir(position, nextDirection))
|
||||||
|
{
|
||||||
|
if (!EntityManager.TryGetComponent(entity, out IDisposalTubeComponent? tube))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tube.CanConnect(oppositeDirection, targetTube))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetTube.CanConnect(nextDirection, tube))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tube;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ using System.Linq;
|
|||||||
using Content.Server.Atmos;
|
using Content.Server.Atmos;
|
||||||
using Content.Server.Atmos.EntitySystems;
|
using Content.Server.Atmos.EntitySystems;
|
||||||
using Content.Server.Disposal.Tube.Components;
|
using Content.Server.Disposal.Tube.Components;
|
||||||
|
using Content.Server.Disposal.Tube;
|
||||||
using Content.Server.Items;
|
using Content.Server.Items;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
@@ -41,10 +43,17 @@ namespace Content.Server.Disposal.Unit.Components
|
|||||||
public IDisposalTubeComponent? PreviousTube { get; set; }
|
public IDisposalTubeComponent? PreviousTube { get; set; }
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public IDisposalTubeComponent? CurrentTube { get; private set; }
|
public Direction PreviousDirection { get; private set; } = Direction.Invalid;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public IDisposalTubeComponent? NextTube { get; set; }
|
public Direction PreviousDirectionFrom => (PreviousDirection == Direction.Invalid) ? Direction.Invalid : PreviousDirection.GetOpposite();
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public IDisposalTubeComponent? CurrentTube { get; private set; }
|
||||||
|
|
||||||
|
// CurrentDirection is not null when CurrentTube isn't null.
|
||||||
|
[ViewVariables]
|
||||||
|
public Direction CurrentDirection { get; private set; } = Direction.Invalid;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of tags attached to the content, used for sorting
|
/// A list of tags attached to the content, used for sorting
|
||||||
@@ -100,11 +109,12 @@ namespace Content.Server.Disposal.Unit.Components
|
|||||||
if (CurrentTube != null)
|
if (CurrentTube != null)
|
||||||
{
|
{
|
||||||
PreviousTube = CurrentTube;
|
PreviousTube = CurrentTube;
|
||||||
|
PreviousDirection = CurrentDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
Owner.Transform.Coordinates = tube.Owner.Transform.Coordinates;
|
Owner.Transform.Coordinates = tube.Owner.Transform.Coordinates;
|
||||||
CurrentTube = tube;
|
CurrentTube = tube;
|
||||||
NextTube = tube.NextTube(this);
|
CurrentDirection = tube.NextDirection(this);
|
||||||
StartingTime = 0.1f;
|
StartingTime = 0.1f;
|
||||||
TimeLeft = 0.1f;
|
TimeLeft = 0.1f;
|
||||||
}
|
}
|
||||||
@@ -115,8 +125,9 @@ namespace Content.Server.Disposal.Unit.Components
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
PreviousTube = null;
|
PreviousTube = null;
|
||||||
|
PreviousDirection = Direction.Invalid;
|
||||||
CurrentTube = null;
|
CurrentTube = null;
|
||||||
NextTube = null;
|
CurrentDirection = Direction.Invalid;
|
||||||
StartingTime = 0;
|
StartingTime = 0;
|
||||||
TimeLeft = 0;
|
TimeLeft = 0;
|
||||||
|
|
||||||
@@ -159,7 +170,7 @@ namespace Content.Server.Disposal.Unit.Components
|
|||||||
TimeLeft -= time;
|
TimeLeft -= time;
|
||||||
frameTime -= time;
|
frameTime -= time;
|
||||||
|
|
||||||
if (CurrentTube == null)
|
if (CurrentTube == null || CurrentTube.Deleted)
|
||||||
{
|
{
|
||||||
ExitDisposals();
|
ExitDisposals();
|
||||||
break;
|
break;
|
||||||
@@ -168,16 +179,17 @@ namespace Content.Server.Disposal.Unit.Components
|
|||||||
if (TimeLeft > 0)
|
if (TimeLeft > 0)
|
||||||
{
|
{
|
||||||
var progress = 1 - TimeLeft / StartingTime;
|
var progress = 1 - TimeLeft / StartingTime;
|
||||||
var origin = CurrentTube.Owner.Transform.WorldPosition;
|
var origin = CurrentTube.Owner.Transform.Coordinates;
|
||||||
var destination = CurrentTube.NextDirection(this).ToVec();
|
var destination = CurrentDirection.ToVec();
|
||||||
var newPosition = destination * progress;
|
var newPosition = destination * progress;
|
||||||
|
|
||||||
Owner.Transform.WorldPosition = origin + newPosition;
|
Owner.Transform.Coordinates = origin.Offset(newPosition);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NextTube == null || !CurrentTube.TransferTo(this, NextTube))
|
var nextTube = EntitySystem.Get<DisposalTubeSystem>().NextTubeFor(CurrentTube.Owner.Uid, CurrentDirection);
|
||||||
|
if (nextTube == null || nextTube.Deleted || !CurrentTube.TransferTo(this, nextTube))
|
||||||
{
|
{
|
||||||
CurrentTube.Remove(this);
|
CurrentTube.Remove(this);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user