Files
tbd-station-14/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs
metalgearsloth 448165ffda Escape pods (#14809)
* Namespace adjustments for days

* pod

* thanks rider

* Fix the oop launch

* Fixes

* Fix stuff

* eeeeeeeee

* Fix

* access

* map

* forgor

* thing

* Genericise escape pod fill
2023-03-23 19:54:41 -06:00

70 lines
2.0 KiB
C#

using Content.Server.Shuttles.Components;
namespace Content.Server.Shuttles.Systems;
public sealed partial class ShuttleSystem
{
private void InitializeGridFills()
{
SubscribeLocalEvent<GridFillComponent, MapInitEvent>(OnGridFillMapInit);
}
private void OnGridFillMapInit(EntityUid uid, GridFillComponent component, MapInitEvent args)
{
if (!TryComp<DockingComponent>(uid, out var dock) ||
!TryComp<TransformComponent>(uid, out var xform) ||
xform.GridUid == null)
{
return;
}
// Spawn on a dummy map and try to dock if possible, otherwise dump it.
var mapId = _mapManager.CreateMap();
var valid = false;
if (_loader.TryLoad(mapId, component.Path.ToString(), out var ent) &&
ent.Count == 1 &&
TryComp<TransformComponent>(ent[0], out var shuttleXform))
{
var escape = GetSingleDock(ent[0]);
if (escape != null)
{
var config = _dockSystem.GetDockingConfig(ent[0], xform.GridUid.Value, escape.Value.Entity, escape.Value.Component, uid, dock);
if (config != null)
{
FTLDock(config, shuttleXform);
valid = true;
}
}
}
if (!valid)
{
_sawmill.Error($"Error loading gridfill dock for {ToPrettyString(uid)} / {component.Path}");
}
_mapManager.DeleteMap(mapId);
}
private (EntityUid Entity, DockingComponent Component)? GetSingleDock(EntityUid uid)
{
var dockQuery = GetEntityQuery<DockingComponent>();
var xformQuery = GetEntityQuery<TransformComponent>();
var xform = xformQuery.GetComponent(uid);
var rator = xform.ChildEnumerator;
while (rator.MoveNext(out var child))
{
if (!dockQuery.TryGetComponent(child, out var dock))
continue;
return (child.Value, dock);
}
return null;
}
}