using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Systems; using Content.Shared._DV.CCVars; using Content.Shared.Tag; using Robust.Shared.EntitySerialization.Systems; using Robust.Shared.Configuration; using Robust.Shared.Prototypes; using Robust.Shared.Utility; using System.Diagnostics.CodeAnalysis; namespace Content.Server.Shipyard; /// /// Handles spawning and ftling ships. /// public sealed class ShipyardSystem : EntitySystem { [Dependency] private readonly IConfigurationManager _config = default!; [Dependency] private readonly MapDeleterShuttleSystem _mapDeleterShuttle = default!; [Dependency] private readonly MapLoaderSystem _mapLoader = default!; [Dependency] private readonly SharedMapSystem _map = default!; [Dependency] private readonly ShuttleSystem _shuttle = default!; public ProtoId DockTag = "DockShipyard"; public bool Enabled; public override void Initialize() { base.Initialize(); Subs.CVar(_config, DCCVars.Shipyard, value => Enabled = value, true); } /// /// Creates a ship from its yaml path in the shipyard. /// public bool TryCreateShuttle(ResPath path, [NotNullWhen(true)] out Entity? shuttle) { shuttle = null; if (!Enabled) return false; var map = _map.CreateMap(out var mapId); if (!_mapLoader.TryLoadGrid(mapId, path, out var grid)) { Log.Error($"Failed to load shuttle {path}"); Del(map); return false; } if (!TryComp(grid, out var comp)) { Log.Error($"Shuttle {path}'s grid was missing ShuttleComponent"); Del(map); return false; } _map.SetPaused(map, false); _mapDeleterShuttle.Enable(grid.Value); shuttle = (grid.Value, comp); return true; } /// /// Adds a ship to the shipyard and attempts to ftl-dock it to the given grid. /// public bool TrySendShuttle(Entity shuttleDestination, ResPath path, [NotNullWhen(true)] out Entity? shuttle) { shuttle = null; if (!Resolve(shuttleDestination, ref shuttleDestination.Comp)) return false; if (!TryCreateShuttle(path, out shuttle)) return false; Log.Info($"Shuttle {path} was spawned for {ToPrettyString(shuttleDestination):station}"); _shuttle.FTLToDock(shuttle.Value, shuttle.Value.Comp, shuttleDestination, priorityTag: DockTag); return true; } }