From aa4e7c061939fbe314be97a2e7f559477b941c07 Mon Sep 17 00:00:00 2001 From: Flesh <62557990+PolterTzi@users.noreply.github.com> Date: Sun, 25 Feb 2024 08:36:22 +0100 Subject: [PATCH] Made ordering multiple crates at cargo order multiple crates (#25518) * 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. --- .../Cargo/Systems/CargoSystem.Orders.cs | 18 +++++++++++------- .../Cargo/Systems/CargoSystem.Shuttle.cs | 8 ++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs index a4daeb8c2d..5ecba41133 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs @@ -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; + } } } diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index 8a661c8896..98ab633f4d 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -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 -- 2.52.0