Generalize ReagentUnit into FixedPoint2 and use it for damage calculations (#5151)

* Damage units

* sum ext method
This commit is contained in:
mirrorcult
2021-11-03 16:48:03 -07:00
committed by GitHub
parent 8165d8f38c
commit 3ab4a30a0f
100 changed files with 730 additions and 601 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
@@ -29,9 +30,9 @@ namespace Content.Shared.Chemistry.Reaction
/// <param name="reaction">The reaction to check.</param>
/// <param name="lowestUnitReactions">How many times this reaction can occur.</param>
/// <returns></returns>
private static bool CanReact(Solution solution, ReactionPrototype reaction, out ReagentUnit lowestUnitReactions)
private static bool CanReact(Solution solution, ReactionPrototype reaction, out FixedPoint2 lowestUnitReactions)
{
lowestUnitReactions = ReagentUnit.MaxValue;
lowestUnitReactions = FixedPoint2.MaxValue;
foreach (var reactantData in reaction.Reactants)
{
@@ -55,7 +56,7 @@ namespace Content.Shared.Chemistry.Reaction
/// Perform a reaction on a solution. This assumes all reaction criteria are met.
/// Removes the reactants from the solution, then returns a solution with all products.
/// </summary>
private Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, ReagentUnit unitReactions)
private Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, FixedPoint2 unitReactions)
{
//Remove reactants
foreach (var reactant in reaction.Reactants)
@@ -80,7 +81,7 @@ namespace Content.Shared.Chemistry.Reaction
return products;
}
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions)
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, FixedPoint2 unitReactions)
{
foreach (var effect in reaction.Effects)
{
@@ -130,7 +131,7 @@ namespace Content.Shared.Chemistry.Reaction
/// Continually react a solution until no more reactions occur, with a volume constraint.
/// If a reaction's products would exceed the max volume, some product is deleted.
/// </summary>
public void FullyReactSolution(Solution solution, IEntity owner, ReagentUnit maxVolume)
public void FullyReactSolution(Solution solution, IEntity owner, FixedPoint2 maxVolume)
{
for (var i = 0; i < MaxReactionIterations; i++)
{