Mining 6 C1-C3: Zone.CargoGained, published by Extract and TryPickUp; HaulFeed words and hold fill
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ae64dbce2c
commit
149c513269
4 changed files with 76 additions and 1 deletions
|
|
@ -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<ItemData>(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<ItemData>(key), Lot = lot, Stored = counts[i] - adrift, Adrift = adrift, Kind = GainKind.Mined
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
47
Assets/Scripts/ServerShared/HaulFeed.cs
Normal file
47
Assets/Scripts/ServerShared/HaulFeed.cs
Normal file
|
|
@ -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<ItemData> 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<EquippedCargoBay>());
|
||||
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<EquippedCargoBay> 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/HaulFeed.cs.meta
Normal file
11
Assets/Scripts/ServerShared/HaulFeed.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d3ef606ec5240119cbb3d7dd51123d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -90,6 +90,8 @@ public class Zone
|
|||
public Subject<ShotOutcome> ShotResolved = new Subject<ShotOutcome>();
|
||||
// Contacts.Step publishes each hull-on-hull contact it resolves; presentations are the only readers.
|
||||
public Subject<ContactEvent> Contacted = new Subject<ContactEvent>();
|
||||
// Published by FireControl.Extract and TryPickUp once ore or an item enters (or is offered to) a hold; read by presentations only.
|
||||
public Subject<CargoGain> CargoGained = new Subject<CargoGain>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue