Fix cargo shuttle (#10397)

This commit is contained in:
metalgearsloth
2022-08-08 09:22:46 +10:00
committed by GitHub
parent ee969c9799
commit 797a11a6ed
3 changed files with 36 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ using Content.Server.Shuttles.Events;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Server.Paper; using Content.Server.Paper;
using Content.Server.Shuttles.Systems; using Content.Server.Shuttles.Systems;
using Content.Server.Station.Components;
using Content.Shared.Cargo; using Content.Shared.Cargo;
using Content.Shared.Cargo.BUI; using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Components; using Content.Shared.Cargo.Components;
@@ -358,13 +359,22 @@ public sealed partial class CargoSystem
/// </summary> /// </summary>
public void CallShuttle(StationCargoOrderDatabaseComponent orderDatabase) public void CallShuttle(StationCargoOrderDatabaseComponent orderDatabase)
{ {
if (!TryComp<CargoShuttleComponent>(orderDatabase.Shuttle, out var shuttle) || if (!TryComp<CargoShuttleComponent>(orderDatabase.Shuttle, out var shuttle))
!TryComp<TransformComponent>(orderDatabase.Owner, out var xform)) return; return;
// Already called / not available // Already called / not available
if (shuttle.NextCall == null || _timing.CurTime < shuttle.NextCall) if (shuttle.NextCall == null || _timing.CurTime < shuttle.NextCall)
return; return;
if (!TryComp<StationDataComponent>(orderDatabase.Owner, out var stationData))
return;
var targetGrid = _station.GetLargestGrid(stationData);
// Nowhere to warp in to.
if (!TryComp<TransformComponent>(targetGrid, out var xform))
return;
shuttle.NextCall = null; shuttle.NextCall = null;
// Find a valid free area nearby to spawn in on // Find a valid free area nearby to spawn in on

View File

@@ -96,7 +96,7 @@ public sealed partial class ShuttleSystem
!TryComp<StationDataComponent>(_station.GetOwningStation(player.Value), out var stationData) || !TryComp<StationDataComponent>(_station.GetOwningStation(player.Value), out var stationData) ||
!TryComp<ShuttleComponent>(stationData.EmergencyShuttle, out var shuttle)) return; !TryComp<ShuttleComponent>(stationData.EmergencyShuttle, out var shuttle)) return;
var targetGrid = GetLargestGrid(stationData); var targetGrid = _station.GetLargestGrid(stationData);
if (targetGrid == null) return; if (targetGrid == null) return;
var config = GetDockingConfig(shuttle, targetGrid.Value); var config = GetDockingConfig(shuttle, targetGrid.Value);
if (config == null) return; if (config == null) return;
@@ -242,7 +242,7 @@ public sealed partial class ShuttleSystem
!TryComp<TransformComponent>(stationData.EmergencyShuttle, out var xform) || !TryComp<TransformComponent>(stationData.EmergencyShuttle, out var xform) ||
!TryComp<ShuttleComponent>(stationData.EmergencyShuttle, out var shuttle)) return; !TryComp<ShuttleComponent>(stationData.EmergencyShuttle, out var shuttle)) return;
var targetGrid = GetLargestGrid(stationData); var targetGrid = _station.GetLargestGrid(stationData);
// UHH GOOD LUCK // UHH GOOD LUCK
if (targetGrid == null) if (targetGrid == null)
@@ -378,27 +378,6 @@ public sealed partial class ShuttleSystem
_commsConsole.UpdateCommsConsoleInterface(); _commsConsole.UpdateCommsConsoleInterface();
} }
/// <summary>
/// Gets the largest member grid from a station.
/// </summary>
private EntityUid? GetLargestGrid(StationDataComponent component)
{
EntityUid? largestGrid = null;
Box2 largestBounds = new Box2();
foreach (var gridUid in component.Grids)
{
if (!TryComp<IMapGridComponent>(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<DockingComponent> GetDocks(EntityUid uid) private List<DockingComponent> GetDocks(EntityUid uid)
{ {
var result = new List<DockingComponent>(); var result = new List<DockingComponent>();

View File

@@ -94,7 +94,7 @@ public sealed class StationSystem : EntitySystem
private void OnStationDeleted(EntityUid uid, StationDataComponent component, ComponentShutdown args) 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 _gameTicker.RunLevel == GameRunLevel.InRound) // And not due to a round restart
{ {
throw new InvalidOperationException($"Station entity {ToPrettyString(uid)} is getting deleted mid-round."); throw new InvalidOperationException($"Station entity {ToPrettyString(uid)} is getting deleted mid-round.");
@@ -205,6 +205,27 @@ public sealed class StationSystem : EntitySystem
#endregion Event handlers #endregion Event handlers
/// <summary>
/// Gets the largest member grid from a station.
/// </summary>
public EntityUid? GetLargestGrid(StationDataComponent component)
{
EntityUid? largestGrid = null;
Box2 largestBounds = new Box2();
foreach (var gridUid in component.Grids)
{
if (!TryComp<IMapGridComponent>(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) public Filter GetInStation(EntityUid source, float range = 32f)
{ {
var station = GetOwningStation(source); var station = GetOwningStation(source);