using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Systems; using Content.Server.Station.Components; using Content.Server.Station.Systems; using Content.Shared.DeltaV.CCVars; using Content.Shared.Tag; using Robust.Server.GameObjects; using Robust.Shared.Configuration; using Robust.Shared.EntitySerialization.Systems; using Robust.Shared.Utility; 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 MapSystem _map = default!; [Dependency] private readonly MapLoaderSystem _mapLoader = default!; [Dependency] private readonly ShuttleSystem _shuttle = default!; [Dependency] private readonly StationSystem _station = default!; [ValidatePrototypeId] public string 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 Entity? TryCreateShuttle(ResPath path) { if (!Enabled) return null; var map = _map.CreateMap(out var mapId); _map.SetPaused(map, false); if (!_mapLoader.TryLoadGrid(mapId, path, out var grid)) { Log.Error($"Failed to load shuttle {path}"); Del(map); return null; } if (!TryComp(grid, out var comp)) { Log.Error($"Shuttle {path}'s grid was missing ShuttleComponent"); Del(map); return null; } _mapDeleterShuttle.Enable(grid.Value.Owner); return (grid.Value.Owner, comp); } /// /// Adds a ship to the shipyard and attempts to ftl-dock it to the given station. /// public Entity? TrySendShuttle(Entity station, ResPath path) { if (!Resolve(station, ref station.Comp)) return null; if (_station.GetLargestGrid(station.Comp) is not {} grid) { Log.Error($"Station {ToPrettyString(station):station} had no largest grid to FTL to"); return null; } if (TryCreateShuttle(path) is not {} shuttle) return null; Log.Info($"Shuttle {path} was spawned for {ToPrettyString(station):station}, FTLing to {grid}"); _shuttle.FTLToDock(shuttle, shuttle.Comp, grid, priorityTag: DockTag); return shuttle; } }