]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Split cargo shuttle to its own component (#23926)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Thu, 11 Jan 2024 15:53:00 +0000 (02:53 +1100)
committerGitHub <noreply@github.com>
Thu, 11 Jan 2024 15:53:00 +0000 (10:53 -0500)
* Split cargo shuttle to its own component

If mappers want 1 morbillion of them this is easier to manage.

* balls

Content.Server/Shuttles/Components/StationCargoShuttleComponent.cs [new file with mode: 0644]
Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs
Resources/Prototypes/Entities/Stations/base.yml

diff --git a/Content.Server/Shuttles/Components/StationCargoShuttleComponent.cs b/Content.Server/Shuttles/Components/StationCargoShuttleComponent.cs
new file mode 100644 (file)
index 0000000..6ee890a
--- /dev/null
@@ -0,0 +1,19 @@
+using Robust.Shared.Utility;
+
+namespace Content.Server.Shuttles.Components;
+
+/// <summary>
+/// GridSpawnComponent but for cargo shuttles
+/// <remarks>
+/// This exists so we don't need to make 1 change to GridSpawn for every single station's unique shuttles.
+/// </remarks>
+/// </summary>
+[RegisterComponent]
+public sealed partial class StationCargoShuttleComponent : Component
+{
+    // If you add more than just make an abstract comp, split them, then use overloads in the system.
+    // YAML is filled out so mappers don't have to read here.
+
+    [DataField(required: true)]
+    public ResPath Path = new("/Maps/Shuttles/cargo.yml");
+}
index 2d52f98423123144ce39b1488d22ab9e00651a2e..5958bf0ebdde54a75e1c891788f3aa5232b09acb 100644 (file)
@@ -14,6 +14,8 @@ public sealed partial class ShuttleSystem
     private void InitializeGridFills()
     {
         SubscribeLocalEvent<GridSpawnComponent, StationPostInitEvent>(OnGridSpawnPostInit);
+        SubscribeLocalEvent<StationCargoShuttleComponent, StationPostInitEvent>(OnCargoSpawnPostInit);
+
         SubscribeLocalEvent<GridFillComponent, MapInitEvent>(OnGridFillMapInit);
 
         _cfg.OnValueChanged(CCVars.GridFill, OnGridFillChange);
@@ -35,6 +37,13 @@ public sealed partial class ShuttleSystem
             {
                 GridSpawns(uid, comp);
             }
+
+            var cargoQuery = AllEntityQuery<StationCargoShuttleComponent>();
+
+            while (cargoQuery.MoveNext(out var uid, out var comp))
+            {
+                CargoSpawn(uid, comp);
+            }
         }
     }
 
@@ -43,6 +52,39 @@ public sealed partial class ShuttleSystem
         GridSpawns(uid, component);
     }
 
+    private void OnCargoSpawnPostInit(EntityUid uid, StationCargoShuttleComponent component, ref StationPostInitEvent args)
+    {
+        CargoSpawn(uid, component);
+    }
+
+    private void CargoSpawn(EntityUid uid, StationCargoShuttleComponent component)
+    {
+        if (!_cfg.GetCVar(CCVars.GridFill))
+            return;
+
+        if (!TryComp(uid, out StationDataComponent? dataComp))
+            return;
+
+        var targetGrid = _station.GetLargestGrid(dataComp);
+
+        if (targetGrid == null)
+            return;
+
+        var mapId = _mapManager.CreateMap();
+
+        if (_loader.TryLoad(mapId, component.Path.ToString(), out var ent) && ent.Count > 0)
+        {
+            if (TryComp<ShuttleComponent>(ent[0], out var shuttle))
+            {
+                TryFTLProximity(ent[0], shuttle, targetGrid.Value);
+            }
+
+            _station.AddGridToStation(uid, ent[0]);
+        }
+
+        _mapManager.DeleteMap(mapId);
+    }
+
     private void GridSpawns(EntityUid uid, GridSpawnComponent component)
     {
         if (!_cfg.GetCVar(CCVars.GridFill))
index 503fd7082d5421c09d9e9f07c537ab7297c7836e..571469253b83d8008fa96c79a650acccd560f69a 100644 (file)
   id: BaseStationShuttles
   abstract: true
   components:
+    - type: StationCargoShuttle
+      path: /Maps/Shuttles/cargo.yml
     - type: GridSpawn
       groups:
-        cargo:
-          paths:
-          - /Maps/Shuttles/cargo.yml
         mining:
           paths:
           - /Maps/Shuttles/mining.yml