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 System.Linq;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
@@ -33,7 +34,7 @@ namespace Content.Shared.Damage
// container prototype
foreach (var type in damageContainerPrototype.SupportedTypes)
{
component.Damage.DamageDict.TryAdd(type, 0);
component.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
}
foreach (var groupID in damageContainerPrototype.SupportedGroups)
@@ -41,7 +42,7 @@ namespace Content.Shared.Damage
var group = _prototypeManager.Index<DamageGroupPrototype>(groupID);
foreach (var type in group.DamageTypes)
{
component.Damage.DamageDict.TryAdd(type, 0);
component.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
}
}
}
@@ -50,7 +51,7 @@ namespace Content.Shared.Damage
// No DamageContainerPrototype was given. So we will allow the container to support all damage types
foreach (var type in _prototypeManager.EnumeratePrototypes<DamageTypePrototype>())
{
component.Damage.DamageDict.TryAdd(type.ID, 0);
component.Damage.DamageDict.TryAdd(type.ID, FixedPoint2.Zero);
}
}
@@ -143,7 +144,7 @@ namespace Content.Shared.Damage
DamageSpecifier oldDamage = new(damageable.Damage);
damageable.Damage.ExclusiveAdd(damage);
damageable.Damage.ClampMin(0);
damageable.Damage.ClampMin(FixedPoint2.Zero);
var delta = damageable.Damage - oldDamage;
delta.TrimZeros();
@@ -162,7 +163,7 @@ namespace Content.Shared.Damage
/// <remakrs>
/// Does nothing If the given damage value is negative.
/// </remakrs>
public void SetAllDamage(DamageableComponent component, int newValue)
public void SetAllDamage(DamageableComponent component, FixedPoint2 newValue)
{
if (newValue < 0)
{