Allow solutions to store extra reagent data (#19323)

This commit is contained in:
Leon Friedrich
2023-09-05 09:55:10 +12:00
committed by GitHub
parent a6b81058d0
commit e4ca6f4fb9
52 changed files with 932 additions and 538 deletions

View File

@@ -220,14 +220,16 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
if (!Resolve(reclaimer, ref reclaimerComponent, ref xform))
return;
var overflow = new Solution();
var totalChemicals = new Dictionary<string, FixedPoint2>();
efficiency *= reclaimerComponent.Efficiency;
var totalChemicals = new Solution();
if (Resolve(item, ref composition, false))
{
foreach (var (key, value) in composition.ChemicalComposition)
{
totalChemicals[key] = totalChemicals.GetValueOrDefault(key) + value;
// TODO use ReagentQuantity
totalChemicals.AddReagent(key, value * efficiency, false);
}
}
@@ -238,27 +240,15 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
{
foreach (var quantity in solution.Contents)
{
totalChemicals[quantity.ReagentId] =
totalChemicals.GetValueOrDefault(quantity.ReagentId) + quantity.Quantity;
totalChemicals.AddReagent(quantity.Reagent.Prototype, quantity.Quantity * efficiency, false);
}
}
}
foreach (var (reagent, amount) in totalChemicals)
_solutionContainer.TryTransferSolution(reclaimer, reclaimerComponent.OutputSolution, totalChemicals, totalChemicals.Volume);
if (totalChemicals.Volume > 0)
{
var outputAmount = amount * efficiency * reclaimerComponent.Efficiency;
_solutionContainer.TryAddReagent(reclaimer, reclaimerComponent.OutputSolution, reagent, outputAmount,
out var accepted);
var overflowAmount = outputAmount - accepted;
if (overflowAmount > 0)
{
overflow.AddReagent(reagent, overflowAmount);
}
}
if (overflow.Volume > 0)
{
_puddle.TrySpillAt(reclaimer, overflow, out _, transformComponent: xform);
_puddle.TrySpillAt(reclaimer, totalChemicals, out _, transformComponent: xform);
}
}
}