]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Made ordering multiple crates at cargo order multiple crates (#25518)
authorFlesh <62557990+PolterTzi@users.noreply.github.com>
Sun, 25 Feb 2024 07:36:22 +0000 (08:36 +0100)
committerGitHub <noreply@github.com>
Sun, 25 Feb 2024 07:36:22 +0000 (18:36 +1100)
* please tell me this is empty

* it wasn't empty, fixing that

* This should fix it

* fix for the fix

* address changes

* fix

* Added some comments, hoping that failed test was a fluke.

Content.Server/Cargo/Systems/CargoSystem.Orders.cs
Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs

index a4daeb8c2d40208fde6f3938e97d3d6461d69e1c..5ecba411336113e14b88e3e0b03cad311b8236e4 100644 (file)
@@ -209,15 +209,19 @@ namespace Content.Server.Cargo.Systems
                 _random.Shuffle(tradePads);
 
                 var freePads = GetFreeCargoPallets(trade, tradePads);
-
-                foreach (var pad in freePads)
+                if (freePads.Count >= order.OrderQuantity) //check if the station has enough free pallets
                 {
-                    var coordinates = new EntityCoordinates(trade, pad.Transform.LocalPosition);
-
-                    if (FulfillOrder(order, coordinates, orderDatabase.PrinterOutput))
+                    foreach (var pad in freePads)
                     {
-                        tradeDestination = trade;
-                        break;
+                        var coordinates = new EntityCoordinates(trade, pad.Transform.LocalPosition);
+
+                        if (FulfillOrder(order, coordinates, orderDatabase.PrinterOutput))
+                        {
+                            tradeDestination = trade;
+                            order.NumDispatched++;
+                            if (order.OrderQuantity <= order.NumDispatched) //Spawn a crate on free pellets until the order is fulfilled.
+                                break;
+                        }
                     }
                 }
 
index 8a661c8896def347a5577881fd73a979582868e4..98ab633f4dae0ee00b45ba8ee09ac164685ec653 100644 (file)
@@ -196,12 +196,14 @@ public sealed partial class CargoSystem
         return _pads;
     }
 
-    private IEnumerable<(EntityUid Entity, CargoPalletComponent Component, TransformComponent Transform)>
+    private List<(EntityUid Entity, CargoPalletComponent Component, TransformComponent Transform)>
         GetFreeCargoPallets(EntityUid gridUid,
             List<(EntityUid Entity, CargoPalletComponent Component, TransformComponent Transform)> pallets)
     {
         _setEnts.Clear();
 
+        List<(EntityUid Entity, CargoPalletComponent Component, TransformComponent Transform)> outList = new();
+
         foreach (var pallet in pallets)
         {
             var aabb = _lookup.GetAABBNoContainer(pallet.Entity, pallet.Transform.LocalPosition, pallet.Transform.LocalRotation);
@@ -209,8 +211,10 @@ public sealed partial class CargoSystem
             if (_lookup.AnyLocalEntitiesIntersecting(gridUid, aabb, LookupFlags.Dynamic))
                 continue;
 
-            yield return pallet;
+            outList.Add(pallet);
         }
+
+        return outList;
     }
 
     #endregion