diff --git a/Assets/Scripts/ServerShared/FireControl.cs b/Assets/Scripts/ServerShared/FireControl.cs index bb6d48d6c..9102b16eb 100644 --- a/Assets/Scripts/ServerShared/FireControl.cs +++ b/Assets/Scripts/ServerShared/FireControl.cs @@ -1872,14 +1872,24 @@ public static class FireControl var commodity = (SimpleCommodityData) catalog.Get(ores[i].Commodity); var maxStack = Math.Max(1, commodity.MaxStack); var lot = counts[i] > 0 ? shooter.ItemManager.ExtractedLot(zoneIndex, chunk.Field, commodity) : 0; + var adrift = 0; for (var left = counts[i]; left > 0; left -= maxStack) { var stack = new SimpleCommodity { Data = new CultRecordRef(key), Lot = lot, Quantity = Math.Min(left, maxStack) }; // A partial store leaves the remainder in Quantity and returns false, so the next bay is offered the rest. var stored = false; if (present) foreach (var bay in shooter.CargoBays) if (stored = bay.TryStore(stack)) break; - if (!stored) zone.Release(stack, at, velocity); + if (!stored) + { + adrift += stack.Quantity; + zone.Release(stack, at, velocity); + } } + if (counts[i] > 0) + zone.CargoGained.OnNext(new CargoGain + { + Taker = shooter, Design = new CultRecordRef(key), Lot = lot, Stored = counts[i] - adrift, Adrift = adrift, Kind = GainKind.Mined + }); } } diff --git a/Assets/Scripts/ServerShared/HaulFeed.cs b/Assets/Scripts/ServerShared/HaulFeed.cs new file mode 100644 index 000000000..b6f4055c8 --- /dev/null +++ b/Assets/Scripts/ServerShared/HaulFeed.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Linq; +using GameCult.Caching; + +public enum GainKind { Mined, Collected } + +// One entry into a hold: what Extract stored (and let float) of one ore, or what a pickup collected. Stored plus Adrift is +// the units; a pickup has Adrift 0. Published on Zone.CargoGained by its two writers and read by presentations only. +public struct CargoGain +{ + public Entity Taker; + public CultRecordRef Design; + public int Lot; + public int Stored; + public int Adrift; + public GainKind Kind; +} + +// The words for a cargo gain, and the taker's hold fill. Nothing here is stored: the line and the fill are derived on +// every call. +public static class HaulFeed +{ + public static string Line(CargoGain gain, ItemManager items) + { + var name = items.ItemData.Get(gain.Design).Name; + var (used, total) = HoldFill(gain.Taker?.CargoBays ?? Enumerable.Empty()); + var hold = $"(hold {used}/{total})"; + if (gain.Kind == GainKind.Collected) return $"Collected {gain.Stored} {name} {hold}"; + return gain.Adrift > 0 + ? $"+{gain.Stored} {name}, {gain.Adrift} adrift {hold}" + : $"+{gain.Stored} {name} {hold}"; + } + + // Occupied cells over the bays' interiors, a multi-cell item counted per cell. + public static (int used, int total) HoldFill(IEnumerable bays) + { + int used = 0, total = 0; + foreach (var bay in bays) + foreach (var v in bay.Data.InteriorShape.AllCoordinates) + { + if (!bay.Data.InteriorShape[v]) continue; + total++; + if (bay.Occupancy[v.x, v.y] != null) used++; + } + return (used, total); + } +} diff --git a/Assets/Scripts/ServerShared/HaulFeed.cs.meta b/Assets/Scripts/ServerShared/HaulFeed.cs.meta new file mode 100644 index 000000000..b9b4b88b6 --- /dev/null +++ b/Assets/Scripts/ServerShared/HaulFeed.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d3ef606ec5240119cbb3d7dd51123d9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index 7cbde82ef..0d729d2be 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -90,6 +90,8 @@ public class Zone public Subject ShotResolved = new Subject(); // Contacts.Step publishes each hull-on-hull contact it resolves; presentations are the only readers. public Subject Contacted = new Subject(); + // Published by FireControl.Extract and TryPickUp once ore or an item enters (or is offered to) a hold; read by presentations only. + public Subject CargoGained = new Subject(); private int _nextShotId; public int NextShotId() => ++_nextShotId; @@ -443,6 +445,11 @@ public class Zone if (floating == null || (floating.Holder != null && !ReferenceEquals(floating.Holder, taker))) return false; if (!taker.CargoBays.Any(bay => bay.TryStore(floating.Item))) return false; FloatingItems.Remove(floating); + CargoGained.OnNext(new CargoGain + { + Taker = taker, Design = floating.Item.Data, Lot = floating.Item.Lot, Kind = GainKind.Collected, + Stored = floating.Item is SimpleCommodity stack ? stack.Quantity : 1 + }); return true; }