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
This commit is contained in:
69
Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs
Normal file
69
Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user