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

@@ -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;