Skip to content

Commit

Permalink
SplitSolutionPerReagent: suggested fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
whatston3 committed Jun 18, 2024
1 parent 666fd57 commit d2ef2a8
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions Content.Shared/Chemistry/Components/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public Solution SplitSolution(FixedPoint2 toTake)
return newSolution;
}

// Frontier: cryogenics per-reagent filter function (#1443)
// Frontier: cryogenics per-reagent filter function (#1443, #1533)
/// <summary>
/// Splits a solution, taking the specified amount of each reagent from the solution.
/// If any reagent in the solution has less volume than specified, it will all be transferred into the new solution.
Expand Down Expand Up @@ -704,13 +704,26 @@ public Solution SplitSolutionPerReagent(FixedPoint2 toTakePer)
else
{
Contents.RemoveSwap(i);
newSolution.Contents.Add(new ReagentQuantity(reagent, quantity));
Volume -= quantity;
//Only add positive quantities to our new solution.
if (quantity > 0)
{
newSolution.Contents.Add(new ReagentQuantity(reagent, quantity));
Volume -= quantity;
}
}
}

newSolution.Volume = origVol - Volume;
_heatCapacityDirty = true;
// If old solution is empty, invalidate old solution and transfer all volume to new.
if (Volume <= 0)
{
RemoveAllSolution();
newSolution.Volume = origVol;
}
else
{
newSolution.Volume = origVol - Volume;
_heatCapacityDirty = true;
}
newSolution._heatCapacityDirty = true;

ValidateSolution();
Expand Down Expand Up @@ -751,13 +764,26 @@ public Solution SplitSolutionPerReagentWithOnly(FixedPoint2 toTakePer, params st
else
{
Contents.RemoveSwap(i);
newSolution.Contents.Add(new ReagentQuantity(reagent, quantity));
Volume -= quantity;
//Only add positive quantities to our new solution.
if (quantity > 0)
{
newSolution.Contents.Add(new ReagentQuantity(reagent, quantity));
Volume -= quantity;
}
}
}

newSolution.Volume = origVol - Volume;
_heatCapacityDirty = true;
// If old solution is empty, invalidate old solution and transfer all volume to new.
if (Volume <= 0)
{
RemoveAllSolution();
newSolution.Volume = origVol;
}
else
{
newSolution.Volume = origVol - Volume;
_heatCapacityDirty = true;
}
newSolution._heatCapacityDirty = true;

ValidateSolution();
Expand Down

0 comments on commit d2ef2a8

Please sign in to comment.