Fix AddReagent modifying to solution being added in some cases (#40959)

fix
This commit is contained in:
slarticodefast
2025-10-18 19:06:08 +02:00
committed by GitHub
parent ae349a446a
commit ccd47a00a3
2 changed files with 33 additions and 26 deletions

View File

@@ -588,7 +588,7 @@ public abstract partial class SharedSolutionContainerSystem : EntitySystem
/// Adds a solution to the container, if it can fully fit.
/// </summary>
/// <param name="targetUid">entity holding targetSolution</param>
/// <param name="targetSolution">entity holding targetSolution</param>
/// <param name="targetSolution">entity holding targetSolution</param>
/// <param name="toAdd">solution being added</param>
/// <returns>If the solution could be added.</returns>
public bool TryAddSolution(Entity<SolutionComponent> soln, Solution toAdd)
@@ -606,40 +606,44 @@ public abstract partial class SharedSolutionContainerSystem : EntitySystem
}
/// <summary>
/// Adds as much of a solution to a container as can fit.
/// Adds as much of a solution to a container as can fit and updates the container.
/// </summary>
/// <param name="targetUid">The entity containing <paramref cref="targetSolution"/></param>
/// <param name="targetSolution">The solution being added to.</param>
/// <param name="toAdd">The solution being added to <paramref cref="targetSolution"/></param>
/// <param name="toAdd">The solution being added to <paramref cref="targetSolution"/>. This solution is not modified.</param>
/// <returns>The quantity of the solution actually added.</returns>
public FixedPoint2 AddSolution(Entity<SolutionComponent> soln, Solution toAdd)
{
var (uid, comp) = soln;
var solution = comp.Solution;
var solution = soln.Comp.Solution;
if (toAdd.Volume == FixedPoint2.Zero)
return FixedPoint2.Zero;
var quantity = FixedPoint2.Max(FixedPoint2.Zero, FixedPoint2.Min(toAdd.Volume, solution.AvailableVolume));
if (quantity < toAdd.Volume)
TryTransferSolution(soln, toAdd, quantity);
{
// TODO: This should be made into a function that directly transfers reagents.
// Currently this is quite inefficient.
solution.AddSolution(toAdd.Clone().SplitSolution(quantity), PrototypeManager);
}
else
ForceAddSolution(soln, toAdd);
solution.AddSolution(toAdd, PrototypeManager);
UpdateChemicals(soln);
return quantity;
}
/// <summary>
/// Adds a solution to a container and updates the container.
/// This can exceed the maximum volume of the solution added to.
/// </summary>
/// <param name="targetUid">The entity containing <paramref cref="targetSolution"/></param>
/// <param name="targetSolution">The solution being added to.</param>
/// <param name="toAdd">The solution being added to <paramref cref="targetSolution"/></param>
/// <param name="toAdd">The solution being added to <paramref cref="targetSolution"/>. This solution is not modified.</param>
/// <returns>Whether any reagents were added to the solution.</returns>
public bool ForceAddSolution(Entity<SolutionComponent> soln, Solution toAdd)
{
var (uid, comp) = soln;
var solution = comp.Solution;
var solution = soln.Comp.Solution;
if (toAdd.Volume == FixedPoint2.Zero)
return false;