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

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Cloning;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
@@ -22,8 +23,8 @@ namespace Content.Shared.Chemistry.Components
{
public readonly bool HasPower;
public readonly bool HasBeaker;
public readonly ReagentUnit BeakerCurrentVolume;
public readonly ReagentUnit BeakerMaxVolume;
public readonly FixedPoint2 BeakerCurrentVolume;
public readonly FixedPoint2 BeakerMaxVolume;
public readonly string ContainerName;
/// <summary>
@@ -38,10 +39,10 @@ namespace Content.Shared.Chemistry.Components
public readonly bool BufferModeTransfer;
public readonly ReagentUnit BufferCurrentVolume;
public readonly FixedPoint2 BufferCurrentVolume;
public ChemMasterBoundUserInterfaceState(bool hasPower, bool hasBeaker, ReagentUnit beakerCurrentVolume, ReagentUnit beakerMaxVolume, string containerName,
string dispenserName, IReadOnlyList<Solution.ReagentQuantity> containerReagents, IReadOnlyList<Solution.ReagentQuantity> bufferReagents, bool bufferModeTransfer, ReagentUnit bufferCurrentVolume)
public ChemMasterBoundUserInterfaceState(bool hasPower, bool hasBeaker, FixedPoint2 beakerCurrentVolume, FixedPoint2 beakerMaxVolume, string containerName,
string dispenserName, IReadOnlyList<Solution.ReagentQuantity> containerReagents, IReadOnlyList<Solution.ReagentQuantity> bufferReagents, bool bufferModeTransfer, FixedPoint2 bufferCurrentVolume)
{
HasPower = hasPower;
HasBeaker = hasBeaker;
@@ -63,13 +64,13 @@ namespace Content.Shared.Chemistry.Components
public class UiActionMessage : BoundUserInterfaceMessage
{
public readonly UiAction action;
public readonly ReagentUnit amount;
public readonly FixedPoint2 amount;
public readonly string id = "";
public readonly bool isBuffer;
public readonly int pillAmount;
public readonly int bottleAmount;
public UiActionMessage(UiAction _action, ReagentUnit? _amount, string? _id, bool? _isBuffer, int? _pillAmount, int? _bottleAmount)
public UiActionMessage(UiAction _action, FixedPoint2? _amount, string? _id, bool? _isBuffer, int? _pillAmount, int? _bottleAmount)
{
action = _action;
if (action == UiAction.ChemButton)

View File

@@ -1,5 +1,6 @@
using System;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
@@ -15,10 +16,10 @@ namespace Content.Shared.Chemistry.Components
[Serializable, NetSerializable]
protected sealed class HyposprayComponentState : ComponentState
{
public ReagentUnit CurVolume { get; }
public ReagentUnit MaxVolume { get; }
public FixedPoint2 CurVolume { get; }
public FixedPoint2 MaxVolume { get; }
public HyposprayComponentState(ReagentUnit curVolume, ReagentUnit maxVolume)
public HyposprayComponentState(FixedPoint2 curVolume, FixedPoint2 maxVolume)
{
CurVolume = curVolume;
MaxVolume = maxVolume;

View File

@@ -1,5 +1,6 @@
using System;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
@@ -20,11 +21,11 @@ namespace Content.Shared.Chemistry.Components
[Serializable, NetSerializable]
protected sealed class InjectorComponentState : ComponentState
{
public ReagentUnit CurrentVolume { get; }
public ReagentUnit TotalVolume { get; }
public FixedPoint2 CurrentVolume { get; }
public FixedPoint2 TotalVolume { get; }
public InjectorToggleMode CurrentMode { get; }
public InjectorComponentState(ReagentUnit currentVolume, ReagentUnit totalVolume, InjectorToggleMode currentMode)
public InjectorComponentState(FixedPoint2 currentVolume, FixedPoint2 totalVolume, InjectorToggleMode currentMode)
{
CurrentVolume = currentVolume;
TotalVolume = totalVolume;

View File

@@ -1,4 +1,5 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -18,10 +19,10 @@ namespace Content.Shared.Chemistry.Components
/// Volume needed to fill this container.
/// </summary>
[ViewVariables]
public ReagentUnit AvailableVolume => MaxVolume - CurrentVolume;
public FixedPoint2 AvailableVolume => MaxVolume - CurrentVolume;
public ReagentUnit DrawAvailable => CurrentVolume;
public ReagentUnit DrainAvailable => CurrentVolume;
public FixedPoint2 DrawAvailable => CurrentVolume;
public FixedPoint2 DrainAvailable => CurrentVolume;
/// <summary>
/// Checks if a solution can fit into the container.
@@ -34,18 +35,18 @@ namespace Content.Shared.Chemistry.Components
}
[DataField("maxSpillRefill")]
public ReagentUnit MaxSpillRefill { get; set; }
public FixedPoint2 MaxSpillRefill { get; set; }
/// <summary>
/// Initially set <see cref="MaxVolume"/>. If empty will be calculated based
/// on sum of <see cref="Contents"/> reagent units.
/// on sum of <see cref="Contents"/> fixed units.
/// </summary>
[DataField("maxVol")] public ReagentUnit InitialMaxVolume;
[DataField("maxVol")] public FixedPoint2 InitialMaxVolume;
[ViewVariables(VVAccess.ReadWrite)]
public ReagentUnit MaxVolume { get; set; } = ReagentUnit.Zero;
public FixedPoint2 MaxVolume { get; set; } = FixedPoint2.Zero;
[ViewVariables]
public ReagentUnit CurrentVolume => TotalVolume;
public FixedPoint2 CurrentVolume => TotalVolume;
}
}

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
@@ -32,7 +33,7 @@ namespace Content.Shared.Chemistry.Components
/// The calculated total volume of all reagents in the solution (ex. Total volume of liquid in beaker).
/// </summary>
[ViewVariables]
public ReagentUnit TotalVolume { get; set; }
public FixedPoint2 TotalVolume { get; set; }
public Color Color => GetColor();
@@ -46,14 +47,14 @@ namespace Content.Shared.Chemistry.Components
/// </summary>
/// <param name="reagentId">The prototype ID of the reagent to add.</param>
/// <param name="quantity">The quantity in milli-units.</param>
public Solution(string reagentId, ReagentUnit quantity)
public Solution(string reagentId, FixedPoint2 quantity)
{
AddReagent(reagentId, quantity);
}
void ISerializationHooks.AfterDeserialization()
{
TotalVolume = ReagentUnit.Zero;
TotalVolume = FixedPoint2.Zero;
Contents.ForEach(reagent => TotalVolume += reagent.Quantity);
}
@@ -62,7 +63,7 @@ namespace Content.Shared.Chemistry.Components
return ContainsReagent(reagentId, out _);
}
public bool ContainsReagent(string reagentId, out ReagentUnit quantity)
public bool ContainsReagent(string reagentId, out FixedPoint2 quantity)
{
foreach (var reagent in Contents)
{
@@ -73,7 +74,7 @@ namespace Content.Shared.Chemistry.Components
}
}
quantity = ReagentUnit.New(0);
quantity = FixedPoint2.New(0);
return false;
}
@@ -93,7 +94,7 @@ namespace Content.Shared.Chemistry.Components
/// </summary>
/// <param name="reagentId">The prototype ID of the reagent to add.</param>
/// <param name="quantity">The quantity in milli-units.</param>
public void AddReagent(string reagentId, ReagentUnit quantity)
public void AddReagent(string reagentId, FixedPoint2 quantity)
{
if (quantity <= 0)
return;
@@ -139,7 +140,7 @@ namespace Content.Shared.Chemistry.Components
/// </summary>
/// <param name="reagentId">The prototype ID of the reagent to add.</param>
/// <returns>The quantity in milli-units.</returns>
public ReagentUnit GetReagentQuantity(string reagentId)
public FixedPoint2 GetReagentQuantity(string reagentId)
{
for (var i = 0; i < Contents.Count; i++)
{
@@ -147,10 +148,10 @@ namespace Content.Shared.Chemistry.Components
return Contents[i].Quantity;
}
return ReagentUnit.New(0);
return FixedPoint2.New(0);
}
public void RemoveReagent(string reagentId, ReagentUnit quantity)
public void RemoveReagent(string reagentId, FixedPoint2 quantity)
{
if(quantity <= 0)
return;
@@ -183,7 +184,7 @@ namespace Content.Shared.Chemistry.Components
/// Remove the specified quantity from this solution.
/// </summary>
/// <param name="quantity">The quantity of this solution to remove</param>
public void RemoveSolution(ReagentUnit quantity)
public void RemoveSolution(FixedPoint2 quantity)
{
if(quantity <= 0)
return;
@@ -214,10 +215,10 @@ namespace Content.Shared.Chemistry.Components
public void RemoveAllSolution()
{
Contents.Clear();
TotalVolume = ReagentUnit.New(0);
TotalVolume = FixedPoint2.New(0);
}
public Solution SplitSolution(ReagentUnit quantity)
public Solution SplitSolution(FixedPoint2 quantity)
{
if (quantity <= 0)
return new Solution();
@@ -232,7 +233,7 @@ namespace Content.Shared.Chemistry.Components
}
newSolution = new Solution();
var newTotalVolume = ReagentUnit.New(0);
var newTotalVolume = FixedPoint2.New(0);
var remainingVolume = TotalVolume;
for (var i = 0; i < Contents.Count; i++)
@@ -291,7 +292,7 @@ namespace Content.Shared.Chemistry.Components
}
Color mixColor = default;
var runningTotalQuantity = ReagentUnit.New(0);
var runningTotalQuantity = FixedPoint2.New(0);
var protoManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var reagent in Contents)
@@ -317,7 +318,7 @@ namespace Content.Shared.Chemistry.Components
public Solution Clone()
{
var volume = ReagentUnit.New(0);
var volume = FixedPoint2.New(0);
var newSolution = new Solution();
for (var i = 0; i < Contents.Count; i++)
@@ -348,9 +349,9 @@ namespace Content.Shared.Chemistry.Components
[DataField("ReagentId", customTypeSerializer:typeof(PrototypeIdSerializer<ReagentPrototype>))]
public readonly string ReagentId;
[DataField("Quantity")]
public readonly ReagentUnit Quantity;
public readonly FixedPoint2 Quantity;
public ReagentQuantity(string reagentId, ReagentUnit quantity)
public ReagentQuantity(string reagentId, FixedPoint2 quantity)
{
ReagentId = reagentId;
Quantity = quantity;
@@ -364,7 +365,7 @@ namespace Content.Shared.Chemistry.Components
public int CompareTo(ReagentQuantity other) { return Quantity.Float().CompareTo(other.Quantity.Float()); }
public void Deconstruct(out string reagentId, out ReagentUnit quantity)
public void Deconstruct(out string reagentId, out FixedPoint2 quantity)
{
reagentId = ReagentId;
quantity = Quantity;