mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Initial commit * Added pods * Transit tubes should no longer connect with disposal pipes * Updated the transit tube sprites * Revisited how the transit tubes work * Fixing merge conflict * Updated sprites * Simplified disposal component collections and updated yaml * Moved the majority of the disposals code to Shared * Move disposed ents via physics * Disposal unit now use generic visualizers * Followers of disposed entities have predicted movement * Made BeingDisposedSystem shared * Added documentation for some components * Code clean up * Removed unneeded container entries, tubes use directions instead of angles * Many EntityUid/Comp -> Entity<Comp> changes * Updated DisposableSystem * Review of DisposalTubeSystem * Review of DisposalUnitSystem * Review of DisposalSignalRouterSystem * Unit updates * Fixing merge conflict * Merge conflict resolved * Re-organization of systems and components * Allow trapped entities to escape endless loops * Fix for item ejection * UI updates * Minor tweak * Fixes for transit tubes * Removed placeholder sprite * Removed transit tubes (for now) * Moved exit stun time to DisposalHolderComponent * Added a limit on the amount of damage that can sustained from disposals travel * Fix for PVS-related sound issues * Added a limit on the number of entities that can be inserted into units * Clean up * Undid file scoping * Fixed test fail * Fixed test fail * Increased min default capacity of disposal units * Fixed audio spam occurring when dumping multiple items into a disposal unit * Tile prying now occurs whenever exiting an open pipe * Prevent attacking and interactions while traveling through disposals * Added generic verbs for entering/exiting disposal units * Fixed UI prediction bug * Bug fixes * Small improvements * Moved the disposal holder prototype from the disposal entry to the unit * Minor clean up * Added support for a disposal holder despawn effect * Added prediction guard * Test fail fix * Re-added new escape behavior * Removed outdated PVS code * Clean up * More escape behavior changes * More clean up * Updated exit selection logic * Bug fix * More clean up * Split up disposal unit code * Cleaned up disposal units some more * Adjusted exit throw distance * Capitalized disposal and mailing unit window titles * Bug fixes * Taggers and routers show existing tags when the UI opens * Fixed test fail * test fail fix * Minor performance improvement * Minor improvement in pathing * merge conflicts * Fix heisentest * Fixed mispredict * Updated system referencing conventions * Updated to account for changes made to the code * Attempting to fix submodule issue * Addressing test fails * Additional fixes for tests * Addressing reviewer comments * Cleaned up exit randomization * T-ray can see disposal pipes when in 'pipe' mode * Fix for flush animation flickering * mild thing * fix both --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
161 lines
5.4 KiB
C#
161 lines
5.4 KiB
C#
using Content.Shared.Atmos;
|
|
using Content.Shared.Disposal.Unit;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Random;
|
|
using System.Linq;
|
|
|
|
namespace Content.Shared.Disposal.Tube;
|
|
|
|
/// <summary>
|
|
/// Handles the basic logic for determining which disposal tubes are connected
|
|
/// and which direction entities inside the tubes should move next.
|
|
/// </summary>
|
|
public sealed partial class DisposalTubeSystem : EntitySystem
|
|
{
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private SharedPopupSystem _popups = default!;
|
|
[Dependency] private SharedMapSystem _map = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<DisposalTubeComponent, GetDisposalsNextDirectionEvent>(OnGetTubeNextDirection);
|
|
}
|
|
|
|
private void OnGetTubeNextDirection(Entity<DisposalTubeComponent> ent, ref GetDisposalsNextDirectionEvent args)
|
|
{
|
|
var exits = GetTubeConnectableDirections(ent);
|
|
SelectNextDirection(ent, exits, ref args);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a list of all potential exits to a disposal tube, accounting for its local rotation.
|
|
/// </summary>
|
|
/// <param name="ent">The disposal tube.</param>
|
|
public Direction[] GetTubeConnectableDirections(Entity<DisposalTubeComponent> ent)
|
|
{
|
|
var rotation = Transform(ent).LocalRotation;
|
|
|
|
return ent.Comp.Exits
|
|
.Select(exit => new Angle(exit.ToAngle() + rotation).GetDir())
|
|
.ToArray();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selects the best exit for a disposal tube, based on a curated list of choices.
|
|
/// </summary>
|
|
/// <param name="ent">The disposal tube.</param>
|
|
/// <param name="exits">The currated list of possible exits from the disposal tube.</param>
|
|
/// <param name="args">The args for the 'get next direction' event.</param>
|
|
public void SelectNextDirection(Entity<DisposalTubeComponent> ent, Direction[] exits, ref GetDisposalsNextDirectionEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (exits.Length == 0)
|
|
return;
|
|
|
|
// The first exit is the default
|
|
args.Next = exits[0];
|
|
|
|
// This may change based on the potential exits available
|
|
// and our current direction of travel
|
|
var currentDirection = args.Holder.Comp.CurrentDirection;
|
|
|
|
switch (exits.Length)
|
|
{
|
|
// There is only one exit
|
|
case 1:
|
|
if (args.Next.GetOpposite() == currentDirection)
|
|
args.Next = Direction.Invalid;
|
|
|
|
return;
|
|
|
|
// If there are two exits
|
|
case 2:
|
|
if (args.Next.GetOpposite() == currentDirection)
|
|
args.Next = exits[1];
|
|
|
|
return;
|
|
|
|
// If there are more than two exits
|
|
default:
|
|
|
|
// Check that the default exit is valid
|
|
if (args.Next.GetOpposite() == currentDirection)
|
|
{
|
|
// If it isn't, pick one of the remaining exits at random
|
|
var directions = exits.Skip(1).ToArray();
|
|
args.Next = _random.Pick(directions);
|
|
}
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to find an adjacent disposal tube in a specified direction.
|
|
/// </summary>
|
|
/// <param name="ent">The original disposal tube.</param>
|
|
/// <param name="direction">The specified direction.</param>
|
|
/// <returns>The adjacent disposal tube.</returns>
|
|
public EntityUid? GetTubeInDirection(Entity<DisposalTubeComponent> ent, Direction direction)
|
|
{
|
|
var oppositeDirection = direction.GetOpposite();
|
|
|
|
var xform = Transform(ent);
|
|
if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
|
|
return null;
|
|
|
|
var position = xform.Coordinates;
|
|
foreach (var entity in _map.GetInDir(xform.GridUid.Value, grid, position, direction))
|
|
{
|
|
if (!TryComp(entity, out DisposalTubeComponent? tube))
|
|
continue;
|
|
|
|
if (!CanConnect((entity, tube), oppositeDirection))
|
|
continue;
|
|
|
|
return entity;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether a disposal tube can make a valid connection in a specified direction.
|
|
/// </summary>
|
|
/// <param name="ent">The disposal tube.</param>
|
|
/// <param name="direction">The specified direction.</param>
|
|
/// <returns>True if a valid conenction can be made.</returns>
|
|
public bool CanConnect(Entity<DisposalTubeComponent> ent, Direction direction)
|
|
{
|
|
if (!Transform(ent).Anchored)
|
|
return false;
|
|
|
|
var exits = GetTubeConnectableDirections(ent);
|
|
|
|
if (exits.Length == 0)
|
|
return false;
|
|
|
|
return exits.Contains(direction);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a pop up message over a disposal tube, listing its potential exits.
|
|
/// </summary>
|
|
/// <param name="ent">The disposal tube.</param>
|
|
/// <param name="recipient">The recipient of the pop up message.</param>
|
|
public void PopupDirections(Entity<DisposalTubeComponent> ent, EntityUid recipient)
|
|
{
|
|
var exits = GetTubeConnectableDirections(ent);
|
|
|
|
if (exits.Length == 0)
|
|
return;
|
|
|
|
var directions = string.Join(", ", exits);
|
|
_popups.PopupEntity(Loc.GetString("disposal-tube-component-popup-directions-text", ("directions", directions)), ent, recipient);
|
|
}
|
|
}
|