FireControl.Extract stamps every mined stack with the Extracted lot of its zone, belt and ore
Extracted gains Body at key 2. ItemManager.ExtractedLot finds or mints the lot; its (zone, belt, ore) index is derived from the ledger at construction and never saved. SavedGame roots skip null items and Lot 0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
00a036427d
commit
df67c875e3
4 changed files with 34 additions and 3 deletions
|
|
@ -1864,14 +1864,17 @@ public static class FireControl
|
|||
|
||||
var at = zone.ChunkPose(chunk.Field, chunk.Index).xy;
|
||||
var velocity = zone.ChunkVelocity(chunk);
|
||||
var zoneIndex = zone.Galaxy?.Zones == null ? -1 : Array.IndexOf(zone.Galaxy.Zones, zone.GalaxyZone);
|
||||
var present = zone.Entities.Contains(shooter);
|
||||
for (var i = 0; i < ores.Length; i++)
|
||||
{
|
||||
var key = ores[i].Commodity.Key;
|
||||
var maxStack = Math.Max(1, ((SimpleCommodityData) catalog.Get(ores[i].Commodity)).MaxStack);
|
||||
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;
|
||||
for (var left = counts[i]; left > 0; left -= maxStack)
|
||||
{
|
||||
var stack = new SimpleCommodity { Data = new CultRecordRef<ItemData>(key), Quantity = Math.Min(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;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ public class ItemManager
|
|||
|
||||
public CultCache ItemData { get; }
|
||||
public ProvenanceLedger Lots { get; }
|
||||
|
||||
// (zone index, belt, commodity) -> the Extracted lot minted for it. Derived from Lots at construction and on mint,
|
||||
// never persisted: a reload rebuilds it from the ledger, so the same source finds the same lot.
|
||||
private readonly Dictionary<(int, CultRecordKey, CultRecordKey), int> _extracted =
|
||||
new Dictionary<(int, CultRecordKey, CultRecordKey), int>();
|
||||
public GameplaySettings GameplaySettings { get; }
|
||||
|
||||
public ItemManager(uint seed, CultCache itemData, ProvenanceLedger lots, GameplaySettings settings, Action<string> logger)
|
||||
|
|
@ -33,6 +38,9 @@ public class ItemManager
|
|||
Random = new Random(seed);
|
||||
ItemData = itemData;
|
||||
Lots = lots;
|
||||
foreach (var (id, lot) in lots.Lots)
|
||||
if (lot.Origin is Extracted extracted)
|
||||
_extracted[(extracted.Zone, extracted.Body.Key, extracted.Commodity.Key)] = id;
|
||||
GameplaySettings = settings;
|
||||
_logger = logger;
|
||||
}
|
||||
|
|
@ -181,6 +189,24 @@ public class ItemManager
|
|||
return Lots.Add(lot);
|
||||
}
|
||||
|
||||
// Mining Cut 5b: the lot of every unit mined from one commodity in one belt of one zone, found or minted. Unbranded
|
||||
// (Product unset) and unworked (Quality 1, no roles). FireControl.Extract is the only caller.
|
||||
public int ExtractedLot(int zone, CultRecordKey belt, SimpleCommodityData commodity)
|
||||
{
|
||||
var key = (zone, belt, ItemData.RefOf<ItemData>(commodity).Key);
|
||||
if (_extracted.TryGetValue(key, out var found)) return found;
|
||||
var id = Lots.Add(new Lot
|
||||
{
|
||||
Design = ItemData.RefOf<ItemData>(commodity),
|
||||
Origin = new Extracted
|
||||
{
|
||||
Zone = zone, Body = new CultRecordRef<BodyData>(belt), Commodity = ItemData.RefOf(commodity)
|
||||
},
|
||||
Quality = 1
|
||||
});
|
||||
return _extracted[key] = id;
|
||||
}
|
||||
|
||||
// The one writer of a crafted instance's Data: copied from the lot's design, never independently set.
|
||||
public CraftedItemInstance CreateInstance(int lot)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -137,6 +137,8 @@ public class Produced : Provenance
|
|||
[MessagePackObject]
|
||||
public class Extracted : Provenance
|
||||
{
|
||||
// Zone is the zone's index in galaxy.Zones (SavedGame's convention), -1 with no galaxy; Body is the belt.
|
||||
[Key(0)] public int Zone;
|
||||
[Key(1)] public CultRecordRef<SimpleCommodityData> Commodity;
|
||||
[Key(2)] public CultRecordRef<BodyData> Body;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ public static class RunSave
|
|||
var roots = zones
|
||||
.SelectMany(zone => zone.Contents?.Entities ?? new List<EntityPack>())
|
||||
.SelectMany(EntitySerializer.Items)
|
||||
.Where(item => item.Lot != 0)
|
||||
.Where(item => item != null && item.Lot != 0)
|
||||
.Select(item => item.Lot);
|
||||
cache.Commit(batch =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue