Generalize ReagentUnit into FixedPoint2 and use it for damage calculations (#5151)
* Damage units * sum ext method
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
@@ -26,12 +27,12 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
private List<EntityUid> _currentlyUsing = new();
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
public FixedPoint2 MaxVolume
|
||||
{
|
||||
get =>
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
? solution.MaxVolume
|
||||
: ReagentUnit.Zero;
|
||||
: FixedPoint2.Zero;
|
||||
set
|
||||
{
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
@@ -41,9 +42,9 @@ namespace Content.Server.Fluids.Components
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
public FixedPoint2 CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution)
|
||||
? solution.CurrentVolume
|
||||
: ReagentUnit.Zero;
|
||||
: FixedPoint2.Zero;
|
||||
|
||||
[DataField("sound")]
|
||||
private SoundSpecifier _sound = new SoundPathSpecifier("/Audio/Effects/Fluids/watersplash.ogg");
|
||||
@@ -93,7 +94,7 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
// Top up mops solution given it needs it to annihilate puddles I guess
|
||||
|
||||
var transferAmount = ReagentUnit.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
|
||||
var transferAmount = FixedPoint2.Min(mopComponent.MaxVolume - mopComponent.CurrentVolume, CurrentVolume);
|
||||
if (transferAmount == 0)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -13,7 +14,7 @@ namespace Content.Server.Fluids.Components
|
||||
public override string Name => "Evaporation";
|
||||
|
||||
/// <summary>
|
||||
/// The time that it will take this puddle to lose one reagent unit of solution, in seconds.
|
||||
/// The time that it will take this puddle to lose one fixed unit of solution, in seconds.
|
||||
/// </summary>
|
||||
[DataField("evaporateTime")]
|
||||
public float EvaporateTime { get; set; } = 5f;
|
||||
@@ -29,14 +30,14 @@ namespace Content.Server.Fluids.Components
|
||||
/// Defaults to evaporate completely.
|
||||
/// </summary>
|
||||
[DataField("lowerLimit")]
|
||||
public ReagentUnit LowerLimit = ReagentUnit.Zero;
|
||||
public FixedPoint2 LowerLimit = FixedPoint2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Upper limit below which puddle won't evaporate. Useful when wanting to make sure large puddle will
|
||||
/// remain forever. Defaults to <see cref="PuddleComponent.DefaultOverflowVolume"/>.
|
||||
/// </summary>
|
||||
[DataField("upperLimit")]
|
||||
public ReagentUnit UpperLimit = PuddleComponent.DefaultOverflowVolume;
|
||||
public FixedPoint2 UpperLimit = PuddleComponent.DefaultOverflowVolume;
|
||||
|
||||
/// <summary>
|
||||
/// The time accumulated since the start.
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.DoAfter;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
@@ -40,9 +41,9 @@ namespace Content.Server.Fluids.Components
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
public FixedPoint2 MaxVolume
|
||||
{
|
||||
get => MopSolution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
get => MopSolution?.MaxVolume ?? FixedPoint2.Zero;
|
||||
set
|
||||
{
|
||||
var solution = MopSolution;
|
||||
@@ -53,14 +54,14 @@ namespace Content.Server.Fluids.Components
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume => MopSolution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
public FixedPoint2 CurrentVolume => MopSolution?.CurrentVolume ?? FixedPoint2.Zero;
|
||||
|
||||
// Currently there's a separate amount for pickup and dropoff so
|
||||
// Picking up a puddle requires multiple clicks
|
||||
// Dumping in a bucket requires 1 click
|
||||
// Long-term you'd probably use a cooldown and start the pickup once we have some form of global cooldown
|
||||
[DataField("pickup_amount")]
|
||||
public ReagentUnit PickupAmount { get; } = ReagentUnit.New(5);
|
||||
public FixedPoint2 PickupAmount { get; } = FixedPoint2.New(5);
|
||||
|
||||
[DataField("pickup_sound")]
|
||||
private SoundSpecifier _pickupSound = new SoundPathSpecifier("/Audio/Effects/Fluids/slosh.ogg");
|
||||
@@ -136,7 +137,7 @@ namespace Content.Server.Fluids.Components
|
||||
return false;
|
||||
|
||||
// Annihilate the puddle
|
||||
var transferAmount = ReagentUnit.Min(ReagentUnit.New(5), puddleComponent.CurrentVolume, CurrentVolume);
|
||||
var transferAmount = FixedPoint2.Min(FixedPoint2.New(5), puddleComponent.CurrentVolume, CurrentVolume);
|
||||
var puddleCleaned = puddleComponent.CurrentVolume - transferAmount <= 0;
|
||||
|
||||
var puddleSystem = EntitySystem.Get<PuddleSystem>();
|
||||
@@ -146,7 +147,7 @@ namespace Content.Server.Fluids.Components
|
||||
if (puddleSystem.EmptyHolder(puddleComponent.Owner.Uid, puddleComponent)) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
||||
{
|
||||
puddleComponent.Owner.Delete();
|
||||
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);
|
||||
transferAmount = FixedPoint2.Min(FixedPoint2.New(5), CurrentVolume);
|
||||
puddleCleaned = true;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -16,8 +17,8 @@ namespace Content.Server.Fluids.Components
|
||||
public sealed class PuddleComponent : Component
|
||||
{
|
||||
public const string DefaultSolutionName = "puddle";
|
||||
private static readonly ReagentUnit DefaultSlipThreshold = ReagentUnit.New(3);
|
||||
public static readonly ReagentUnit DefaultOverflowVolume = ReagentUnit.New(20);
|
||||
private static readonly FixedPoint2 DefaultSlipThreshold = FixedPoint2.New(3);
|
||||
public static readonly FixedPoint2 DefaultOverflowVolume = FixedPoint2.New(20);
|
||||
|
||||
public override string Name => "Puddle";
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace Content.Server.Fluids.Components
|
||||
// to check for low volumes for evaporation or whatever
|
||||
|
||||
|
||||
[DataField("slipThreshold")] public ReagentUnit SlipThreshold = DefaultSlipThreshold;
|
||||
[DataField("slipThreshold")] public FixedPoint2 SlipThreshold = DefaultSlipThreshold;
|
||||
|
||||
[DataField("spillSound")]
|
||||
public SoundSpecifier SpillSound = new SoundPathSpecifier("/Audio/Effects/Fluids/splat.ogg");
|
||||
@@ -46,12 +47,12 @@ namespace Content.Server.Fluids.Components
|
||||
public bool Overflown;
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public ReagentUnit CurrentVolume => EntitySystem.Get<PuddleSystem>().CurrentVolume(Owner.Uid);
|
||||
public FixedPoint2 CurrentVolume => EntitySystem.Get<PuddleSystem>().CurrentVolume(Owner.Uid);
|
||||
|
||||
[ViewVariables] [DataField("overflowVolume")]
|
||||
public ReagentUnit OverflowVolume = DefaultOverflowVolume;
|
||||
public FixedPoint2 OverflowVolume = DefaultOverflowVolume;
|
||||
|
||||
public ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
|
||||
public FixedPoint2 OverflowLeft => CurrentVolume - OverflowVolume;
|
||||
|
||||
[DataField("solution")] public string SolutionName { get; set; } = DefaultSolutionName;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.Coordinates.Helpers;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -132,7 +133,7 @@ namespace Content.Server.Fluids.Components
|
||||
.TryGetRefillableSolution(spillEntity.Uid, out var solutionContainerComponent))
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().Refill(spillEntity.Uid, solutionContainerComponent,
|
||||
solution.SplitSolution(ReagentUnit.Min(
|
||||
solution.SplitSolution(FixedPoint2.Min(
|
||||
solutionContainerComponent.AvailableVolume,
|
||||
solutionContainerComponent.MaxSpillRefill))
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Cooldown;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Fluids;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
@@ -34,7 +35,7 @@ namespace Content.Server.Fluids.Components
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
[DataField("transferAmount")]
|
||||
private ReagentUnit _transferAmount = ReagentUnit.New(10);
|
||||
private FixedPoint2 _transferAmount = FixedPoint2.New(10);
|
||||
[DataField("sprayVelocity")]
|
||||
private float _sprayVelocity = 1.5f;
|
||||
[DataField("sprayAliveTime")]
|
||||
@@ -56,7 +57,7 @@ namespace Content.Server.Fluids.Components
|
||||
/// The amount of solution to be sprayer from this solution when using it
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public ReagentUnit TransferAmount
|
||||
public FixedPoint2 TransferAmount
|
||||
{
|
||||
get => _transferAmount;
|
||||
set => _transferAmount = value;
|
||||
@@ -75,11 +76,11 @@ namespace Content.Server.Fluids.Components
|
||||
[DataField("spraySound", required: true)]
|
||||
public SoundSpecifier SpraySound { get; } = default!;
|
||||
|
||||
public ReagentUnit CurrentVolume {
|
||||
public FixedPoint2 CurrentVolume {
|
||||
get
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution);
|
||||
return solution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
return solution?.CurrentVolume ?? FixedPoint2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
var solution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, _transferAmount);
|
||||
|
||||
if (solution.TotalVolume <= ReagentUnit.Zero)
|
||||
if (solution.TotalVolume <= FixedPoint2.Zero)
|
||||
break;
|
||||
|
||||
var vapor = entManager.SpawnEntity(_vaporPrototype, playerPos.Offset(distance < 1 ? quarter : threeQuarters));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -36,7 +37,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
|
||||
|
||||
_solutionContainerSystem.SplitSolution(uid, solution,
|
||||
ReagentUnit.Min(ReagentUnit.New(1), solution.CurrentVolume));
|
||||
FixedPoint2.Min(FixedPoint2.New(1), solution.CurrentVolume));
|
||||
|
||||
if (solution.CurrentVolume == 0)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Directions;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Fluids;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Physics;
|
||||
@@ -46,7 +47,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
private void OnInit(EntityUid uid, PuddleComponent component, ComponentInit args)
|
||||
{
|
||||
var solution = _solutionContainerSystem.EnsureSolution(uid, component.SolutionName);
|
||||
solution.MaxVolume = ReagentUnit.New(1000);
|
||||
solution.MaxVolume = FixedPoint2.New(1000);
|
||||
}
|
||||
|
||||
private void OnUpdate(EntityUid uid, PuddleComponent component, SolutionChangedEvent args)
|
||||
@@ -74,7 +75,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
|
||||
private void UpdateSlip(EntityUid entityUid, PuddleComponent puddleComponent)
|
||||
{
|
||||
if ((puddleComponent.SlipThreshold == ReagentUnit.New(-1) ||
|
||||
if ((puddleComponent.SlipThreshold == FixedPoint2.New(-1) ||
|
||||
puddleComponent.CurrentVolume < puddleComponent.SlipThreshold) &&
|
||||
EntityManager.TryGetComponent(entityUid, out SlipperyComponent? oldSlippery))
|
||||
{
|
||||
@@ -95,7 +96,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
if (!_solutionContainerSystem.TryGetDrainableSolution(args.Target.Uid, out var solution))
|
||||
return;
|
||||
|
||||
if (solution.DrainAvailable == ReagentUnit.Zero)
|
||||
if (solution.DrainAvailable == FixedPoint2.Zero)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
@@ -147,15 +148,15 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
|| solution.Contents.Count == 0;
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume(EntityUid uid, PuddleComponent? puddleComponent = null)
|
||||
public FixedPoint2 CurrentVolume(EntityUid uid, PuddleComponent? puddleComponent = null)
|
||||
{
|
||||
if (!Resolve(uid, ref puddleComponent))
|
||||
return ReagentUnit.Zero;
|
||||
return FixedPoint2.Zero;
|
||||
|
||||
return _solutionContainerSystem.TryGetSolution(puddleComponent.Owner.Uid, puddleComponent.SolutionName,
|
||||
out var solution)
|
||||
? solution.CurrentVolume
|
||||
: ReagentUnit.Zero;
|
||||
: FixedPoint2.Zero;
|
||||
}
|
||||
|
||||
public bool TryAddSolution(EntityUid uid, Solution solution,
|
||||
@@ -210,7 +211,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
var nextPuddles = new List<PuddleComponent>() { puddleComponent };
|
||||
var overflownPuddles = new List<PuddleComponent>();
|
||||
|
||||
while (puddleComponent.OverflowLeft > ReagentUnit.Zero && nextPuddles.Count > 0)
|
||||
while (puddleComponent.OverflowLeft > FixedPoint2.Zero && nextPuddles.Count > 0)
|
||||
{
|
||||
foreach (var next in nextPuddles.ToArray())
|
||||
{
|
||||
@@ -220,7 +221,7 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
overflownPuddles.Add(next);
|
||||
|
||||
var adjacentPuddles = GetAllAdjacentOverflow(next).ToArray();
|
||||
if (puddleComponent.OverflowLeft <= ReagentUnit.Epsilon * adjacentPuddles.Length)
|
||||
if (puddleComponent.OverflowLeft <= FixedPoint2.Epsilon * adjacentPuddles.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -230,12 +231,12 @@ namespace Content.Server.Fluids.EntitySystems
|
||||
continue;
|
||||
}
|
||||
|
||||
var numberOfAdjacent = ReagentUnit.New(adjacentPuddles.Length);
|
||||
var numberOfAdjacent = FixedPoint2.New(adjacentPuddles.Length);
|
||||
var overflowSplit = puddleComponent.OverflowLeft / numberOfAdjacent;
|
||||
foreach (var adjacent in adjacentPuddles)
|
||||
{
|
||||
var adjacentPuddle = adjacent();
|
||||
var quantity = ReagentUnit.Min(overflowSplit, adjacentPuddle.OverflowVolume);
|
||||
var quantity = FixedPoint2.Min(overflowSplit, adjacentPuddle.OverflowVolume);
|
||||
var puddleSolution = _solutionContainerSystem.EnsureSolution(puddleComponent.Owner.Uid,
|
||||
puddleComponent.SolutionName);
|
||||
var spillAmount = _solutionContainerSystem.SplitSolution(puddleComponent.Owner.Uid,
|
||||
|
||||
Reference in New Issue
Block a user