Shuttle drone improvements (#16931)

This commit is contained in:
metalgearsloth
2023-05-31 11:13:02 +10:00
committed by GitHub
parent 53d4e408aa
commit 57858f802f
35 changed files with 335 additions and 278 deletions

View File

@@ -0,0 +1,13 @@
using Content.Server.Shuttles.Systems;
using Robust.Shared.Utility;
namespace Content.Server.Shuttles.Components;
/// <summary>
/// Similar to <see cref="GridFillComponent"/> except spawns the grid near to the station.
/// </summary>
[RegisterComponent, Access(typeof(ShuttleSystem))]
public sealed class GridSpawnComponent : Component
{
[DataField("paths", required: true)] public List<ResPath> Paths = new();
}

View File

@@ -8,5 +8,8 @@ namespace Content.Server.Shuttles.Events;
[ByRefEvent]
public struct ConsoleShuttleEvent
{
/// <summary>
/// Console that we proxy into.
/// </summary>
public EntityUid? Console;
}

View File

@@ -0,0 +1,75 @@
using Content.Server.Shuttle.Components;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.Station.Components;
using Content.Server.UserInterface;
namespace Content.Server.Shuttles.Systems;
public sealed partial class ShuttleConsoleSystem
{
/// <summary>
/// Refreshes all drone console entities.
/// </summary>
public void RefreshDroneConsoles()
{
var query = AllEntityQuery<DroneConsoleComponent>();
while (query.MoveNext(out var uid, out var comp))
{
comp.Entity = GetShuttleConsole(uid, comp);
}
}
private void OnDronePilotConsoleOpen(EntityUid uid, DroneConsoleComponent component, AfterActivatableUIOpenEvent args)
{
component.Entity = GetShuttleConsole(uid);
}
private void OnDronePilotConsoleClose(EntityUid uid, DroneConsoleComponent component, BoundUIClosedEvent args)
{
component.Entity = null;
}
private void OnCargoGetConsole(EntityUid uid, DroneConsoleComponent component, ref ConsoleShuttleEvent args)
{
args.Console = GetShuttleConsole(uid, component);
}
/// <summary>
/// Gets the relevant shuttle console to proxy from the drone console.
/// </summary>
private EntityUid? GetShuttleConsole(EntityUid uid, DroneConsoleComponent? component = null)
{
if (!Resolve(uid, ref component))
return null;
var stationUid = _station.GetOwningStation(uid);
if (stationUid == null)
return null;
// I know this sucks but needs device linking or something idunno
var query = AllEntityQuery<ShuttleConsoleComponent, TransformComponent>();
while (query.MoveNext(out var cUid, out _, out var xform))
{
if (xform.GridUid == null ||
!TryComp<StationMemberComponent>(xform.GridUid, out var member) ||
member.Station != stationUid)
{
continue;
}
foreach (var compType in component.Components.Values)
{
if (!HasComp(xform.GridUid, compType.Component.GetType()))
continue;
return cUid;
}
}
return null;
}
}

View File

@@ -1,7 +1,9 @@
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Shuttle.Components;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.Station.Systems;
using Content.Server.UserInterface;
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
@@ -21,13 +23,14 @@ using Robust.Shared.Utility;
namespace Content.Server.Shuttles.Systems;
public sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly ShuttleSystem _shuttle = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly TagSystem _tags = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
@@ -42,6 +45,10 @@ public sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
SubscribeLocalEvent<ShuttleConsoleComponent, ShuttleConsoleFTLRequestMessage>(OnDestinationMessage);
SubscribeLocalEvent<ShuttleConsoleComponent, BoundUIClosedEvent>(OnConsoleUIClose);
SubscribeLocalEvent<DroneConsoleComponent, ConsoleShuttleEvent>(OnCargoGetConsole);
SubscribeLocalEvent<DroneConsoleComponent, AfterActivatableUIOpenEvent>(OnDronePilotConsoleOpen);
SubscribeLocalEvent<DroneConsoleComponent, BoundUIClosedEvent>(OnDronePilotConsoleClose);
SubscribeLocalEvent<DockEvent>(OnDock);
SubscribeLocalEvent<UndockEvent>(OnUndock);

View File

@@ -1,5 +1,7 @@
using Content.Server.Shuttles.Components;
using Content.Server.Station.Components;
using Content.Server.Station.Events;
using Content.Shared.Cargo.Components;
using Content.Shared.CCVar;
namespace Content.Server.Shuttles.Systems;
@@ -8,11 +10,88 @@ public sealed partial class ShuttleSystem
{
private void InitializeGridFills()
{
SubscribeLocalEvent<GridSpawnComponent, StationPostInitEvent>(OnGridSpawnPostInit);
SubscribeLocalEvent<GridFillComponent, MapInitEvent>(OnGridFillMapInit);
_cfg.OnValueChanged(CCVars.GridFill, OnGridFillChange);
}
private void ShutdownGridFills()
{
_cfg.UnsubValueChanged(CCVars.GridFill, OnGridFillChange);
}
private void OnGridFillChange(bool obj)
{
// If you're doing this on live then god help you,
if (obj)
{
var query = AllEntityQuery<GridSpawnComponent>();
while (query.MoveNext(out var uid, out var comp))
{
GridSpawns(uid, comp);
}
}
}
private void OnGridSpawnPostInit(EntityUid uid, GridSpawnComponent component, ref StationPostInitEvent args)
{
GridSpawns(uid, component);
}
private void GridSpawns(EntityUid uid, GridSpawnComponent component)
{
if (!_cfg.GetCVar(CCVars.GridFill))
return;
if (!TryComp<StationDataComponent>(uid, out var data))
{
return;
}
var targetGrid = _station.GetLargestGrid(data);
if (targetGrid == null)
return;
// Spawn on a dummy map and try to FTL if possible, otherwise dump it.
var mapId = _mapManager.CreateMap();
var valid = true;
foreach (var path in component.Paths)
{
if (_loader.TryLoad(mapId, path.ToString(), out var ent) && ent.Count == 1)
{
if (TryComp<ShuttleComponent>(ent[0], out var shuttle))
{
TryFTLProximity(ent[0], shuttle, targetGrid.Value);
_station.AddGridToStation(uid, ent[0]);
}
else
{
valid = false;
}
}
else
{
valid = false;
}
if (!valid)
{
_sawmill.Error($"Error loading gridspawn for {ToPrettyString(uid)} / {path}");
}
}
_mapManager.DeleteMap(mapId);
}
private void OnGridFillMapInit(EntityUid uid, GridFillComponent component, MapInitEvent args)
{
if (!_cfg.GetCVar(CCVars.GridFill))
return;
if (!TryComp<DockingComponent>(uid, out var dock) ||
!TryComp<TransformComponent>(uid, out var xform) ||
xform.GridUid == null)
@@ -20,9 +99,6 @@ public sealed partial class ShuttleSystem
return;
}
if (_cfg.GetCVar(CCVars.DisableGridFill))
return;
// Spawn on a dummy map and try to dock if possible, otherwise dump it.
var mapId = _mapManager.CreateMap();
var valid = false;

View File

@@ -67,6 +67,13 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem
SubscribeLocalEvent<FixturesComponent, GridFixtureChangeEvent>(OnGridFixtureChange);
}
public override void Shutdown()
{
base.Shutdown();
ShutdownGridFills();
}
public override void Update(float frameTime)
{
base.Update(frameTime);