diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index 195cc4f342..c30a7d70c5 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -6,6 +6,7 @@ using Content.Server.Shuttles.Events; using Content.Server.UserInterface; using Content.Server.Paper; using Content.Server.Shuttles.Systems; +using Content.Server.Station.Components; using Content.Shared.Cargo; using Content.Shared.Cargo.BUI; using Content.Shared.Cargo.Components; @@ -358,13 +359,22 @@ public sealed partial class CargoSystem /// public void CallShuttle(StationCargoOrderDatabaseComponent orderDatabase) { - if (!TryComp(orderDatabase.Shuttle, out var shuttle) || - !TryComp(orderDatabase.Owner, out var xform)) return; + if (!TryComp(orderDatabase.Shuttle, out var shuttle)) + return; // Already called / not available if (shuttle.NextCall == null || _timing.CurTime < shuttle.NextCall) return; + if (!TryComp(orderDatabase.Owner, out var stationData)) + return; + + var targetGrid = _station.GetLargestGrid(stationData); + + // Nowhere to warp in to. + if (!TryComp(targetGrid, out var xform)) + return; + shuttle.NextCall = null; // Find a valid free area nearby to spawn in on diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs index c1fd6fc9e6..547d218143 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.EmergencyShuttle.cs @@ -96,7 +96,7 @@ public sealed partial class ShuttleSystem !TryComp(_station.GetOwningStation(player.Value), out var stationData) || !TryComp(stationData.EmergencyShuttle, out var shuttle)) return; - var targetGrid = GetLargestGrid(stationData); + var targetGrid = _station.GetLargestGrid(stationData); if (targetGrid == null) return; var config = GetDockingConfig(shuttle, targetGrid.Value); if (config == null) return; @@ -242,7 +242,7 @@ public sealed partial class ShuttleSystem !TryComp(stationData.EmergencyShuttle, out var xform) || !TryComp(stationData.EmergencyShuttle, out var shuttle)) return; - var targetGrid = GetLargestGrid(stationData); + var targetGrid = _station.GetLargestGrid(stationData); // UHH GOOD LUCK if (targetGrid == null) @@ -378,27 +378,6 @@ public sealed partial class ShuttleSystem _commsConsole.UpdateCommsConsoleInterface(); } - /// - /// Gets the largest member grid from a station. - /// - private EntityUid? GetLargestGrid(StationDataComponent component) - { - EntityUid? largestGrid = null; - Box2 largestBounds = new Box2(); - - foreach (var gridUid in component.Grids) - { - if (!TryComp(gridUid, out var grid)) continue; - - if (grid.Grid.LocalAABB.Size.LengthSquared < largestBounds.Size.LengthSquared) continue; - - largestBounds = grid.Grid.LocalAABB; - largestGrid = gridUid; - } - - return largestGrid; - } - private List GetDocks(EntityUid uid) { var result = new List(); diff --git a/Content.Server/Station/Systems/StationSystem.cs b/Content.Server/Station/Systems/StationSystem.cs index b052f01e77..ac00f7a4a9 100644 --- a/Content.Server/Station/Systems/StationSystem.cs +++ b/Content.Server/Station/Systems/StationSystem.cs @@ -94,7 +94,7 @@ public sealed class StationSystem : EntitySystem private void OnStationDeleted(EntityUid uid, StationDataComponent component, ComponentShutdown args) { - if (_stations.Contains(uid) && // Was not deleted via DeleteStation() + if (_stations.Contains(uid) && // Was not deleted via DeleteStation() _gameTicker.RunLevel == GameRunLevel.InRound) // And not due to a round restart { throw new InvalidOperationException($"Station entity {ToPrettyString(uid)} is getting deleted mid-round."); @@ -205,6 +205,27 @@ public sealed class StationSystem : EntitySystem #endregion Event handlers + /// + /// Gets the largest member grid from a station. + /// + public EntityUid? GetLargestGrid(StationDataComponent component) + { + EntityUid? largestGrid = null; + Box2 largestBounds = new Box2(); + + foreach (var gridUid in component.Grids) + { + if (!TryComp(gridUid, out var grid) || + grid.Grid.LocalAABB.Size.LengthSquared < largestBounds.Size.LengthSquared) + continue; + + largestBounds = grid.Grid.LocalAABB; + largestGrid = gridUid; + } + + return largestGrid; + } + public Filter GetInStation(EntityUid source, float range = 32f) { var station = GetOwningStation(source);