From 3ab4a30a0f7e34945c3c73bff7e04de660d1c87d Mon Sep 17 00:00:00 2001 From: mirrorcult Date: Wed, 3 Nov 2021 16:48:03 -0700 Subject: [PATCH] Generalize ReagentUnit into FixedPoint2 and use it for damage calculations (#5151) * Damage units * sum ext method --- .../Administration/UI/AdminAddReagentUI.cs | 5 +- .../Components/HyposprayComponent.cs | 5 +- .../Chemistry/Components/InjectorComponent.cs | 5 +- .../Chemistry/UI/ChemMasterWindow.xaml.cs | 27 ++-- .../UI/TransferAmountBoundUserInterface.cs | 3 +- Content.Client/Damage/DamageVisualizer.cs | 43 +++--- .../Damage/DamageVisualizerComponent.cs | 5 +- .../HealthOverlay/UI/HealthOverlayGui.cs | 11 +- .../UI/MedicalScannerWindow.xaml.cs | 2 + ...est.cs => FixedPoint2SerializationTest.cs} | 13 +- .../Tests/Commands/RejuvenateTest.cs | 6 +- .../Tests/Damageable/DamageableTest.cs | 48 ++++--- .../DestructibleDamageGroupTest.cs | 7 +- .../DestructibleThresholdActivationTest.cs | 9 +- .../Tests/Fluids/PuddleTest.cs | 7 +- .../Combat/Melee/MeleeWeaponDamageCon.cs | 2 +- .../Considerations/Combat/TargetHealthCon.cs | 2 +- .../Administration/UI/AdminAddReagentEui.cs | 5 +- .../Atmos/EntitySystems/BarotraumaSystem.cs | 3 +- .../Atmos/Reactions/WaterVaporReaction.cs | 3 +- .../Body/Behavior/StomachBehavior.cs | 13 +- .../Body/Circulatory/BloodstreamComponent.cs | 9 +- .../Body/Metabolism/MetabolizerComponent.cs | 3 +- .../Body/Metabolism/MetabolizerSystem.cs | 3 +- .../Botany/Components/PlantHolderComponent.cs | 7 +- .../Botany/Components/ProduceComponent.cs | 7 +- .../Components/ChemMasterComponent.cs | 33 ++--- .../FoamSolutionAreaEffectComponent.cs | 3 +- .../Components/HyposprayComponent.cs | 7 +- .../Chemistry/Components/InjectorComponent.cs | 15 +- .../MeleeChemicalInjectorComponent.cs | 3 +- .../Components/ReagentDispenserComponent.cs | 25 ++-- .../Components/ReagentTankComponent.cs | 3 +- .../SmokeSolutionAreaEffectComponent.cs | 5 +- .../Components/SolutionAreaEffectComponent.cs | 5 +- .../SolutionInjectOnCollideComponent.cs | 3 +- .../Components/SolutionTransferComponent.cs | 23 +-- .../Chemistry/Components/VaporComponent.cs | 3 +- .../EntitySystems/ChemicalReactionSystem.cs | 3 +- .../EntitySystems/RehydratableSystem.cs | 3 +- .../SolutionContainerSystem.Capabilities.cs | 9 +- .../EntitySystems/SolutionContainerSystem.cs | 17 +-- .../EntitySystems/SolutionTransferSystem.cs | 3 +- .../Chemistry/EntitySystems/VaporSystem.cs | 3 +- .../ReagentThreshold.cs | 5 +- .../AddToSolutionReaction.cs | 3 +- .../ExtinguishReaction.cs | 3 +- .../FlammableReaction.cs | 3 +- .../WashCreamPieReaction.cs | 3 +- .../TileReactions/CleanTileReaction.cs | 5 +- .../TileReactions/ExtinguishTileReaction.cs | 11 +- .../TileReactions/FlammableTileReaction.cs | 9 +- .../SpillIfPuddlePresentTileReaction.cs | 7 +- .../TileReactions/SpillTileReaction.cs | 7 +- .../Cleanable/CleanableComponent.cs | 5 +- .../Extinguisher/FireExtinguisherComponent.cs | 3 +- .../Fluids/Components/BucketComponent.cs | 11 +- .../Fluids/Components/EvaporationComponent.cs | 7 +- .../Fluids/Components/MopComponent.cs | 13 +- .../Fluids/Components/PuddleComponent.cs | 13 +- .../Fluids/Components/SpillExtensions.cs | 3 +- .../Fluids/Components/SprayComponent.cs | 11 +- .../Fluids/EntitySystems/EvaporationSystem.cs | 3 +- .../Fluids/EntitySystems/PuddleSystem.cs | 21 +-- .../Kitchen/Components/MicrowaveComponent.cs | 5 +- .../MobState/States/NormalMobState.cs | 3 +- .../Nutrition/Components/DrinkComponent.cs | 3 +- .../Nutrition/Components/FoodComponent.cs | 7 +- .../Components/SliceableFoodComponent.cs | 3 +- .../Nutrition/Components/SmokableComponent.cs | 3 +- .../Nutrition/EntitySystems/DrinkSystem.cs | 3 +- .../Nutrition/EntitySystems/SmokingSystem.cs | 5 +- .../Tools/Components/WelderComponent.cs | 5 +- Content.Server/Tools/ToolSystem.Welder.cs | 17 +-- .../Administration/AdminAddReagentEuiState.cs | 7 +- Content.Shared/Chemistry/ChemistrySystem.cs | 5 +- .../Components/SharedChemMasterComponent.cs | 15 +- .../Components/SharedHyposprayComponent.cs | 7 +- .../Components/SharedInjectorComponent.cs | 7 +- .../Components/Solution.Managerial.cs | 17 +-- .../Chemistry/Components/Solution.cs | 37 ++--- .../SharedReagentDispenserComponent.cs | 11 +- .../Chemistry/Reaction/ITileReaction.cs | 3 +- .../Chemistry/Reaction/ReactionPrototype.cs | 9 +- .../Reaction/SharedChemicalReactionSystem.cs | 11 +- .../Reagent/ReagentEntityReaction.cs | 5 +- .../Chemistry/Reagent/ReagentPrototype.cs | 5 +- .../Chemistry/SharedTransferAmount.cs | 11 +- Content.Shared/Damage/DamageSpecifier.cs | 62 ++++---- Content.Shared/Damage/DamageableComponent.cs | 17 +-- Content.Shared/Damage/DamageableSystem.cs | 11 +- .../FixedPoint2.cs} | 112 +++++++++------ .../SharedMedicalScannerComponent.cs | 5 +- .../MobState/Components/MobStateComponent.cs | 51 +++---- Content.Shared/MobState/IMobStateComponent.cs | 27 ++-- Content.Shared/MobState/State/BaseMobState.cs | 5 +- Content.Shared/MobState/State/IMobState.cs | 3 +- ...gentUnit_Tests.cs => FixedPoint2_Tests.cs} | 59 ++++---- .../Shared/Chemistry/Solution_Tests.cs | 133 +++++++++--------- Content.Tests/Shared/DamageTest.cs | 77 +++++----- 100 files changed, 730 insertions(+), 601 deletions(-) rename Content.IntegrationTests/Tests/Chemistry/{ReagentUnitSerializationTest.cs => FixedPoint2SerializationTest.cs} (66%) rename Content.Shared/{Chemistry/Reagent/ReagentUnit.cs => FixedPoint/FixedPoint2.cs} (54%) rename Content.Tests/Shared/Chemistry/{ReagentUnit_Tests.cs => FixedPoint2_Tests.cs} (68%) diff --git a/Content.Client/Administration/UI/AdminAddReagentUI.cs b/Content.Client/Administration/UI/AdminAddReagentUI.cs index 425fb16746..bd1b6faf03 100644 --- a/Content.Client/Administration/UI/AdminAddReagentUI.cs +++ b/Content.Client/Administration/UI/AdminAddReagentUI.cs @@ -2,6 +2,7 @@ using Content.Client.Eui; using Content.Shared.Administration; using Content.Shared.Chemistry.Reagent; using Content.Shared.Eui; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; @@ -40,7 +41,7 @@ namespace Content.Client.Administration.UI _window.HandleState((AdminAddReagentEuiState) state); } - private void DoAdd(bool close, string reagentId, ReagentUnit amount) + private void DoAdd(bool close, string reagentId, FixedPoint2 amount) { SendMessage(new AdminAddReagentEuiMsg.DoAdd { @@ -121,7 +122,7 @@ namespace Content.Client.Administration.UI _eui.DoAdd( close, _reagentIdEdit.Text, - ReagentUnit.New(float.Parse(_amountEdit.Text))); + FixedPoint2.New(float.Parse(_amountEdit.Text))); } private void CheckErrors() diff --git a/Content.Client/Chemistry/Components/HyposprayComponent.cs b/Content.Client/Chemistry/Components/HyposprayComponent.cs index 4d832dccae..51be06e5c2 100644 --- a/Content.Client/Chemistry/Components/HyposprayComponent.cs +++ b/Content.Client/Chemistry/Components/HyposprayComponent.cs @@ -3,6 +3,7 @@ using Content.Client.Message; using Content.Client.Stylesheets; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; @@ -15,8 +16,8 @@ namespace Content.Client.Chemistry.Components [RegisterComponent] public sealed class HyposprayComponent : SharedHyposprayComponent, IItemStatus { - [ViewVariables] private ReagentUnit CurrentVolume { get; set; } - [ViewVariables] private ReagentUnit TotalVolume { get; set; } + [ViewVariables] private FixedPoint2 CurrentVolume { get; set; } + [ViewVariables] private FixedPoint2 TotalVolume { get; set; } [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) diff --git a/Content.Client/Chemistry/Components/InjectorComponent.cs b/Content.Client/Chemistry/Components/InjectorComponent.cs index a21f042636..cfc911d2d6 100644 --- a/Content.Client/Chemistry/Components/InjectorComponent.cs +++ b/Content.Client/Chemistry/Components/InjectorComponent.cs @@ -3,6 +3,7 @@ using Content.Client.Message; using Content.Client.Stylesheets; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; @@ -18,8 +19,8 @@ namespace Content.Client.Chemistry.Components [RegisterComponent] public class InjectorComponent : SharedInjectorComponent, IItemStatus { - [ViewVariables] private ReagentUnit CurrentVolume { get; set; } - [ViewVariables] private ReagentUnit TotalVolume { get; set; } + [ViewVariables] private FixedPoint2 CurrentVolume { get; set; } + [ViewVariables] private FixedPoint2 TotalVolume { get; set; } [ViewVariables] private InjectorToggleMode CurrentMode { get; set; } [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; diff --git a/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs b/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs index 306000dfd6..1debacec2f 100644 --- a/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs +++ b/Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs @@ -4,6 +4,7 @@ using Content.Client.Stylesheets; using Content.Client.UserInterface; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -47,7 +48,7 @@ namespace Content.Client.Chemistry.UI BottleAmount.InitDefaultButtons(); } - private ChemButton MakeChemButton(string text, ReagentUnit amount, string id, bool isBuffer, string styleClass) + private ChemButton MakeChemButton(string text, FixedPoint2 amount, string id, bool isBuffer, string styleClass) { var button = new ChemButton(text, amount, id, isBuffer, styleClass); button.OnPressed += args @@ -129,11 +130,11 @@ namespace Content.Client.Chemistry.UI //Padding new Control {HorizontalExpand = true}, - MakeChemButton("1", ReagentUnit.New(1), reagent.ReagentId, false, StyleBase.ButtonOpenRight), - MakeChemButton("5", ReagentUnit.New(5), reagent.ReagentId, false, StyleBase.ButtonOpenBoth), - MakeChemButton("10", ReagentUnit.New(10), reagent.ReagentId, false, StyleBase.ButtonOpenBoth), - MakeChemButton("25", ReagentUnit.New(25), reagent.ReagentId, false, StyleBase.ButtonOpenBoth), - MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), ReagentUnit.New(-1), reagent.ReagentId, false, StyleBase.ButtonOpenLeft), + MakeChemButton("1", FixedPoint2.New(1), reagent.ReagentId, false, StyleBase.ButtonOpenRight), + MakeChemButton("5", FixedPoint2.New(5), reagent.ReagentId, false, StyleBase.ButtonOpenBoth), + MakeChemButton("10", FixedPoint2.New(10), reagent.ReagentId, false, StyleBase.ButtonOpenBoth), + MakeChemButton("25", FixedPoint2.New(25), reagent.ReagentId, false, StyleBase.ButtonOpenBoth), + MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), FixedPoint2.New(-1), reagent.ReagentId, false, StyleBase.ButtonOpenLeft), } }); } @@ -189,11 +190,11 @@ namespace Content.Client.Chemistry.UI //Padding new Control {HorizontalExpand = true}, - MakeChemButton("1", ReagentUnit.New(1), reagent.ReagentId, true, StyleBase.ButtonOpenRight), - MakeChemButton("5", ReagentUnit.New(5), reagent.ReagentId, true, StyleBase.ButtonOpenBoth), - MakeChemButton("10", ReagentUnit.New(10), reagent.ReagentId, true, StyleBase.ButtonOpenBoth), - MakeChemButton("25", ReagentUnit.New(25), reagent.ReagentId, true, StyleBase.ButtonOpenBoth), - MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), ReagentUnit.New(-1), reagent.ReagentId, true, StyleBase.ButtonOpenLeft), + MakeChemButton("1", FixedPoint2.New(1), reagent.ReagentId, true, StyleBase.ButtonOpenRight), + MakeChemButton("5", FixedPoint2.New(5), reagent.ReagentId, true, StyleBase.ButtonOpenBoth), + MakeChemButton("10", FixedPoint2.New(10), reagent.ReagentId, true, StyleBase.ButtonOpenBoth), + MakeChemButton("25", FixedPoint2.New(25), reagent.ReagentId, true, StyleBase.ButtonOpenBoth), + MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), FixedPoint2.New(-1), reagent.ReagentId, true, StyleBase.ButtonOpenLeft), } }); } @@ -203,10 +204,10 @@ namespace Content.Client.Chemistry.UI public class ChemButton : Button { - public ReagentUnit Amount { get; set; } + public FixedPoint2 Amount { get; set; } public bool isBuffer = true; public string Id { get; set; } - public ChemButton(string _text, ReagentUnit _amount, string _id, bool _isBuffer, string _styleClass) + public ChemButton(string _text, FixedPoint2 _amount, string _id, bool _isBuffer, string _styleClass) { AddStyleClass(_styleClass); Text = _text; diff --git a/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs b/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs index df0c3356e4..30f0f00f92 100644 --- a/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs +++ b/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs @@ -1,5 +1,6 @@ using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; @@ -20,7 +21,7 @@ namespace Content.Client.Chemistry.UI { if (int.TryParse(_window.AmountLineEdit.Text, out var i)) { - SendMessage(new TransferAmountSetValueMessage(ReagentUnit.New(i))); + SendMessage(new TransferAmountSetValueMessage(FixedPoint2.New(i))); _window.Close(); } }; diff --git a/Content.Client/Damage/DamageVisualizer.cs b/Content.Client/Damage/DamageVisualizer.cs index d89911d313..dd11555117 100644 --- a/Content.Client/Damage/DamageVisualizer.cs +++ b/Content.Client/Damage/DamageVisualizer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -58,7 +59,7 @@ namespace Content.Client.Damage /// isn't required for it. /// [DataField("thresholds", required: true)] - private List _thresholds = new(); + private List _thresholds = new(); /// /// Layers to target, by layerMapKey. @@ -295,7 +296,7 @@ namespace Content.Client.Damage || !entity.TryGetComponent(out var appearanceComponent)) return; - _thresholds.Add(0); + _thresholds.Add(FixedPoint2.Zero); _thresholds.Sort(); if (_thresholds[0] != 0) @@ -324,7 +325,7 @@ namespace Content.Client.Damage return; } - damageData.LastThresholdPerGroup.Add(damageType, 0); + damageData.LastThresholdPerGroup.Add(damageType, FixedPoint2.Zero); } } // Are we tracking a single damage group without overlay instead? @@ -338,7 +339,7 @@ namespace Content.Client.Damage return; } - damageData.LastThresholdPerGroup.Add(_damageGroup, 0); + damageData.LastThresholdPerGroup.Add(_damageGroup, FixedPoint2.Zero); } } // Ditto above, but instead we go through every group. @@ -356,7 +357,7 @@ namespace Content.Client.Damage damageData.Valid = false; return; } - damageData.LastThresholdPerGroup.Add(damageType, 0); + damageData.LastThresholdPerGroup.Add(damageType, FixedPoint2.Zero); } else if (_damageGroup != null) { @@ -367,7 +368,7 @@ namespace Content.Client.Damage return; } - damageData.LastThresholdPerGroup.Add(_damageGroup, 0); + damageData.LastThresholdPerGroup.Add(_damageGroup, FixedPoint2.Zero); } } @@ -604,7 +605,7 @@ namespace Content.Client.Damage { foreach (var (damageGroup, sprite) in _damageOverlayGroups) { - int threshold = damageData.LastThresholdPerGroup[damageGroup]; + FixedPoint2 threshold = damageData.LastThresholdPerGroup[damageGroup]; ReorderOverlaySprite(spriteComponent, damageData, sprite, @@ -625,12 +626,12 @@ namespace Content.Client.Damage } } - private void ReorderOverlaySprite(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, DamageVisualizerSprite sprite, string key, string statePrefix, int threshold) + private void ReorderOverlaySprite(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, DamageVisualizerSprite sprite, string key, string statePrefix, FixedPoint2 threshold) { spriteComponent.LayerMapTryGet(key, out int spriteLayer); bool visibility = spriteComponent[spriteLayer].Visible; spriteComponent.RemoveLayer(spriteLayer); - if (threshold == 0) // these should automatically be invisible + if (threshold == FixedPoint2.Zero) // these should automatically be invisible threshold = _thresholds[1]; spriteLayer = spriteComponent.AddLayer( new SpriteSpecifier.Rsi( @@ -650,7 +651,7 @@ namespace Content.Client.Damage /// private void UpdateDamageVisuals(DamageableComponent damageComponent, SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData) { - if (!CheckThresholdBoundary(damageComponent.TotalDamage, damageData.LastDamageThreshold, out int threshold)) + if (!CheckThresholdBoundary(damageComponent.TotalDamage, damageData.LastDamageThreshold, out FixedPoint2 threshold)) return; damageData.LastDamageThreshold = threshold; @@ -679,11 +680,11 @@ namespace Content.Client.Damage continue; if (!_prototypeManager.TryIndex(damageGroup, out var damageGroupPrototype) - || !damageComponent.Damage.TryGetDamageInGroup(damageGroupPrototype, out int damageTotal)) + || !damageComponent.Damage.TryGetDamageInGroup(damageGroupPrototype, out FixedPoint2 damageTotal)) continue; - if (!damageData.LastThresholdPerGroup.TryGetValue(damageGroup, out int lastThreshold) - || !CheckThresholdBoundary(damageTotal, lastThreshold, out int threshold)) + if (!damageData.LastThresholdPerGroup.TryGetValue(damageGroup, out FixedPoint2 lastThreshold) + || !CheckThresholdBoundary(damageTotal, lastThreshold, out FixedPoint2 threshold)) continue; damageData.LastThresholdPerGroup[damageGroup] = threshold; @@ -704,10 +705,10 @@ namespace Content.Client.Damage /// /// Checks if a threshold boundary was passed. /// - private bool CheckThresholdBoundary(int damageTotal, int lastThreshold, out int threshold) + private bool CheckThresholdBoundary(FixedPoint2 damageTotal, FixedPoint2 lastThreshold, out FixedPoint2 threshold) { - threshold = 0; - damageTotal = (int) Math.Floor(damageTotal / _divisor); + threshold = FixedPoint2.Zero; + damageTotal = damageTotal / _divisor; int thresholdIndex = _thresholds.BinarySearch(damageTotal); if (thresholdIndex < 0) @@ -753,7 +754,7 @@ namespace Content.Client.Damage /// it assumes you're updating a layer that is tracking all /// damage. /// - private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, int threshold) + private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, FixedPoint2 threshold) { if (_overlay && _damageOverlayGroups != null) { @@ -783,7 +784,7 @@ namespace Content.Client.Damage /// /// Updates a target layer by damage group. /// - private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, string damageGroup, int threshold) + private void UpdateTargetLayer(SpriteComponent spriteComponent, DamageVisualizerDataComponent damageData, object layerMapKey, string damageGroup, FixedPoint2 threshold) { if (_overlay && _damageOverlayGroups != null) { @@ -813,7 +814,7 @@ namespace Content.Client.Damage /// /// Updates an overlay that is tracking all damage. /// - private void UpdateOverlay(SpriteComponent spriteComponent, int threshold) + private void UpdateOverlay(SpriteComponent spriteComponent, FixedPoint2 threshold) { spriteComponent.LayerMapTryGet($"DamageOverlay", out int spriteLayer); @@ -826,7 +827,7 @@ namespace Content.Client.Damage /// /// Updates an overlay based on damage group. /// - private void UpdateOverlay(SpriteComponent spriteComponent, string damageGroup, int threshold) + private void UpdateOverlay(SpriteComponent spriteComponent, string damageGroup, FixedPoint2 threshold) { if (_damageOverlayGroups != null) { @@ -848,7 +849,7 @@ namespace Content.Client.Damage /// function calls it), and what threshold /// was passed into it. /// - private void UpdateDamageLayerState(SpriteComponent spriteComponent, int spriteLayer, string statePrefix, int threshold) + private void UpdateDamageLayerState(SpriteComponent spriteComponent, int spriteLayer, string statePrefix, FixedPoint2 threshold) { if (threshold == 0) { diff --git a/Content.Client/Damage/DamageVisualizerComponent.cs b/Content.Client/Damage/DamageVisualizerComponent.cs index 01b648dc4b..4e0e404ed3 100644 --- a/Content.Client/Damage/DamageVisualizerComponent.cs +++ b/Content.Client/Damage/DamageVisualizerComponent.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; namespace Content.Client.Damage @@ -17,10 +18,10 @@ namespace Content.Client.Damage public List TargetLayerMapKeys = new(); public bool Disabled = false; public bool Valid = true; - public int LastDamageThreshold = 0; + public FixedPoint2 LastDamageThreshold = FixedPoint2.Zero; public Dictionary DisabledLayers = new(); public Dictionary LayerMapKeyStates = new(); - public Dictionary LastThresholdPerGroup = new(); + public Dictionary LastThresholdPerGroup = new(); public string TopMostLayerKey = default!; } } diff --git a/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs b/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs index 00b016ae12..707d48f5e2 100644 --- a/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs +++ b/Content.Client/HealthOverlay/UI/HealthOverlayGui.cs @@ -1,6 +1,7 @@ using Content.Client.IoC; using Content.Client.Resources; using Content.Shared.Damage; +using Content.Shared.FixedPoint; using Content.Shared.MobState; using Robust.Client.Graphics; using Robust.Client.UserInterface; @@ -84,7 +85,7 @@ namespace Content.Client.HealthOverlay.UI return; } - int threshold; + FixedPoint2 threshold; if (mobState.IsAlive()) { @@ -97,7 +98,7 @@ namespace Content.Client.HealthOverlay.UI CritBar.Ratio = 1; CritBar.Visible = true; - HealthBar.Ratio = 1 - (float) damageable.TotalDamage / threshold; + HealthBar.Ratio = 1 - (damageable.TotalDamage / threshold).Float(); HealthBar.Visible = true; } else if (mobState.IsCritical()) @@ -113,9 +114,9 @@ namespace Content.Client.HealthOverlay.UI } CritBar.Visible = true; - CritBar.Ratio = 1 - (float) - (damageable.TotalDamage - critThreshold) / - (deadThreshold - critThreshold); + CritBar.Ratio = 1 - + ((damageable.TotalDamage - critThreshold) / + (deadThreshold - critThreshold)).Float(); } else if (mobState.IsDead()) { diff --git a/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs b/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs index 3fc13a341b..5100367f35 100644 --- a/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs +++ b/Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs @@ -9,6 +9,7 @@ using Robust.Shared.Localization; using Robust.Shared.Prototypes; using static Content.Shared.MedicalScanner.SharedMedicalScannerComponent; using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.XAML; @@ -39,6 +40,7 @@ namespace Content.Client.MedicalScanner.UI text.Append($"{Loc.GetString("medical-scanner-window-entity-health-text", ("entityName", entity.Name))}\n"); var totalDamage = state.DamagePerType.Values.Sum(); + text.Append($"{Loc.GetString("medical-scanner-window-entity-damage-total-text", ("amount", totalDamage))}\n"); HashSet shownTypes = new(); diff --git a/Content.IntegrationTests/Tests/Chemistry/ReagentUnitSerializationTest.cs b/Content.IntegrationTests/Tests/Chemistry/FixedPoint2SerializationTest.cs similarity index 66% rename from Content.IntegrationTests/Tests/Chemistry/ReagentUnitSerializationTest.cs rename to Content.IntegrationTests/Tests/Chemistry/FixedPoint2SerializationTest.cs index 3aac172d5d..f7e22823e8 100644 --- a/Content.IntegrationTests/Tests/Chemistry/ReagentUnitSerializationTest.cs +++ b/Content.IntegrationTests/Tests/Chemistry/FixedPoint2SerializationTest.cs @@ -1,5 +1,6 @@ using System.Reflection; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using NUnit.Framework; using Robust.Shared.Serialization.Manager; using Robust.Shared.Serialization.Manager.Attributes; @@ -9,18 +10,18 @@ using Robust.UnitTesting.Shared.Serialization; namespace Content.IntegrationTests.Tests.Chemistry { - public class ReagentUnitSerializationTest : SerializationTest + public class FixedPoint2SerializationTest : SerializationTest { protected override Assembly[] Assemblies => new[] { - typeof(ReagentUnitSerializationTest).Assembly + typeof(FixedPoint2SerializationTest).Assembly }; [Test] public void DeserializeNullTest() { var node = new ValueDataNode("null"); - var unit = Serialization.ReadValue(node); + var unit = Serialization.ReadValue(node); Assert.That(unit, Is.Null); } @@ -29,15 +30,15 @@ namespace Content.IntegrationTests.Tests.Chemistry public void DeserializeNullDefinitionTest() { var node = new MappingDataNode().Add("unit", "null"); - var definition = Serialization.ReadValueOrThrow(node); + var definition = Serialization.ReadValueOrThrow(node); Assert.That(definition.Unit, Is.Null); } } [DataDefinition] - public class ReagentUnitTestDefinition + public class FixedPoint2TestDefinition { - [DataField("unit")] public ReagentUnit? Unit { get; set; } = ReagentUnit.New(5); + [DataField("unit")] public FixedPoint2? Unit { get; set; } = FixedPoint2.New(5); } } diff --git a/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs b/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs index 359cd2cfa7..6860b0b36d 100644 --- a/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs +++ b/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Content.Server.Administration.Commands; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; using Content.Shared.MobState; using NUnit.Framework; using Robust.Shared.GameObjects; @@ -56,7 +57,8 @@ namespace Content.IntegrationTests.Tests.Commands Assert.That(mobState.IsIncapacitated, Is.False); // Kill the entity - DamageSpecifier damage = new(prototypeManager.Index("Toxin"), 10000000); + DamageSpecifier damage = new(prototypeManager.Index("Toxin"), + FixedPoint2.New(10000000)); EntitySystem.Get().TryChangeDamage(human.Uid, damage, true); // Check that it is dead @@ -74,7 +76,7 @@ namespace Content.IntegrationTests.Tests.Commands Assert.That(mobState.IsDead, Is.False); Assert.That(mobState.IsIncapacitated, Is.False); - Assert.That(damageable.TotalDamage, Is.Zero); + Assert.That(damageable.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); }); } } diff --git a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs index 6d68a93653..b3a20f9cf2 100644 --- a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs +++ b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.Map; @@ -108,7 +109,7 @@ namespace Content.IntegrationTests.Tests.Damageable DamageTypePrototype type3b = default!; DamageTypePrototype type3c = default!; - int typeDamage, groupDamage; + FixedPoint2 typeDamage, groupDamage; await server.WaitPost(() => { @@ -148,7 +149,7 @@ namespace Content.IntegrationTests.Tests.Damageable // Check that damage is evenly distributed over a group if its a nice multiple var types = group3.DamageTypes; - var damageToDeal = types.Count() * 5; + var damageToDeal = FixedPoint2.New(types.Count() * 5); DamageSpecifier damage = new(group3, damageToDeal); sDamageableSystem.TryChangeDamage(uid, damage, true); @@ -166,73 +167,74 @@ namespace Content.IntegrationTests.Tests.Damageable sDamageableSystem.TryChangeDamage(uid, -damage); Assert.That(DamageChanged); DamageChanged = false; - Assert.That(sDamageableComponent.TotalDamage, Is.Zero); - Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(0)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); + Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(FixedPoint2.Zero)); foreach (var type in types) { Assert.That(sDamageableComponent.Damage.DamageDict.TryGetValue(type, out typeDamage)); - Assert.That(typeDamage, Is.Zero); + Assert.That(typeDamage, Is.EqualTo(FixedPoint2.Zero)); } // Check that damage works properly if it is NOT perfectly divisible among group members types = group3.DamageTypes; - damageToDeal = types.Count() * 5 - 1; + damageToDeal = FixedPoint2.New(types.Count() * 5 - 1); damage = new DamageSpecifier(group3, damageToDeal); sDamageableSystem.TryChangeDamage(uid, damage, true); Assert.That(DamageChanged); DamageChanged = false; Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damageToDeal)); Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(damageToDeal)); - // integer rounding. In this case, first member gets 1 less than others. Assert.That(sDamageableComponent.Damage.DamageDict[type3a.ID], Is.EqualTo(damageToDeal / types.Count())); - Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(1 + damageToDeal / types.Count())); - Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(1 + damageToDeal / types.Count())); + Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(damageToDeal / types.Count())); + + // last one will get 0.01 less, since its not perfectly divisble by 3 + Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(damageToDeal / types.Count() - 0.01)); // Heal sDamageableSystem.TryChangeDamage(uid, -damage); Assert.That(DamageChanged); DamageChanged = false; - Assert.That(sDamageableComponent.TotalDamage, Is.Zero); - Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(0)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); + Assert.That(sDamageableComponent.DamagePerGroup[group3.ID], Is.EqualTo(FixedPoint2.Zero)); foreach (var type in types) { Assert.That(sDamageableComponent.Damage.DamageDict.TryGetValue(type, out typeDamage)); - Assert.That(typeDamage, Is.Zero); + Assert.That(typeDamage, Is.EqualTo(FixedPoint2.Zero)); } // Test that unsupported groups return false when setting/getting damage (and don't change damage) - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0)); - damage = new DamageSpecifier(group1, 10) + new DamageSpecifier(type2b, 10); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); + damage = new DamageSpecifier(group1, FixedPoint2.New(10)) + new DamageSpecifier(type2b, FixedPoint2.New(10)); sDamageableSystem.TryChangeDamage(uid, damage, true); Assert.That(DamageChanged, Is.False); Assert.That(sDamageableComponent.DamagePerGroup.TryGetValue(group1.ID, out groupDamage), Is.False); Assert.That(sDamageableComponent.Damage.DamageDict.TryGetValue(type1.ID, out typeDamage), Is.False); - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); // Test SetAll function sDamageableSystem.SetAllDamage(sDamageableComponent, 10); - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(10 * sDamageableComponent.Damage.DamageDict.Count())); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(10 * sDamageableComponent.Damage.DamageDict.Count()))); sDamageableSystem.SetAllDamage(sDamageableComponent, 0); - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); // Test 'wasted' healing sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(type3a, 5)); sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(type3b, 7)); sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, -11)); - Assert.That(sDamageableComponent.Damage.DamageDict[type3a.ID], Is.EqualTo(2)); - Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(3)); - Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(0)); + Assert.That(sDamageableComponent.Damage.DamageDict[type3a.ID], Is.EqualTo(FixedPoint2.New(1.33))); + Assert.That(sDamageableComponent.Damage.DamageDict[type3b.ID], Is.EqualTo(FixedPoint2.New(3.33))); + Assert.That(sDamageableComponent.Damage.DamageDict[type3c.ID], Is.EqualTo(FixedPoint2.New(0))); // Test Over-Healing - sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, -100)); + sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, FixedPoint2.New(-100))); Assert.That(DamageChanged); DamageChanged = false; - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); // Test that if no health change occurred, returns false sDamageableSystem.TryChangeDamage(uid, new DamageSpecifier(group3, -100)); Assert.That(DamageChanged, Is.False); - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); }); } } diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs index 39b8ad74c9..280d313d13 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Content.Server.Destructible.Thresholds.Triggers; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -60,8 +61,8 @@ namespace Content.IntegrationTests.Tests.Destructible var bruteDamageGroup = sPrototypeManager.Index("TestBrute"); var burnDamageGroup = sPrototypeManager.Index("TestBurn"); - DamageSpecifier bruteDamage = new(bruteDamageGroup,5); - DamageSpecifier burnDamage = new(burnDamageGroup,5); + DamageSpecifier bruteDamage = new(bruteDamageGroup, FixedPoint2.New(5)); + DamageSpecifier burnDamage = new(burnDamageGroup, FixedPoint2.New(5)); // Raise brute damage to 5 sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bruteDamage, true); @@ -112,7 +113,7 @@ namespace Content.IntegrationTests.Tests.Destructible // Lower brute damage to 0 sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bruteDamage * -10); - Assert.That(sDamageableComponent.TotalDamage,Is.EqualTo(20)); + Assert.That(sDamageableComponent.TotalDamage,Is.EqualTo(FixedPoint2.New(20))); // No new thresholds reached, healing should not trigger it Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached); diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs index e92225fe69..795c965759 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs @@ -6,6 +6,7 @@ using Content.Server.Destructible.Thresholds.Behaviors; using Content.Server.Destructible.Thresholds.Triggers; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -186,7 +187,7 @@ namespace Content.IntegrationTests.Tests.Destructible sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bluntDamage*5, true); // Check that the total damage matches - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50))); // Both thresholds should have triggered Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Has.Exactly(2).Items); @@ -234,7 +235,7 @@ namespace Content.IntegrationTests.Tests.Destructible sDamageableSystem.SetAllDamage(sDamageableComponent, 0); // Check that the entity has 0 damage - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); // Set both thresholds to only trigger once foreach (var destructibleThreshold in sDestructibleComponent.Thresholds) @@ -247,7 +248,7 @@ namespace Content.IntegrationTests.Tests.Destructible sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bluntDamage*5, true); // Check that the total damage matches - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50))); // No thresholds should have triggered as they were already triggered before, and they are set to only trigger once Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty); @@ -260,7 +261,7 @@ namespace Content.IntegrationTests.Tests.Destructible } // Check that the total damage matches - Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50)); + Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50))); // They shouldn't have been triggered by changing TriggersOnce Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty); diff --git a/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs b/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs index bf1c95f85a..5fe124b8a3 100644 --- a/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs +++ b/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs @@ -4,6 +4,7 @@ using Content.Server.Fluids.Components; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; using Content.Shared.Coordinates; +using Content.Shared.FixedPoint; using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.Map; @@ -56,7 +57,7 @@ namespace Content.IntegrationTests.Tests.Fluids server.Assert(() => { - var solution = new Solution("water", ReagentUnit.New(20)); + var solution = new Solution("water", FixedPoint2.New(20)); var puddle = solution.SpillAt(coordinates, "PuddleSmear"); Assert.NotNull(puddle); }); @@ -94,7 +95,7 @@ namespace Content.IntegrationTests.Tests.Fluids server.Assert(() => { var coordinates = grid.ToCoordinates(); - var solution = new Solution("water", ReagentUnit.New(20)); + var solution = new Solution("water", FixedPoint2.New(20)); var puddle = solution.SpillAt(coordinates, "PuddleSmear"); Assert.Null(puddle); }); @@ -154,7 +155,7 @@ namespace Content.IntegrationTests.Tests.Fluids // Spawn a puddle await server.WaitAssertion(() => { - var solution = new Solution("water", ReagentUnit.New(amount)); + var solution = new Solution("water", FixedPoint2.New(amount)); puddle = solution.SpillAt(sCoordinates, "PuddleSmear"); // Check that the puddle was created diff --git a/Content.Server/AI/Utility/Considerations/Combat/Melee/MeleeWeaponDamageCon.cs b/Content.Server/AI/Utility/Considerations/Combat/Melee/MeleeWeaponDamageCon.cs index 5a606679e9..470db45994 100644 --- a/Content.Server/AI/Utility/Considerations/Combat/Melee/MeleeWeaponDamageCon.cs +++ b/Content.Server/AI/Utility/Considerations/Combat/Melee/MeleeWeaponDamageCon.cs @@ -16,7 +16,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee } // Just went with max health - return meleeWeaponComponent.Damage.Total / 300.0f; + return (meleeWeaponComponent.Damage.Total / 300.0f).Float(); } } } diff --git a/Content.Server/AI/Utility/Considerations/Combat/TargetHealthCon.cs b/Content.Server/AI/Utility/Considerations/Combat/TargetHealthCon.cs index 58feb5aa85..9196904a72 100644 --- a/Content.Server/AI/Utility/Considerations/Combat/TargetHealthCon.cs +++ b/Content.Server/AI/Utility/Considerations/Combat/TargetHealthCon.cs @@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat return 0.0f; } - return damageableComponent.TotalDamage / 300.0f; + return (float) damageableComponent.TotalDamage / 300.0f; } } } diff --git a/Content.Server/Administration/UI/AdminAddReagentEui.cs b/Content.Server/Administration/UI/AdminAddReagentEui.cs index 9cfcf882b9..eb3e19944a 100644 --- a/Content.Server/Administration/UI/AdminAddReagentEui.cs +++ b/Content.Server/Administration/UI/AdminAddReagentEui.cs @@ -6,6 +6,7 @@ using Content.Shared.Administration; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; using Content.Shared.Eui; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -42,8 +43,8 @@ namespace Content.Server.Administration.UI return new AdminAddReagentEuiState { - CurVolume = ReagentUnit.Zero, - MaxVolume = ReagentUnit.Zero + CurVolume = FixedPoint2.Zero, + MaxVolume = FixedPoint2.Zero }; } diff --git a/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs b/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs index f1c2044c48..7f74c79121 100644 --- a/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs +++ b/Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs @@ -5,6 +5,7 @@ using Content.Server.Atmos.Components; using Content.Shared.Alert; using Content.Shared.Atmos; using Content.Shared.Damage; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -71,7 +72,7 @@ namespace Content.Server.Atmos.EntitySystems foreach (var (barotrauma, damageable, transform) in EntityManager.EntityQuery()) { - var totalDamage = 0; + var totalDamage = FixedPoint2.Zero; foreach (var (barotraumaDamageType, _) in barotrauma.Damage.DamageDict) { if (!damageable.Damage.DamageDict.TryGetValue(barotraumaDamageType, out var damage)) diff --git a/Content.Server/Atmos/Reactions/WaterVaporReaction.cs b/Content.Server/Atmos/Reactions/WaterVaporReaction.cs index 8161cc5739..6d489ad584 100644 --- a/Content.Server/Atmos/Reactions/WaterVaporReaction.cs +++ b/Content.Server/Atmos/Reactions/WaterVaporReaction.cs @@ -2,6 +2,7 @@ using Content.Server.Atmos.EntitySystems; using Content.Server.Fluids.Components; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Maps; using JetBrains.Annotations; using Robust.Shared.Serialization.Manager.Attributes; @@ -35,7 +36,7 @@ namespace Content.Server.Atmos.Reactions mixture.AdjustMoles(GasId, -MolesPerUnit); var tileRef = tile.GridIndices.GetTileRef(tile.GridIndex); - tileRef.SpillAt(new Solution(Reagent, ReagentUnit.New(MolesPerUnit)), PuddlePrototype, sound: false); + tileRef.SpillAt(new Solution(Reagent, FixedPoint2.New(MolesPerUnit)), PuddlePrototype, sound: false); return ReactionResult.Reacting; } diff --git a/Content.Server/Body/Behavior/StomachBehavior.cs b/Content.Server/Body/Behavior/StomachBehavior.cs index 0eb98139cd..160477a674 100644 --- a/Content.Server/Body/Behavior/StomachBehavior.cs +++ b/Content.Server/Body/Behavior/StomachBehavior.cs @@ -5,6 +5,7 @@ using Content.Server.Chemistry.EntitySystems; using Content.Shared.Body.Networks; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -65,7 +66,7 @@ namespace Content.Server.Body.Behavior // This reagent has been in the stomach long enough, TRY to transfer it. // But first, check if the reagent still exists, and how much is left. // Some poor spessman may have washed down a potassium snack with some water. - if (StomachSolution.ContainsReagent(delta.ReagentId, out ReagentUnit quantity)) + if (StomachSolution.ContainsReagent(delta.ReagentId, out FixedPoint2 quantity)) { if (quantity > delta.Quantity) { @@ -97,10 +98,10 @@ namespace Content.Server.Body.Behavior /// /// Max volume of internal solution storage /// - public ReagentUnit MaxVolume + public FixedPoint2 MaxVolume { get => - StomachSolution?.MaxVolume ?? ReagentUnit.Zero; + StomachSolution?.MaxVolume ?? FixedPoint2.Zero; set { @@ -116,7 +117,7 @@ namespace Content.Server.Body.Behavior /// [DataField("maxVolume")] [ViewVariables] - protected ReagentUnit InitialMaxVolume { get; private set; } = ReagentUnit.New(100); + protected FixedPoint2 InitialMaxVolume { get; private set; } = FixedPoint2.New(100); /// /// Time in seconds between reagents being ingested and them being @@ -181,10 +182,10 @@ namespace Content.Server.Body.Behavior protected class ReagentDelta { public readonly string ReagentId; - public readonly ReagentUnit Quantity; + public readonly FixedPoint2 Quantity; public float Lifetime { get; private set; } - public ReagentDelta(string reagentId, ReagentUnit quantity) + public ReagentDelta(string reagentId, FixedPoint2 quantity) { ReagentId = reagentId; Quantity = quantity; diff --git a/Content.Server/Body/Circulatory/BloodstreamComponent.cs b/Content.Server/Body/Circulatory/BloodstreamComponent.cs index 9503dde557..0e7b6d04df 100644 --- a/Content.Server/Body/Circulatory/BloodstreamComponent.cs +++ b/Content.Server/Body/Circulatory/BloodstreamComponent.cs @@ -7,6 +7,7 @@ using Content.Shared.Atmos; using Content.Shared.Body.Networks; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -23,7 +24,7 @@ namespace Content.Server.Body.Circulatory /// Max volume of internal solution storage /// [DataField("maxVolume")] [ViewVariables] - private ReagentUnit _initialMaxVolume = ReagentUnit.New(250); + private FixedPoint2 _initialMaxVolume = FixedPoint2.New(250); /// /// Internal solution for reagent storage @@ -34,7 +35,7 @@ namespace Content.Server.Body.Circulatory /// Empty volume of internal solution /// [ViewVariables] - public ReagentUnit EmptyVolume => _internalSolution?.AvailableVolume ?? ReagentUnit.Zero; + public FixedPoint2 EmptyVolume => _internalSolution?.AvailableVolume ?? FixedPoint2.Zero; [ViewVariables] public GasMixture Air { get; set; } = new(6) @@ -60,8 +61,8 @@ namespace Content.Server.Body.Circulatory public override bool TryTransferSolution(Solution solution) { // For now doesn't support partial transfers - var current = _internalSolution?.CurrentVolume ?? ReagentUnit.Zero; - var max = _internalSolution?.MaxVolume ?? ReagentUnit.Zero; + var current = _internalSolution?.CurrentVolume ?? FixedPoint2.Zero; + var max = _internalSolution?.MaxVolume ?? FixedPoint2.Zero; if (solution.TotalVolume + current > max) { return false; diff --git a/Content.Server/Body/Metabolism/MetabolizerComponent.cs b/Content.Server/Body/Metabolism/MetabolizerComponent.cs index d1dccdc1a4..24960fe756 100644 --- a/Content.Server/Body/Metabolism/MetabolizerComponent.cs +++ b/Content.Server/Body/Metabolism/MetabolizerComponent.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using Content.Shared.Body.Networks; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary; @@ -47,7 +48,7 @@ namespace Content.Server.Body.Metabolism /// Amount of reagent to metabolize, per metabolism cycle. /// [DataField("metabolismRate")] - public ReagentUnit MetabolismRate = ReagentUnit.New(1.0f); + public FixedPoint2 MetabolismRate = FixedPoint2.New(1.0f); /// /// A list of effects to apply when these reagents are metabolized. diff --git a/Content.Server/Body/Metabolism/MetabolizerSystem.cs b/Content.Server/Body/Metabolism/MetabolizerSystem.cs index 003ac7f10a..f45176f9d1 100644 --- a/Content.Server/Body/Metabolism/MetabolizerSystem.cs +++ b/Content.Server/Body/Metabolism/MetabolizerSystem.cs @@ -5,6 +5,7 @@ using Content.Shared.Body.Components; using Content.Shared.Body.Mechanism; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -64,7 +65,7 @@ namespace Content.Server.Body.Metabolism { if (body.Owner.HasComponent() && solutionsSys.TryGetSolution(body.Owner.Uid, comp.SolutionName, out solution) - && solution.CurrentVolume >= ReagentUnit.Zero) + && solution.CurrentVolume >= FixedPoint2.Zero) { reagentList = solution.Contents; } diff --git a/Content.Server/Botany/Components/PlantHolderComponent.cs b/Content.Server/Botany/Components/PlantHolderComponent.cs index d3d66eed47..3a1d28067e 100644 --- a/Content.Server/Botany/Components/PlantHolderComponent.cs +++ b/Content.Server/Botany/Components/PlantHolderComponent.cs @@ -12,6 +12,7 @@ using Content.Shared.Audio; using Content.Shared.Botany; using Content.Shared.Chemistry.Reagent; using Content.Shared.Examine; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Random.Helpers; @@ -560,7 +561,7 @@ namespace Content.Server.Botany.Components } else { - var one = ReagentUnit.New(1); + var one = FixedPoint2.New(1); foreach (var reagent in solutionSystem.RemoveEachReagent(solution, one)) { var reagentProto = _prototypeManager.Index(reagent); @@ -727,7 +728,7 @@ namespace Content.Server.Botany.Components if (solutionSystem.TryGetDrainableSolution(usingItem.Uid, out var solution) && solutionSystem.TryGetSolution(Owner.Uid, SoilSolutionName, out var targetSolution)) { - var amount = ReagentUnit.New(5); + var amount = FixedPoint2.New(5); var sprayed = false; var targetEntity = Owner.Uid; var solutionEntity = usingItem.Uid; @@ -735,7 +736,7 @@ namespace Content.Server.Botany.Components if (usingItem.TryGetComponent(out SprayComponent? spray)) { sprayed = true; - amount = ReagentUnit.New(1); + amount = FixedPoint2.New(1); SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem, AudioHelpers.WithVariation(0.125f)); diff --git a/Content.Server/Botany/Components/ProduceComponent.cs b/Content.Server/Botany/Components/ProduceComponent.cs index 3cec2be151..ea9fad7ca9 100644 --- a/Content.Server/Botany/Components/ProduceComponent.cs +++ b/Content.Server/Botany/Components/ProduceComponent.cs @@ -1,5 +1,6 @@ using Content.Server.Chemistry.EntitySystems; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -50,10 +51,10 @@ namespace Content.Server.Botany.Components solutionContainer.RemoveAllSolution(); foreach (var (chem, quantity) in Seed.Chemicals) { - var amount = ReagentUnit.New(quantity.Min); + var amount = FixedPoint2.New(quantity.Min); if (quantity.PotencyDivisor > 0 && Potency > 0) - amount += ReagentUnit.New(Potency / quantity.PotencyDivisor); - amount = ReagentUnit.New((int) MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max)); + amount += FixedPoint2.New(Potency / quantity.PotencyDivisor); + amount = FixedPoint2.New((int) MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max)); solutionContainer.MaxVolume += amount; solutionContainer.AddReagent(chem, amount); } diff --git a/Content.Server/Chemistry/Components/ChemMasterComponent.cs b/Content.Server/Chemistry/Components/ChemMasterComponent.cs index 2d10d8f5bf..a29c665112 100644 --- a/Content.Server/Chemistry/Components/ChemMasterComponent.cs +++ b/Content.Server/Chemistry/Components/ChemMasterComponent.cs @@ -10,6 +10,7 @@ using Content.Server.UserInterface; using Content.Shared.ActionBlocker; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Random.Helpers; @@ -184,7 +185,7 @@ namespace Content.Server.Chemistry.Components if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) || !EntitySystem.Get().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution)) { - return new ChemMasterBoundUserInterfaceState(Powered, false, ReagentUnit.New(0), ReagentUnit.New(0), + return new ChemMasterBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0), "", Owner.Name, new List(), BufferSolution.Contents, _bufferModeTransfer, BufferSolution.TotalVolume); } @@ -225,7 +226,7 @@ namespace Content.Server.Chemistry.Components hands.PutInHand(item); } - private void TransferReagent(string id, ReagentUnit amount, bool isBuffer) + private void TransferReagent(string id, FixedPoint2 amount, bool isBuffer) { if (!HasBeaker && _bufferModeTransfer) return; var beaker = BeakerContainer.ContainedEntity; @@ -240,16 +241,16 @@ namespace Content.Server.Chemistry.Components { if (reagent.ReagentId == id) { - ReagentUnit actualAmount; + FixedPoint2 actualAmount; if ( - amount == ReagentUnit - .New(-1)) //amount is ReagentUnit.New(-1) when the client sends a message requesting to remove all solution from the container + amount == FixedPoint2 + .New(-1)) //amount is FixedPoint2.New(-1) when the client sends a message requesting to remove all solution from the container { - actualAmount = ReagentUnit.Min(reagent.Quantity, beakerSolution.AvailableVolume); + actualAmount = FixedPoint2.Min(reagent.Quantity, beakerSolution.AvailableVolume); } else { - actualAmount = ReagentUnit.Min(reagent.Quantity, amount, beakerSolution.AvailableVolume); + actualAmount = FixedPoint2.Min(reagent.Quantity, amount, beakerSolution.AvailableVolume); } @@ -271,14 +272,14 @@ namespace Content.Server.Chemistry.Components { if (reagent.ReagentId == id) { - ReagentUnit actualAmount; - if (amount == ReagentUnit.New(-1)) + FixedPoint2 actualAmount; + if (amount == FixedPoint2.New(-1)) { actualAmount = reagent.Quantity; } else { - actualAmount = ReagentUnit.Min(reagent.Quantity, amount); + actualAmount = FixedPoint2.Min(reagent.Quantity, amount); } EntitySystem.Get().TryRemoveReagent(beaker.Uid, beakerSolution, id, actualAmount); @@ -298,11 +299,11 @@ namespace Content.Server.Chemistry.Components if (action == UiAction.CreateBottles) { - var individualVolume = BufferSolution.TotalVolume / ReagentUnit.New(bottleAmount); - if (individualVolume < ReagentUnit.New(1)) + var individualVolume = BufferSolution.TotalVolume / FixedPoint2.New(bottleAmount); + if (individualVolume < FixedPoint2.New(1)) return; - var actualVolume = ReagentUnit.Min(individualVolume, ReagentUnit.New(30)); + var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(30)); for (int i = 0; i < bottleAmount; i++) { var bottle = Owner.EntityManager.SpawnEntity("ChemistryEmptyBottle01", Owner.Transform.Coordinates); @@ -331,11 +332,11 @@ namespace Content.Server.Chemistry.Components } else //Pills { - var individualVolume = BufferSolution.TotalVolume / ReagentUnit.New(pillAmount); - if (individualVolume < ReagentUnit.New(1)) + var individualVolume = BufferSolution.TotalVolume / FixedPoint2.New(pillAmount); + if (individualVolume < FixedPoint2.New(1)) return; - var actualVolume = ReagentUnit.Min(individualVolume, ReagentUnit.New(50)); + var actualVolume = FixedPoint2.Min(individualVolume, FixedPoint2.New(50)); for (int i = 0; i < pillAmount; i++) { var pill = Owner.EntityManager.SpawnEntity("pill", Owner.Transform.Coordinates); diff --git a/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs index 195474e466..36a0768a32 100644 --- a/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs @@ -3,6 +3,7 @@ using Content.Server.Chemistry.EntitySystems; using Content.Server.Inventory.Components; using Content.Server.Items; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Foam; using Content.Shared.Inventory; using Robust.Server.GameObjects; @@ -56,7 +57,7 @@ namespace Content.Server.Chemistry.Components } var cloneSolution = solution.Clone(); - var transferAmount = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction * (1 - protection), + var transferAmount = FixedPoint2.Min(cloneSolution.TotalVolume * solutionFraction * (1 - protection), bloodstream.EmptyVolume); var transferSolution = cloneSolution.SplitSolution(transferAmount); diff --git a/Content.Server/Chemistry/Components/HyposprayComponent.cs b/Content.Server/Chemistry/Components/HyposprayComponent.cs index d1f4a9e328..223ebf0e0c 100644 --- a/Content.Server/Chemistry/Components/HyposprayComponent.cs +++ b/Content.Server/Chemistry/Components/HyposprayComponent.cs @@ -4,6 +4,7 @@ using Content.Server.Interaction.Components; using Content.Server.Weapon.Melee; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.MobState.Components; using Content.Shared.Popups; using Content.Shared.Sound; @@ -27,7 +28,7 @@ namespace Content.Server.Chemistry.Components [DataField("TransferAmount")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5); + public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5); [DataField("InjectSound")] private SoundSpecifier _injectSound = new SoundPathSpecifier("/Audio/Items/hypospray.ogg"); @@ -85,7 +86,7 @@ namespace Content.Server.Chemistry.Components SoundSystem.Play(Filter.Pvs(user), _injectSound.GetSound(), user); // Get transfer amount. May be smaller than _transferAmount if not enough room - var realTransferAmount = ReagentUnit.Min(TransferAmount, targetSolution.AvailableVolume); + var realTransferAmount = FixedPoint2.Min(TransferAmount, targetSolution.AvailableVolume); if (realTransferAmount <= 0) { @@ -126,7 +127,7 @@ namespace Content.Server.Chemistry.Components var solutionSys = Owner.EntityManager.EntitySysManager.GetEntitySystem(); return solutionSys.TryGetSolution(Owner.Uid, SolutionName, out var solution) ? new HyposprayComponentState(solution.CurrentVolume, solution.MaxVolume) - : new HyposprayComponentState(ReagentUnit.Zero, ReagentUnit.Zero); + : new HyposprayComponentState(FixedPoint2.Zero, FixedPoint2.Zero); } } } diff --git a/Content.Server/Chemistry/Components/InjectorComponent.cs b/Content.Server/Chemistry/Components/InjectorComponent.cs index 0622544f25..54b0baefb5 100644 --- a/Content.Server/Chemistry/Components/InjectorComponent.cs +++ b/Content.Server/Chemistry/Components/InjectorComponent.cs @@ -6,6 +6,7 @@ using Content.Server.Chemistry.EntitySystems; using Content.Shared.Body.Networks; 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; @@ -41,14 +42,14 @@ namespace Content.Server.Chemistry.Components /// [ViewVariables] [DataField("transferAmount")] - private ReagentUnit _transferAmount = ReagentUnit.New(5); + private FixedPoint2 _transferAmount = FixedPoint2.New(5); /// /// Initial storage volume of the injector /// [ViewVariables] [DataField("initialMaxVolume")] - private ReagentUnit _initialMaxVolume = ReagentUnit.New(15); + private FixedPoint2 _initialMaxVolume = FixedPoint2.New(15); private InjectorToggleMode _toggleState; @@ -180,7 +181,7 @@ namespace Content.Server.Chemistry.Components return; // Get transfer amount. May be smaller than _transferAmount if not enough room - var realTransferAmount = ReagentUnit.Min(_transferAmount, targetBloodstream.EmptyVolume); + var realTransferAmount = FixedPoint2.Min(_transferAmount, targetBloodstream.EmptyVolume); if (realTransferAmount <= 0) { @@ -223,7 +224,7 @@ namespace Content.Server.Chemistry.Components } // Get transfer amount. May be smaller than _transferAmount if not enough room - var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.AvailableVolume); + var realTransferAmount = FixedPoint2.Min(_transferAmount, targetSolution.AvailableVolume); if (realTransferAmount <= 0) { @@ -285,7 +286,7 @@ namespace Content.Server.Chemistry.Components } // Get transfer amount. May be smaller than _transferAmount if not enough room - var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.DrawAvailable); + var realTransferAmount = FixedPoint2.Min(_transferAmount, targetSolution.DrawAvailable); if (realTransferAmount <= 0) { @@ -317,8 +318,8 @@ namespace Content.Server.Chemistry.Components Owner.EntityManager.EntitySysManager.GetEntitySystem() .TryGetSolution(Owner.Uid, SolutionName, out var solution); - var currentVolume = solution?.CurrentVolume ?? ReagentUnit.Zero; - var maxVolume = solution?.MaxVolume ?? ReagentUnit.Zero; + var currentVolume = solution?.CurrentVolume ?? FixedPoint2.Zero; + var maxVolume = solution?.MaxVolume ?? FixedPoint2.Zero; return new InjectorComponentState(currentVolume, maxVolume, ToggleState); } diff --git a/Content.Server/Chemistry/Components/MeleeChemicalInjectorComponent.cs b/Content.Server/Chemistry/Components/MeleeChemicalInjectorComponent.cs index 93c64e8aec..7da40e9c19 100644 --- a/Content.Server/Chemistry/Components/MeleeChemicalInjectorComponent.cs +++ b/Content.Server/Chemistry/Components/MeleeChemicalInjectorComponent.cs @@ -1,5 +1,6 @@ using System; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -13,7 +14,7 @@ namespace Content.Server.Chemistry.Components [ViewVariables(VVAccess.ReadWrite)] [DataField("transferAmount")] - public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1); + public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(1); [ViewVariables(VVAccess.ReadWrite)] public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); } diff --git a/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs b/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs index 57aab6367d..e1fe379ce7 100644 --- a/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs +++ b/Content.Server/Chemistry/Components/ReagentDispenserComponent.cs @@ -12,6 +12,7 @@ using Content.Shared.ActionBlocker; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Dispenser; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Sound; @@ -53,7 +54,7 @@ namespace Content.Server.Chemistry.Components private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"); [ViewVariables] public bool HasBeaker => BeakerContainer.ContainedEntity != null; - [ViewVariables] private ReagentUnit _dispenseAmount = ReagentUnit.New(10); + [ViewVariables] private FixedPoint2 _dispenseAmount = FixedPoint2.New(10); [UsedImplicitly] [ViewVariables] @@ -163,31 +164,31 @@ namespace Content.Server.Chemistry.Components TryClear(); break; case UiButton.SetDispenseAmount1: - _dispenseAmount = ReagentUnit.New(1); + _dispenseAmount = FixedPoint2.New(1); break; case UiButton.SetDispenseAmount5: - _dispenseAmount = ReagentUnit.New(5); + _dispenseAmount = FixedPoint2.New(5); break; case UiButton.SetDispenseAmount10: - _dispenseAmount = ReagentUnit.New(10); + _dispenseAmount = FixedPoint2.New(10); break; case UiButton.SetDispenseAmount15: - _dispenseAmount = ReagentUnit.New(15); + _dispenseAmount = FixedPoint2.New(15); break; case UiButton.SetDispenseAmount20: - _dispenseAmount = ReagentUnit.New(20); + _dispenseAmount = FixedPoint2.New(20); break; case UiButton.SetDispenseAmount25: - _dispenseAmount = ReagentUnit.New(25); + _dispenseAmount = FixedPoint2.New(25); break; case UiButton.SetDispenseAmount30: - _dispenseAmount = ReagentUnit.New(30); + _dispenseAmount = FixedPoint2.New(30); break; case UiButton.SetDispenseAmount50: - _dispenseAmount = ReagentUnit.New(50); + _dispenseAmount = FixedPoint2.New(50); break; case UiButton.SetDispenseAmount100: - _dispenseAmount = ReagentUnit.New(100); + _dispenseAmount = FixedPoint2.New(100); break; case UiButton.Dispense: if (HasBeaker) @@ -237,8 +238,8 @@ namespace Content.Server.Chemistry.Components if (beaker == null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) || !EntitySystem.Get().TryGetSolution(beaker.Uid, fits.Solution, out var solution)) { - return new ReagentDispenserBoundUserInterfaceState(Powered, false, ReagentUnit.New(0), - ReagentUnit.New(0), + return new ReagentDispenserBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), + FixedPoint2.New(0), string.Empty, Inventory, Owner.Name, null, _dispenseAmount); } diff --git a/Content.Server/Chemistry/Components/ReagentTankComponent.cs b/Content.Server/Chemistry/Components/ReagentTankComponent.cs index 7d55f43d15..8e6bdb313c 100644 --- a/Content.Server/Chemistry/Components/ReagentTankComponent.cs +++ b/Content.Server/Chemistry/Components/ReagentTankComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -13,7 +14,7 @@ namespace Content.Server.Chemistry.Components [DataField("transferAmount")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(10); + public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(10); [DataField("tankType")] [ViewVariables(VVAccess.ReadWrite)] diff --git a/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs index adb99fcb7d..f1dc187bb7 100644 --- a/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/SmokeSolutionAreaEffectComponent.cs @@ -3,6 +3,7 @@ using Content.Server.Body.Respiratory; using Content.Server.Chemistry.EntitySystems; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Smoking; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; @@ -39,12 +40,12 @@ namespace Content.Server.Chemistry.Components var chemistry = EntitySystem.Get(); var cloneSolution = solution.Clone(); - var transferAmount = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume); + var transferAmount = FixedPoint2.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume); var transferSolution = cloneSolution.SplitSolution(transferAmount); foreach (var reagentQuantity in transferSolution.Contents.ToArray()) { - if (reagentQuantity.Quantity == ReagentUnit.Zero) continue; + if (reagentQuantity.Quantity == FixedPoint2.Zero) continue; chemistry.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.ReagentId, reagentQuantity.Quantity, transferSolution); } diff --git a/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs index 3782e5560a..1fee4a57a0 100644 --- a/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs @@ -6,6 +6,7 @@ using Content.Server.Coordinates.Helpers; using Content.Shared.Chemistry; 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; @@ -133,7 +134,7 @@ namespace Content.Server.Chemistry.Components foreach (var reagentQuantity in solution.Contents) { - if (reagentQuantity.Quantity == ReagentUnit.Zero) continue; + if (reagentQuantity.Quantity == FixedPoint2.Zero) continue; var reagent = PrototypeManager.Index(reagentQuantity.ReagentId); // React with the tile the effect is on @@ -164,7 +165,7 @@ namespace Content.Server.Chemistry.Components return; var addSolution = - solution.SplitSolution(ReagentUnit.Min(solution.TotalVolume, solutionArea.AvailableVolume)); + solution.SplitSolution(FixedPoint2.Min(solution.TotalVolume, solutionArea.AvailableVolume)); EntitySystem.Get().TryAddSolution(Owner.Uid, solutionArea, addSolution); diff --git a/Content.Server/Chemistry/Components/SolutionInjectOnCollideComponent.cs b/Content.Server/Chemistry/Components/SolutionInjectOnCollideComponent.cs index 85efc832bb..9affe11de1 100644 --- a/Content.Server/Chemistry/Components/SolutionInjectOnCollideComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionInjectOnCollideComponent.cs @@ -1,5 +1,6 @@ using System; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -16,7 +17,7 @@ namespace Content.Server.Chemistry.Components [ViewVariables(VVAccess.ReadWrite)] [DataField("transferAmount")] - public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1); + public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(1); [ViewVariables(VVAccess.ReadWrite)] public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); } diff --git a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs b/Content.Server/Chemistry/Components/SolutionTransferComponent.cs index 0dc40ef2a0..c25d602c35 100644 --- a/Content.Server/Chemistry/Components/SolutionTransferComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionTransferComponent.cs @@ -6,6 +6,7 @@ using Content.Server.UserInterface; using Content.Shared.Chemistry; 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; @@ -35,21 +36,21 @@ namespace Content.Server.Chemistry.Components /// [DataField("transferAmount")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5); + public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5); /// /// The minimum amount of solution that can be transferred at once from this solution. /// [DataField("minTransferAmount")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit MinimumTransferAmount { get; set; } = ReagentUnit.New(5); + public FixedPoint2 MinimumTransferAmount { get; set; } = FixedPoint2.New(5); /// /// The maximum amount of solution that can be transferred at once from this solution. /// [DataField("maxTransferAmount")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit MaximumTransferAmount { get; set; } = ReagentUnit.New(50); + public FixedPoint2 MaximumTransferAmount { get; set; } = FixedPoint2.New(50); /// /// Can this entity take reagent from reagent tanks? @@ -95,14 +96,14 @@ namespace Content.Server.Chemistry.Components serverMsg.Session.AttachedEntity?.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount))); - SetTransferAmount(ReagentUnit.New(amount)); + SetTransferAmount(FixedPoint2.New(amount)); break; } } - public void SetTransferAmount(ReagentUnit amount) + public void SetTransferAmount(FixedPoint2 amount) { - amount = ReagentUnit.New(Math.Clamp(amount.Int(), MinimumTransferAmount.Int(), + amount = FixedPoint2.New(Math.Clamp(amount.Int(), MinimumTransferAmount.Int(), MaximumTransferAmount.Int())); TransferAmount = amount; } @@ -162,30 +163,30 @@ namespace Content.Server.Chemistry.Components } /// The actual amount transferred. - private static ReagentUnit DoTransfer(IEntity user, + private static FixedPoint2 DoTransfer(IEntity user, IEntity sourceEntity, Solution source, IEntity targetEntity, Solution target, - ReagentUnit amount) + FixedPoint2 amount) { if (source.DrainAvailable == 0) { sourceEntity.PopupMessage(user, Loc.GetString("comp-solution-transfer-is-empty", ("target", sourceEntity))); - return ReagentUnit.Zero; + return FixedPoint2.Zero; } if (target.AvailableVolume == 0) { targetEntity.PopupMessage(user, Loc.GetString("comp-solution-transfer-is-full", ("target", targetEntity))); - return ReagentUnit.Zero; + return FixedPoint2.Zero; } var actualAmount = - ReagentUnit.Min(amount, ReagentUnit.Min(source.DrainAvailable, target.AvailableVolume)); + FixedPoint2.Min(amount, FixedPoint2.Min(source.DrainAvailable, target.AvailableVolume)); var solution = EntitySystem.Get().Drain(sourceEntity.Uid, source, actualAmount); EntitySystem.Get().Refill(targetEntity.Uid, target, solution); diff --git a/Content.Server/Chemistry/Components/VaporComponent.cs b/Content.Server/Chemistry/Components/VaporComponent.cs index 7eda0be87f..265d5c2c0f 100644 --- a/Content.Server/Chemistry/Components/VaporComponent.cs +++ b/Content.Server/Chemistry/Components/VaporComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Vapor; using Robust.Shared.GameObjects; using Robust.Shared.Map; @@ -12,7 +13,7 @@ namespace Content.Server.Chemistry.Components { [ViewVariables] [DataField("transferAmount")] - internal ReagentUnit TransferAmount = ReagentUnit.New(0.5); + internal FixedPoint2 TransferAmount = FixedPoint2.New(0.5); internal bool Reached; internal float ReactTimer; diff --git a/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs index 69cfde9ea1..1a376e5f65 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs @@ -1,6 +1,7 @@ using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.Player; @@ -9,7 +10,7 @@ namespace Content.Server.Chemistry.EntitySystems { public class ChemicalReactionSystem : SharedChemicalReactionSystem { - protected override void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, ReagentUnit unitReactions) + protected override void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, FixedPoint2 unitReactions) { base.OnReaction(solution, reaction, owner, unitReactions); diff --git a/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs b/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs index 27e249d66f..37ab0be606 100644 --- a/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/RehydratableSystem.cs @@ -1,6 +1,7 @@ using Content.Server.Chemistry.Components; using Content.Server.Popups; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -21,7 +22,7 @@ namespace Content.Server.Chemistry.EntitySystems private void OnSolutionChange(EntityUid uid, RehydratableComponent component, SolutionChangedEvent args) { - if (_solutionsSystem.GetReagentQuantity(uid, component.CatalystPrototype) > ReagentUnit.Zero) + if (_solutionsSystem.GetReagentQuantity(uid, component.CatalystPrototype) > FixedPoint2.Zero) { Expand(component, component.Owner); } diff --git a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.Capabilities.cs b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.Capabilities.cs index 6e68aa835d..ed4dca054e 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.Capabilities.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.Capabilities.cs @@ -2,6 +2,7 @@ using Content.Server.Chemistry.Components.SolutionManager; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; namespace Content.Server.Chemistry.EntitySystems @@ -26,7 +27,7 @@ namespace Content.Server.Chemistry.EntitySystems TryAddSolution(targetUid, targetSolution, addedSolution); } - public Solution Draw(EntityUid targetUid, Solution solution, ReagentUnit amount, + public Solution Draw(EntityUid targetUid, Solution solution, FixedPoint2 amount, DrawableSolutionComponent? drawableSolution = null) { if (!Resolve(targetUid, ref drawableSolution, false)) @@ -35,7 +36,7 @@ namespace Content.Server.Chemistry.EntitySystems return SplitSolution(targetUid, solution, amount); } - public Solution Drain(EntityUid targetUid, Solution targetSolution, ReagentUnit amount, + public Solution Drain(EntityUid targetUid, Solution targetSolution, FixedPoint2 amount, DrainableSolutionComponent? drainableSolution = null) { if (!Resolve(targetUid, ref drainableSolution, false)) @@ -106,10 +107,10 @@ namespace Content.Server.Chemistry.EntitySystems return true; } - public ReagentUnit DrainAvailable(EntityUid uid) + public FixedPoint2 DrainAvailable(EntityUid uid) { return !TryGetDrainableSolution(uid, out var solution) - ? ReagentUnit.Zero + ? FixedPoint2.Zero : solution.CurrentVolume; } diff --git a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs index 3286afd773..c42775239f 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; using Content.Shared.Examine; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -51,7 +52,7 @@ namespace Content.Server.Chemistry.EntitySystems foreach (var keyValue in component.Solutions) { var solutionHolder = keyValue.Value; - if (solutionHolder.MaxVolume == ReagentUnit.Zero) + if (solutionHolder.MaxVolume == FixedPoint2.Zero) { solutionHolder.MaxVolume = solutionHolder.TotalVolume > solutionHolder.InitialMaxVolume ? solutionHolder.TotalVolume @@ -115,7 +116,7 @@ namespace Content.Server.Chemistry.EntitySystems /// /// the volume of solution to remove. /// The solution that was removed. - public Solution SplitSolution(EntityUid targetUid, Solution solutionHolder, ReagentUnit quantity) + public Solution SplitSolution(EntityUid targetUid, Solution solutionHolder, FixedPoint2 quantity) { var splitSol = solutionHolder.SplitSolution(quantity); UpdateChemicals(targetUid, solutionHolder); @@ -164,8 +165,8 @@ namespace Content.Server.Chemistry.EntitySystems /// The amount of reagent to add. /// The amount of reagent successfully added. /// If all the reagent could be added. - public bool TryAddReagent(EntityUid targetUid, Solution targetSolution, string reagentId, ReagentUnit quantity, - out ReagentUnit acceptedQuantity) + public bool TryAddReagent(EntityUid targetUid, Solution targetSolution, string reagentId, FixedPoint2 quantity, + out FixedPoint2 acceptedQuantity) { acceptedQuantity = targetSolution.AvailableVolume > quantity ? quantity : targetSolution.AvailableVolume; targetSolution.AddReagent(reagentId, acceptedQuantity); @@ -184,7 +185,7 @@ namespace Content.Server.Chemistry.EntitySystems /// The Id of the reagent to remove. /// The amount of reagent to remove. /// If the reagent to remove was found in the container. - public bool TryRemoveReagent(EntityUid targetUid, Solution? container, string reagentId, ReagentUnit quantity) + public bool TryRemoveReagent(EntityUid targetUid, Solution? container, string reagentId, FixedPoint2 quantity) { if (container == null || !container.ContainsReagent(reagentId)) return false; @@ -248,7 +249,7 @@ namespace Content.Server.Chemistry.EntitySystems return solutionsMgr.Solutions[name]; } - public string[] RemoveEachReagent(Solution solution, ReagentUnit quantity) + public string[] RemoveEachReagent(Solution solution, FixedPoint2 quantity) { var removedReagent = new string[solution.Contents.Count]; if (quantity <= 0) @@ -284,9 +285,9 @@ namespace Content.Server.Chemistry.EntitySystems } } - public ReagentUnit GetReagentQuantity(EntityUid ownerUid, string reagentId) + public FixedPoint2 GetReagentQuantity(EntityUid ownerUid, string reagentId) { - var reagentQuantity = ReagentUnit.New(0); + var reagentQuantity = FixedPoint2.New(0); if (EntityManager.TryGetEntity(ownerUid, out var owner) && owner.TryGetComponent(out SolutionContainerManagerComponent? managerComponent)) { diff --git a/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs index 315b297d34..6be2c98c69 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionTransferSystem.cs @@ -6,6 +6,7 @@ using Robust.Shared.Localization; using Robust.Server.GameObjects; using System.Collections.Generic; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Popups; namespace Content.Server.Chemistry.EntitySystems @@ -53,7 +54,7 @@ namespace Content.Server.Chemistry.EntitySystems verb.Category = VerbCategory.SetTransferAmount; verb.Act = () => { - component.TransferAmount = ReagentUnit.New(amount); + component.TransferAmount = FixedPoint2.New(amount); args.User.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount))); }; diff --git a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs index 3430993b3d..f3cb54896d 100644 --- a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs @@ -2,6 +2,7 @@ using Content.Server.Chemistry.Components.SolutionManager; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Physics; using Content.Shared.Vapor; using JetBrains.Annotations; @@ -104,7 +105,7 @@ namespace Content.Server.Chemistry.EntitySystems var tile = mapGrid.GetTileRef(entity.Transform.Coordinates.ToVector2i(EntityManager, _mapManager)); foreach (var reagentQuantity in contents.Contents.ToArray()) { - if (reagentQuantity.Quantity == ReagentUnit.Zero) continue; + if (reagentQuantity.Quantity == FixedPoint2.Zero) continue; var reagent = _protoManager.Index(reagentQuantity.ReagentId); _solutionContainerSystem.TryRemoveReagent(vapor.Owner.Uid, contents, reagentQuantity.ReagentId, reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f)); diff --git a/Content.Server/Chemistry/ReagentEffectConditions/ReagentThreshold.cs b/Content.Server/Chemistry/ReagentEffectConditions/ReagentThreshold.cs index c2419d82a4..ed89541272 100644 --- a/Content.Server/Chemistry/ReagentEffectConditions/ReagentThreshold.cs +++ b/Content.Server/Chemistry/ReagentEffectConditions/ReagentThreshold.cs @@ -1,5 +1,6 @@ using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; @@ -12,10 +13,10 @@ namespace Content.Server.Chemistry.ReagentEffectConditions public class ReagentThreshold : ReagentEffectCondition { [DataField("min")] - public ReagentUnit Min = ReagentUnit.Zero; + public FixedPoint2 Min = FixedPoint2.Zero; [DataField("max")] - public ReagentUnit Max = ReagentUnit.MaxValue; + public FixedPoint2 Max = FixedPoint2.MaxValue; public override bool Condition(IEntity solutionEntity, Solution.ReagentQuantity reagent) { diff --git a/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs b/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs index d4e9007bec..6ae5f56dc3 100644 --- a/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs +++ b/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.Chemistry.EntitySystems; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; @@ -19,7 +20,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions // ReSharper disable once CollectionNeverUpdated.Local private readonly HashSet _reagents = new(); - protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source) + protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source) { // TODO see if this is correct if (!EntitySystem.Get() diff --git a/Content.Server/Chemistry/ReagentEntityReactions/ExtinguishReaction.cs b/Content.Server/Chemistry/ReagentEntityReactions/ExtinguishReaction.cs index b306bed33d..b252f9abd8 100644 --- a/Content.Server/Chemistry/ReagentEntityReactions/ExtinguishReaction.cs +++ b/Content.Server/Chemistry/ReagentEntityReactions/ExtinguishReaction.cs @@ -3,6 +3,7 @@ using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; @@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions // ReSharper disable once CollectionNeverUpdated.Local private readonly HashSet _reagents = new (); - protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source) + protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source) { if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return; diff --git a/Content.Server/Chemistry/ReagentEntityReactions/FlammableReaction.cs b/Content.Server/Chemistry/ReagentEntityReactions/FlammableReaction.cs index 25673c96f9..0585f60cb8 100644 --- a/Content.Server/Chemistry/ReagentEntityReactions/FlammableReaction.cs +++ b/Content.Server/Chemistry/ReagentEntityReactions/FlammableReaction.cs @@ -3,6 +3,7 @@ using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; @@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions // ReSharper disable once CollectionNeverUpdated.Local private readonly HashSet _reagents = new (); - protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source) + protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source) { if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return; diff --git a/Content.Server/Chemistry/ReagentEntityReactions/WashCreamPieReaction.cs b/Content.Server/Chemistry/ReagentEntityReactions/WashCreamPieReaction.cs index 5676ce0bce..36e62a1105 100644 --- a/Content.Server/Chemistry/ReagentEntityReactions/WashCreamPieReaction.cs +++ b/Content.Server/Chemistry/ReagentEntityReactions/WashCreamPieReaction.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.Nutrition.EntitySystems; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Nutrition.Components; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions // ReSharper disable once CollectionNeverUpdated.Local private readonly HashSet _reagents = new (); - protected override void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Solution? source) + protected override void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Solution? source) { if (!entity.TryGetComponent(out CreamPiedComponent? creamPied) || !_reagents.Contains(reagent.ID)) return; diff --git a/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs b/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs index c2101d8704..79192ee579 100644 --- a/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs @@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.Map; using Robust.Shared.Serialization.Manager.Attributes; @@ -13,10 +14,10 @@ namespace Content.Server.Chemistry.TileReactions [DataDefinition] public class CleanTileReaction : ITileReaction { - ReagentUnit ITileReaction.TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) + FixedPoint2 ITileReaction.TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume) { var entities = tile.GetEntitiesInTileFast().ToArray(); - var amount = ReagentUnit.Zero; + var amount = FixedPoint2.Zero; foreach (var entity in entities) { if (entity.TryGetComponent(out CleanableComponent? cleanable)) diff --git a/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs b/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs index 5a1cdb877b..7ccbb5fb94 100644 --- a/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs @@ -5,6 +5,7 @@ using Content.Shared.Atmos; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Maps; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -19,17 +20,17 @@ namespace Content.Server.Chemistry.TileReactions { [DataField("coolingTemperature")] private float _coolingTemperature = 2f; - public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) + public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume) { - if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) - return ReagentUnit.Zero; + if (reactVolume <= FixedPoint2.Zero || tile.Tile.IsEmpty) + return FixedPoint2.Zero; var atmosphereSystem = EntitySystem.Get(); var environment = atmosphereSystem.GetTileMixture(tile.GridIndex, tile.GridIndices, true); if (environment == null || !atmosphereSystem.IsHotspotActive(tile.GridIndex, tile.GridIndices)) - return ReagentUnit.Zero; + return FixedPoint2.Zero; environment.Temperature = MathF.Max(MathF.Min(environment.Temperature - (_coolingTemperature * 1000f), @@ -38,7 +39,7 @@ namespace Content.Server.Chemistry.TileReactions atmosphereSystem.React(tile.GridIndex, tile.GridIndices); atmosphereSystem.HotspotExtinguish(tile.GridIndex, tile.GridIndices); - return ReagentUnit.Zero; + return FixedPoint2.Zero; } } } diff --git a/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs b/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs index b82c9288e6..d953a6f42e 100644 --- a/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs @@ -4,6 +4,7 @@ using Content.Server.Atmos.EntitySystems; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Maps; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -18,16 +19,16 @@ namespace Content.Server.Chemistry.TileReactions { [DataField("temperatureMultiplier")] private float _temperatureMultiplier = 1.15f; - public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) + public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume) { - if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) - return ReagentUnit.Zero; + if (reactVolume <= FixedPoint2.Zero || tile.Tile.IsEmpty) + return FixedPoint2.Zero; var atmosphereSystem = EntitySystem.Get(); var environment = atmosphereSystem.GetTileMixture(tile.GridIndex, tile.GridIndices, true); if (environment == null || !atmosphereSystem.IsHotspotActive(tile.GridIndex, tile.GridIndices)) - return ReagentUnit.Zero; + return FixedPoint2.Zero; environment.Temperature *= MathF.Max(_temperatureMultiplier * reactVolume.Float(), 1f); atmosphereSystem.React(tile.GridIndex, tile.GridIndices); diff --git a/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs b/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs index a8674f9173..5a55b264eb 100644 --- a/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs @@ -2,6 +2,7 @@ using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.Map; using Robust.Shared.Serialization.Manager.Attributes; @@ -12,11 +13,11 @@ namespace Content.Server.Chemistry.TileReactions [DataDefinition] public class SpillIfPuddlePresentTileReaction : ITileReaction { - public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) + public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume) { - if (reactVolume < 5 || !tile.TryGetPuddle(null, out _)) return ReagentUnit.Zero; + if (reactVolume < 5 || !tile.TryGetPuddle(null, out _)) return FixedPoint2.Zero; - return tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", true, false) != null ? reactVolume : ReagentUnit.Zero; + return tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", true, false) != null ? reactVolume : FixedPoint2.Zero; } } } diff --git a/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs b/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs index 3c5116dc29..46a894adc2 100644 --- a/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs @@ -2,6 +2,7 @@ using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Slippery; using JetBrains.Annotations; using Robust.Shared.Map; @@ -18,9 +19,9 @@ namespace Content.Server.Chemistry.TileReactions [DataField("paralyzeTime")] private float _paralyzeTime = 1; [DataField("overflow")] private bool _overflow; - public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) + public FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume) { - if (reactVolume < 5) return ReagentUnit.Zero; + if (reactVolume < 5) return FixedPoint2.Zero; // TODO Make this not puddle smear. var puddle = tile.SpillAt(new Solution(reagent.ID, reactVolume), "PuddleSmear", _overflow, false); @@ -35,7 +36,7 @@ namespace Content.Server.Chemistry.TileReactions return reactVolume; } - return ReagentUnit.Zero; + return FixedPoint2.Zero; } } } diff --git a/Content.Server/Cleanable/CleanableComponent.cs b/Content.Server/Cleanable/CleanableComponent.cs index a9c34121e1..d87103c87c 100644 --- a/Content.Server/Cleanable/CleanableComponent.cs +++ b/Content.Server/Cleanable/CleanableComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -11,8 +12,8 @@ namespace Content.Server.Cleanable public override string Name => "Cleanable"; [DataField("cleanAmount")] - private ReagentUnit _cleanAmount = ReagentUnit.Zero; + private FixedPoint2 _cleanAmount = FixedPoint2.Zero; [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit CleanAmount => _cleanAmount; + public FixedPoint2 CleanAmount => _cleanAmount; } } diff --git a/Content.Server/Extinguisher/FireExtinguisherComponent.cs b/Content.Server/Extinguisher/FireExtinguisherComponent.cs index c2ace0bae3..982e0fa889 100644 --- a/Content.Server/Extinguisher/FireExtinguisherComponent.cs +++ b/Content.Server/Extinguisher/FireExtinguisherComponent.cs @@ -9,6 +9,7 @@ using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Sound; using Content.Shared.Extinguisher; +using Content.Shared.FixedPoint; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; @@ -63,7 +64,7 @@ namespace Content.Server.Extinguisher && solutionContainerSystem.TryGetDrainableSolution(targetEntity.Uid, out var targetSolution) && solutionContainerSystem.TryGetDrainableSolution(Owner.Uid, out var container)) { - var transfer = ReagentUnit.Min(container.AvailableVolume, targetSolution.DrainAvailable); + var transfer = FixedPoint2.Min(container.AvailableVolume, targetSolution.DrainAvailable); if (transfer > 0) { var drained = solutionContainerSystem.Drain(targetEntity.Uid, targetSolution, transfer); diff --git a/Content.Server/Fluids/Components/BucketComponent.cs b/Content.Server/Fluids/Components/BucketComponent.cs index c3253c09ce..b4f5695e35 100644 --- a/Content.Server/Fluids/Components/BucketComponent.cs +++ b/Content.Server/Fluids/Components/BucketComponent.cs @@ -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 _currentlyUsing = new(); - public ReagentUnit MaxVolume + public FixedPoint2 MaxVolume { get => EntitySystem.Get().TryGetSolution(Owner.Uid, SolutionName, out var solution) ? solution.MaxVolume - : ReagentUnit.Zero; + : FixedPoint2.Zero; set { if (EntitySystem.Get().TryGetSolution(Owner.Uid, SolutionName, out var solution)) @@ -41,9 +42,9 @@ namespace Content.Server.Fluids.Components } } - public ReagentUnit CurrentVolume => EntitySystem.Get().TryGetSolution(Owner.Uid, SolutionName, out var solution) + public FixedPoint2 CurrentVolume => EntitySystem.Get().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; diff --git a/Content.Server/Fluids/Components/EvaporationComponent.cs b/Content.Server/Fluids/Components/EvaporationComponent.cs index 0e9f089c36..d3eec2c6a5 100644 --- a/Content.Server/Fluids/Components/EvaporationComponent.cs +++ b/Content.Server/Fluids/Components/EvaporationComponent.cs @@ -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"; /// - /// 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. /// [DataField("evaporateTime")] public float EvaporateTime { get; set; } = 5f; @@ -29,14 +30,14 @@ namespace Content.Server.Fluids.Components /// Defaults to evaporate completely. /// [DataField("lowerLimit")] - public ReagentUnit LowerLimit = ReagentUnit.Zero; + public FixedPoint2 LowerLimit = FixedPoint2.Zero; /// /// Upper limit below which puddle won't evaporate. Useful when wanting to make sure large puddle will /// remain forever. Defaults to . /// [DataField("upperLimit")] - public ReagentUnit UpperLimit = PuddleComponent.DefaultOverflowVolume; + public FixedPoint2 UpperLimit = PuddleComponent.DefaultOverflowVolume; /// /// The time accumulated since the start. diff --git a/Content.Server/Fluids/Components/MopComponent.cs b/Content.Server/Fluids/Components/MopComponent.cs index 338032dab0..36f1eedb79 100644 --- a/Content.Server/Fluids/Components/MopComponent.cs +++ b/Content.Server/Fluids/Components/MopComponent.cs @@ -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(); @@ -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 diff --git a/Content.Server/Fluids/Components/PuddleComponent.cs b/Content.Server/Fluids/Components/PuddleComponent.cs index 3a62bfd3b6..bd020bf788 100644 --- a/Content.Server/Fluids/Components/PuddleComponent.cs +++ b/Content.Server/Fluids/Components/PuddleComponent.cs @@ -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().CurrentVolume(Owner.Uid); + public FixedPoint2 CurrentVolume => EntitySystem.Get().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; } diff --git a/Content.Server/Fluids/Components/SpillExtensions.cs b/Content.Server/Fluids/Components/SpillExtensions.cs index a07ccfdd14..9b515efbad 100644 --- a/Content.Server/Fluids/Components/SpillExtensions.cs +++ b/Content.Server/Fluids/Components/SpillExtensions.cs @@ -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().Refill(spillEntity.Uid, solutionContainerComponent, - solution.SplitSolution(ReagentUnit.Min( + solution.SplitSolution(FixedPoint2.Min( solutionContainerComponent.AvailableVolume, solutionContainerComponent.MaxSpillRefill)) ); diff --git a/Content.Server/Fluids/Components/SprayComponent.cs b/Content.Server/Fluids/Components/SprayComponent.cs index d4f0faa901..7f3e7f651b 100644 --- a/Content.Server/Fluids/Components/SprayComponent.cs +++ b/Content.Server/Fluids/Components/SprayComponent.cs @@ -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 /// [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().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().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)); diff --git a/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs b/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs index 59261fa866..0ca5a761bf 100644 --- a/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs +++ b/Content.Server/Fluids/EntitySystems/EvaporationSystem.cs @@ -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) { diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs index 6e273f1aaf..b271435bc4 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs @@ -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 }; var overflownPuddles = new List(); - 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, diff --git a/Content.Server/Kitchen/Components/MicrowaveComponent.cs b/Content.Server/Kitchen/Components/MicrowaveComponent.cs index d436556549..f86613b5f5 100644 --- a/Content.Server/Kitchen/Components/MicrowaveComponent.cs +++ b/Content.Server/Kitchen/Components/MicrowaveComponent.cs @@ -15,6 +15,7 @@ using Content.Shared.Body.Components; using Content.Shared.Body.Part; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Kitchen; using Content.Shared.Kitchen.Components; @@ -263,7 +264,7 @@ namespace Content.Server.Kitchen.Components } //Get transfer amount. May be smaller than _transferAmount if not enough room - var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, solution.AvailableVolume); + var realTransferAmount = FixedPoint2.Min(attackPourable.TransferAmount, solution.AvailableVolume); if (realTransferAmount <= 0) //Special message if container is full { Owner.PopupMessage(eventArgs.User, @@ -440,7 +441,7 @@ namespace Content.Server.Kitchen.Components foreach (var recipeReagent in recipe.IngredientsReagents) { EntitySystem.Get() - .TryRemoveReagent(solutionUid, solution, recipeReagent.Key, ReagentUnit.New(recipeReagent.Value)); + .TryRemoveReagent(solutionUid, solution, recipeReagent.Key, FixedPoint2.New(recipeReagent.Value)); } foreach (var recipeSolid in recipe.IngredientsSolids) diff --git a/Content.Server/MobState/States/NormalMobState.cs b/Content.Server/MobState/States/NormalMobState.cs index 34212a1d4f..c4c68277e2 100644 --- a/Content.Server/MobState/States/NormalMobState.cs +++ b/Content.Server/MobState/States/NormalMobState.cs @@ -1,6 +1,7 @@ using Content.Server.Alert; using Content.Shared.Alert; using Content.Shared.Damage; +using Content.Shared.FixedPoint; using Content.Shared.MobState; using Content.Shared.MobState.State; using Robust.Shared.GameObjects; @@ -9,7 +10,7 @@ namespace Content.Server.MobState.States { public class NormalMobState : SharedNormalMobState { - public override void UpdateState(IEntity entity, int threshold) + public override void UpdateState(IEntity entity, FixedPoint2 threshold) { base.UpdateState(entity, threshold); diff --git a/Content.Server/Nutrition/Components/DrinkComponent.cs b/Content.Server/Nutrition/Components/DrinkComponent.cs index a3963b329e..54d9393cac 100644 --- a/Content.Server/Nutrition/Components/DrinkComponent.cs +++ b/Content.Server/Nutrition/Components/DrinkComponent.cs @@ -5,6 +5,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using Content.Server.Nutrition.EntitySystems; +using Content.Shared.FixedPoint; using Robust.Shared.Analyzers; namespace Content.Server.Nutrition.Components @@ -28,7 +29,7 @@ namespace Content.Server.Nutrition.Components internal bool DefaultToOpened; [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount { get; [UsedImplicitly] private set; } = ReagentUnit.New(5); + public FixedPoint2 TransferAmount { get; [UsedImplicitly] private set; } = FixedPoint2.New(5); [ViewVariables(VVAccess.ReadWrite)] public bool Opened; diff --git a/Content.Server/Nutrition/Components/FoodComponent.cs b/Content.Server/Nutrition/Components/FoodComponent.cs index 6e8fcbc22a..2bebd99b09 100644 --- a/Content.Server/Nutrition/Components/FoodComponent.cs +++ b/Content.Server/Nutrition/Components/FoodComponent.cs @@ -8,6 +8,7 @@ using Content.Server.Hands.Components; using Content.Server.Items; using Content.Shared.Body.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using Content.Shared.Popups; @@ -42,7 +43,7 @@ namespace Content.Server.Nutrition.Components [ViewVariables] [DataField("transferAmount")] - private ReagentUnit? TransferAmount { get; set; } = ReagentUnit.New(5); + private FixedPoint2? TransferAmount { get; set; } = FixedPoint2.New(5); [DataField("utensilsNeeded")] private UtensilType _utensilsNeeded = UtensilType.None; @@ -65,7 +66,7 @@ namespace Content.Server.Nutrition.Components return solution.CurrentVolume == 0 ? 0 - : Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / (ReagentUnit)TransferAmount).Float())); + : Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / (FixedPoint2)TransferAmount).Float())); } } @@ -162,7 +163,7 @@ namespace Content.Server.Nutrition.Components return false; } - var transferAmount = TransferAmount != null ? ReagentUnit.Min((ReagentUnit)TransferAmount, solution.CurrentVolume) : solution.CurrentVolume; + var transferAmount = TransferAmount != null ? FixedPoint2.Min((FixedPoint2)TransferAmount, solution.CurrentVolume) : solution.CurrentVolume; var split = solutionContainerSys.SplitSolution(Owner.Uid, solution, transferAmount); var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split)); diff --git a/Content.Server/Nutrition/Components/SliceableFoodComponent.cs b/Content.Server/Nutrition/Components/SliceableFoodComponent.cs index ba711de01c..458957de3f 100644 --- a/Content.Server/Nutrition/Components/SliceableFoodComponent.cs +++ b/Content.Server/Nutrition/Components/SliceableFoodComponent.cs @@ -5,6 +5,7 @@ using Content.Server.Hands.Components; using Content.Server.Items; using Content.Shared.Chemistry.Reagent; using Content.Shared.Examine; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Sound; using Robust.Shared.Audio; @@ -75,7 +76,7 @@ namespace Content.Server.Nutrition.Components // Basically, we want to: // 1. Split off a representative chunk var lostSolution = scs.SplitSolution(Owner.Uid, solution, - solution.CurrentVolume / ReagentUnit.New(Count)); + solution.CurrentVolume / FixedPoint2.New(Count)); // 2. Delete the Nutriment (it's already in the target) so we just have additives // It might be an idea to remove the removal of Nutriment & clear the food lostSolution.RemoveReagent("Nutriment", lostSolution.GetReagentQuantity("Nutriment")); diff --git a/Content.Server/Nutrition/Components/SmokableComponent.cs b/Content.Server/Nutrition/Components/SmokableComponent.cs index de78fc6524..2c992dbadb 100644 --- a/Content.Server/Nutrition/Components/SmokableComponent.cs +++ b/Content.Server/Nutrition/Components/SmokableComponent.cs @@ -1,5 +1,6 @@ using Content.Server.Nutrition.EntitySystems; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Smoking; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; @@ -19,7 +20,7 @@ namespace Content.Server.Nutrition.Components /// Solution inhale amount per second. /// [DataField("inhaleAmount")] - public ReagentUnit InhaleAmount { get; } = ReagentUnit.New(0.05f); + public FixedPoint2 InhaleAmount { get; } = FixedPoint2.New(0.05f); [DataField("state")] public SmokableState State { get; set; } = SmokableState.Unlit; diff --git a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs index 59b6b29c9d..828ceb0ddb 100644 --- a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs @@ -7,6 +7,7 @@ using Content.Server.Nutrition.Components; using Content.Shared.Body.Components; using Content.Shared.Chemistry.Reagent; using Content.Shared.Examine; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; using Content.Shared.Nutrition.Components; @@ -217,7 +218,7 @@ namespace Content.Server.Nutrition.EntitySystems if (user != target && !user.InRangeUnobstructed(target, popup: true)) return false; - var transferAmount = ReagentUnit.Min(component.TransferAmount, interactions.DrainAvailable); + var transferAmount = FixedPoint2.Min(component.TransferAmount, interactions.DrainAvailable); var drain = _solutionContainerSystem.Drain(owner.Uid, interactions, transferAmount); var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(drain)); diff --git a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs index b07547f5ef..e000e8cdc2 100644 --- a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs @@ -5,6 +5,7 @@ using Content.Server.Chemistry.EntitySystems; using Content.Server.Nutrition.Components; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Smoking; using Content.Shared.Temperature; using Robust.Server.GameObjects; @@ -83,12 +84,12 @@ namespace Content.Server.Nutrition.EntitySystems var inhaledSolution = _solutionContainerSystem.SplitSolution(uid, solution, smokable.InhaleAmount * _timer); - if (solution.TotalVolume == ReagentUnit.Zero) + if (solution.TotalVolume == FixedPoint2.Zero) { RaiseLocalEvent(uid, new SmokableSolutionEmptyEvent()); } - if (inhaledSolution.TotalVolume == ReagentUnit.Zero) + if (inhaledSolution.TotalVolume == FixedPoint2.Zero) continue; // This is awful. I hate this so much. diff --git a/Content.Server/Tools/Components/WelderComponent.cs b/Content.Server/Tools/Components/WelderComponent.cs index 680e8f8b39..9ffb0b5250 100644 --- a/Content.Server/Tools/Components/WelderComponent.cs +++ b/Content.Server/Tools/Components/WelderComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Sound; using Content.Shared.Tools.Components; using Robust.Shared.GameObjects; @@ -26,13 +27,13 @@ namespace Content.Server.Tools.Components /// Fuel consumption per second, while the welder is active. /// [DataField("fuelConsumption")] - public ReagentUnit FuelConsumption { get; } = ReagentUnit.New(0.05f); + public FixedPoint2 FuelConsumption { get; } = FixedPoint2.New(0.05f); /// /// A fuel amount to be consumed when the welder goes from being unlit to being lit. /// [DataField("welderOnConsume")] - public ReagentUnit FuelLitCost { get; } = ReagentUnit.New(0.5f); + public FixedPoint2 FuelLitCost { get; } = FixedPoint2.New(0.5f); /// /// Sound played when the welder is turned off. diff --git a/Content.Server/Tools/ToolSystem.Welder.cs b/Content.Server/Tools/ToolSystem.Welder.cs index 65884be0a2..7b1ddda95f 100644 --- a/Content.Server/Tools/ToolSystem.Welder.cs +++ b/Content.Server/Tools/ToolSystem.Welder.cs @@ -8,6 +8,7 @@ using Content.Server.Tools.Components; using Content.Shared.Audio; using Content.Shared.Chemistry.Reagent; using Content.Shared.Examine; +using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Temperature; @@ -43,11 +44,11 @@ namespace Content.Server.Tools SubscribeLocalEvent(OnWelderGetState); } - public (ReagentUnit fuel, ReagentUnit capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null) + public (FixedPoint2 fuel, FixedPoint2 capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null) { if (!Resolve(uid, ref welder, ref solutionContainer) || !_solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var fuelSolution, solutionContainer)) - return (ReagentUnit.Zero, ReagentUnit.Zero); + return (FixedPoint2.Zero, FixedPoint2.Zero); return (_solutionContainerSystem.GetReagentQuantity(uid, welder.FuelReagent), fuelSolution.MaxVolume); } @@ -88,7 +89,7 @@ namespace Content.Server.Tools var fuel = solution.GetReagentQuantity(welder.FuelReagent); // Not enough fuel to lit welder. - if (fuel == ReagentUnit.Zero || fuel < welder.FuelLitCost) + if (fuel == FixedPoint2.Zero || fuel < welder.FuelLitCost) { if(user != null) _popupSystem.PopupEntity(Loc.GetString("welder-component-no-fuel-message"), uid, Filter.Entities(user.Value)); @@ -182,7 +183,7 @@ namespace Content.Server.Tools var (fuel, capacity) = GetWelderFuelAndCapacity(uid, welder); args.PushMarkup(Loc.GetString("welder-component-on-examine-detailed-message", - ("colorName", fuel < capacity / ReagentUnit.New(4f) ? "darkorange" : "orange"), + ("colorName", fuel < capacity / FixedPoint2.New(4f) ? "darkorange" : "orange"), ("fuelLeft", fuel), ("fuelCapacity", capacity))); } @@ -213,7 +214,7 @@ namespace Content.Server.Tools && _solutionContainerSystem.TryGetDrainableSolution(args.Target.Uid, out var targetSolution) && _solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var welderSolution)) { - var trans = ReagentUnit.Min(welderSolution.AvailableVolume, targetSolution.DrainAvailable); + var trans = FixedPoint2.Min(welderSolution.AvailableVolume, targetSolution.DrainAvailable); if (trans > 0) { var drained = _solutionContainerSystem.Drain(args.Target.Uid, targetSolution, trans); @@ -249,7 +250,7 @@ namespace Content.Server.Tools var (fuel, _) = GetWelderFuelAndCapacity(uid, welder); - if (ReagentUnit.New(args.Fuel) > fuel) + if (FixedPoint2.New(args.Fuel) > fuel) { _popupSystem.PopupEntity(Loc.GetString("welder-component-cannot-weld-message"), uid, Filter.Entities(args.User)); args.Cancel(); @@ -271,7 +272,7 @@ namespace Content.Server.Tools var (fuel, _) = GetWelderFuelAndCapacity(uid, welder); - var neededFuel = ReagentUnit.New(args.Fuel); + var neededFuel = FixedPoint2.New(args.Fuel); if (neededFuel > fuel) { @@ -320,7 +321,7 @@ namespace Content.Server.Tools solution.RemoveReagent(welder.FuelReagent, welder.FuelConsumption * _welderTimer); - if (solution.GetReagentQuantity(welder.FuelReagent) <= ReagentUnit.Zero) + if (solution.GetReagentQuantity(welder.FuelReagent) <= FixedPoint2.Zero) TryTurnWelderOff(tool, null, welder); welder.Dirty(); diff --git a/Content.Shared/Administration/AdminAddReagentEuiState.cs b/Content.Shared/Administration/AdminAddReagentEuiState.cs index 9ec07d041a..23a15fb1e7 100644 --- a/Content.Shared/Administration/AdminAddReagentEuiState.cs +++ b/Content.Shared/Administration/AdminAddReagentEuiState.cs @@ -2,6 +2,7 @@ using System; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reagent; using Content.Shared.Eui; +using Content.Shared.FixedPoint; using Robust.Shared.Serialization; namespace Content.Shared.Administration @@ -9,8 +10,8 @@ namespace Content.Shared.Administration [Serializable, NetSerializable] public sealed class AdminAddReagentEuiState : EuiStateBase { - public ReagentUnit MaxVolume; - public ReagentUnit CurVolume; + public FixedPoint2 MaxVolume; + public FixedPoint2 CurVolume; } public static class AdminAddReagentEuiMsg @@ -25,7 +26,7 @@ namespace Content.Shared.Administration public sealed class DoAdd : EuiMessageBase { public bool CloseAfter; - public ReagentUnit Amount; + public FixedPoint2 Amount; public string ReagentId = string.Empty; } } diff --git a/Content.Shared/Chemistry/ChemistrySystem.cs b/Content.Shared/Chemistry/ChemistrySystem.cs index 41cc37a34f..65c6dd8093 100644 --- a/Content.Shared/Chemistry/ChemistrySystem.cs +++ b/Content.Shared/Chemistry/ChemistrySystem.cs @@ -1,6 +1,7 @@ using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -21,14 +22,14 @@ namespace Content.Shared.Chemistry } } - public void ReactionEntity(IEntity entity, ReactionMethod method, string reagentId, ReagentUnit reactVolume, Solution? source) + public void ReactionEntity(IEntity entity, ReactionMethod method, string reagentId, FixedPoint2 reactVolume, Solution? source) { // We throw if the reagent specified doesn't exist. ReactionEntity(entity, method, _prototypeManager.Index(reagentId), reactVolume, source); } public void ReactionEntity(IEntity entity, ReactionMethod method, ReagentPrototype reagent, - ReagentUnit reactVolume, Solution? source) + FixedPoint2 reactVolume, Solution? source) { if (entity == null || entity.Deleted || !entity.TryGetComponent(out ReactiveComponent? reactive)) return; diff --git a/Content.Shared/Chemistry/Components/SharedChemMasterComponent.cs b/Content.Shared/Chemistry/Components/SharedChemMasterComponent.cs index 7a0b30748a..2e01bc8080 100644 --- a/Content.Shared/Chemistry/Components/SharedChemMasterComponent.cs +++ b/Content.Shared/Chemistry/Components/SharedChemMasterComponent.cs @@ -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; /// @@ -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 containerReagents, IReadOnlyList bufferReagents, bool bufferModeTransfer, ReagentUnit bufferCurrentVolume) + public ChemMasterBoundUserInterfaceState(bool hasPower, bool hasBeaker, FixedPoint2 beakerCurrentVolume, FixedPoint2 beakerMaxVolume, string containerName, + string dispenserName, IReadOnlyList containerReagents, IReadOnlyList 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) diff --git a/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs b/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs index 8f5e9836fa..9ab0e15b88 100644 --- a/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs +++ b/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs @@ -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; diff --git a/Content.Shared/Chemistry/Components/SharedInjectorComponent.cs b/Content.Shared/Chemistry/Components/SharedInjectorComponent.cs index c2ff3487eb..05d955949a 100644 --- a/Content.Shared/Chemistry/Components/SharedInjectorComponent.cs +++ b/Content.Shared/Chemistry/Components/SharedInjectorComponent.cs @@ -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; diff --git a/Content.Shared/Chemistry/Components/Solution.Managerial.cs b/Content.Shared/Chemistry/Components/Solution.Managerial.cs index 482c57d076..493c38f9a4 100644 --- a/Content.Shared/Chemistry/Components/Solution.Managerial.cs +++ b/Content.Shared/Chemistry/Components/Solution.Managerial.cs @@ -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. /// [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; /// /// 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; } /// /// Initially set . If empty will be calculated based - /// on sum of reagent units. + /// on sum of fixed units. /// - [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; } } diff --git a/Content.Shared/Chemistry/Components/Solution.cs b/Content.Shared/Chemistry/Components/Solution.cs index 5aeb4f2c8d..3a11c7e584 100644 --- a/Content.Shared/Chemistry/Components/Solution.cs +++ b/Content.Shared/Chemistry/Components/Solution.cs @@ -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). /// [ViewVariables] - public ReagentUnit TotalVolume { get; set; } + public FixedPoint2 TotalVolume { get; set; } public Color Color => GetColor(); @@ -46,14 +47,14 @@ namespace Content.Shared.Chemistry.Components /// /// The prototype ID of the reagent to add. /// The quantity in milli-units. - 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 /// /// The prototype ID of the reagent to add. /// The quantity in milli-units. - 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 /// /// The prototype ID of the reagent to add. /// The quantity in milli-units. - 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. /// /// The quantity of this solution to remove - 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(); 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))] 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; diff --git a/Content.Shared/Chemistry/Dispenser/SharedReagentDispenserComponent.cs b/Content.Shared/Chemistry/Dispenser/SharedReagentDispenserComponent.cs index 56ef705e2a..407c18b8c2 100644 --- a/Content.Shared/Chemistry/Dispenser/SharedReagentDispenserComponent.cs +++ b/Content.Shared/Chemistry/Dispenser/SharedReagentDispenserComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; @@ -26,8 +27,8 @@ namespace Content.Shared.Chemistry.Dispenser { 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; /// /// A list of the reagents which this dispenser can dispense. @@ -38,10 +39,10 @@ namespace Content.Shared.Chemistry.Dispenser /// public readonly List? ContainerReagents; public readonly string DispenserName; - public readonly ReagentUnit SelectedDispenseAmount; + public readonly FixedPoint2 SelectedDispenseAmount; - public ReagentDispenserBoundUserInterfaceState(bool hasPower, bool hasBeaker, ReagentUnit beakerCurrentVolume, ReagentUnit beakerMaxVolume, string containerName, - List inventory, string dispenserName, List? containerReagents, ReagentUnit selectedDispenseAmount) + public ReagentDispenserBoundUserInterfaceState(bool hasPower, bool hasBeaker, FixedPoint2 beakerCurrentVolume, FixedPoint2 beakerMaxVolume, string containerName, + List inventory, string dispenserName, List? containerReagents, FixedPoint2 selectedDispenseAmount) { HasPower = hasPower; HasBeaker = hasBeaker; diff --git a/Content.Shared/Chemistry/Reaction/ITileReaction.cs b/Content.Shared/Chemistry/Reaction/ITileReaction.cs index 8310652b11..1f6a6bf307 100644 --- a/Content.Shared/Chemistry/Reaction/ITileReaction.cs +++ b/Content.Shared/Chemistry/Reaction/ITileReaction.cs @@ -1,10 +1,11 @@ using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.Map; namespace Content.Shared.Chemistry.Reaction { public interface ITileReaction { - ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume); + FixedPoint2 TileReact(TileRef tile, ReagentPrototype reagent, FixedPoint2 reactVolume); } } diff --git a/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs b/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs index e52b801069..dc2edfa125 100644 --- a/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs +++ b/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Content.Shared.Sound; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; @@ -14,7 +15,7 @@ namespace Content.Shared.Chemistry.Reaction public class ReactionPrototype : IPrototype { [DataField("reactants")] private Dictionary _reactants = new(); - [DataField("products")] private Dictionary _products = new(); + [DataField("products")] private Dictionary _products = new(); [DataField("effects", serverOnly: true)] private List _effects = new(); [ViewVariables] @@ -31,7 +32,7 @@ namespace Content.Shared.Chemistry.Reaction /// /// Reagents created when the reaction occurs. /// - public IReadOnlyDictionary Products => _products; + public IReadOnlyDictionary Products => _products; /// /// Effects to be triggered when the reaction occurs. /// @@ -48,14 +49,14 @@ namespace Content.Shared.Chemistry.Reaction public class ReactantPrototype { [DataField("amount")] - private ReagentUnit _amount = ReagentUnit.New(1); + private FixedPoint2 _amount = FixedPoint2.New(1); [DataField("catalyst")] private bool _catalyst; /// /// Minimum amount of the reactant needed for the reaction to occur. /// - public ReagentUnit Amount => _amount; + public FixedPoint2 Amount => _amount; /// /// Whether or not the reactant is a catalyst. Catalysts aren't removed when a reaction occurs. /// diff --git a/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs b/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs index d5f9fb6e8f..4835a996b6 100644 --- a/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs +++ b/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs @@ -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 /// The reaction to check. /// How many times this reaction can occur. /// - 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. /// - 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. /// - 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++) { diff --git a/Content.Shared/Chemistry/Reagent/ReagentEntityReaction.cs b/Content.Shared/Chemistry/Reagent/ReagentEntityReaction.cs index 3d96dc3bc8..ac7686abf6 100644 --- a/Content.Shared/Chemistry/Reagent/ReagentEntityReaction.cs +++ b/Content.Shared/Chemistry/Reagent/ReagentEntityReaction.cs @@ -1,4 +1,5 @@ using System; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -27,7 +28,7 @@ namespace Content.Shared.Chemistry.Reagent [DataField("ingestion")] public bool Ingestion { get; } = false; - public void React(ReactionMethod method, IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Components.Solution? source) + public void React(ReactionMethod method, IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Components.Solution? source) { switch (method) { @@ -50,6 +51,6 @@ namespace Content.Shared.Chemistry.Reagent React(entity, reagent, volume, source); } - protected abstract void React(IEntity entity, ReagentPrototype reagent, ReagentUnit volume, Components.Solution? source); + protected abstract void React(IEntity entity, ReagentPrototype reagent, FixedPoint2 volume, Components.Solution? source); } } diff --git a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs index 321dacd497..f4dd05b88e 100644 --- a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs +++ b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Shared.Botany; using Content.Shared.Chemistry.Reaction; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -77,9 +78,9 @@ namespace Content.Shared.Chemistry.Reagent return SubstanceColor; } - public ReagentUnit ReactionTile(TileRef tile, ReagentUnit reactVolume) + public FixedPoint2 ReactionTile(TileRef tile, FixedPoint2 reactVolume) { - var removed = ReagentUnit.Zero; + var removed = FixedPoint2.Zero; if (tile.Tile.IsEmpty) return removed; diff --git a/Content.Shared/Chemistry/SharedTransferAmount.cs b/Content.Shared/Chemistry/SharedTransferAmount.cs index b983d1ed5f..36dbf29fc1 100644 --- a/Content.Shared/Chemistry/SharedTransferAmount.cs +++ b/Content.Shared/Chemistry/SharedTransferAmount.cs @@ -1,5 +1,6 @@ using System; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; @@ -8,10 +9,10 @@ namespace Content.Shared.Chemistry [Serializable, NetSerializable] public class TransferAmountBoundInterfaceState : BoundUserInterfaceState { - public ReagentUnit Max; - public ReagentUnit Min; + public FixedPoint2 Max; + public FixedPoint2 Min; - public TransferAmountBoundInterfaceState(ReagentUnit max, ReagentUnit min) + public TransferAmountBoundInterfaceState(FixedPoint2 max, FixedPoint2 min) { Max = max; Min = min; @@ -21,9 +22,9 @@ namespace Content.Shared.Chemistry [Serializable, NetSerializable] public class TransferAmountSetValueMessage : BoundUserInterfaceMessage { - public ReagentUnit Value; + public FixedPoint2 Value; - public TransferAmountSetValueMessage(ReagentUnit value) + public TransferAmountSetValueMessage(FixedPoint2 value) { Value = value; } diff --git a/Content.Shared/Damage/DamageSpecifier.cs b/Content.Shared/Damage/DamageSpecifier.cs index 677caab595..bf589efbcb 100644 --- a/Content.Shared/Damage/DamageSpecifier.cs +++ b/Content.Shared/Damage/DamageSpecifier.cs @@ -9,12 +9,10 @@ using Robust.Shared.ViewVariables; using System; using System.Collections.Generic; using System.Linq; +using Content.Shared.FixedPoint; namespace Content.Shared.Damage { - // TODO DAMAGE UNITS Move this whole class away from, using integers. Also get rid of a lot of the rounding. Just - // use DamageUnit math operators. - /// /// This class represents a collection of damage types and damage values. /// @@ -25,17 +23,17 @@ namespace Content.Shared.Damage [DataDefinition] public class DamageSpecifier { - [DataField("types", customTypeSerializer: typeof(PrototypeIdDictionarySerializer))] - private readonly Dictionary? _damageTypeDictionary; + [DataField("types", customTypeSerializer: typeof(PrototypeIdDictionarySerializer))] + private readonly Dictionary? _damageTypeDictionary; - [DataField("groups", customTypeSerializer: typeof(PrototypeIdDictionarySerializer))] - private readonly Dictionary? _damageGroupDictionary; + [DataField("groups", customTypeSerializer: typeof(PrototypeIdDictionarySerializer))] + private readonly Dictionary? _damageGroupDictionary; /// /// Main DamageSpecifier dictionary. Most DamageSpecifier functions exist to somehow modifying this. /// [ViewVariables(VVAccess.ReadWrite)] - public Dictionary DamageDict + public Dictionary DamageDict { get { @@ -45,7 +43,7 @@ namespace Content.Shared.Damage } set => _damageDict = value; } - private Dictionary? _damageDict; + private Dictionary? _damageDict; /// /// Sum of the damage values. @@ -55,7 +53,7 @@ namespace Content.Shared.Damage /// in another. For this purpose, you should instead use and then check the property. /// - public int Total => DamageDict.Values.Sum(); + public FixedPoint2 Total => DamageDict.Values.Sum(); /// /// Whether this damage specifier has any entries. @@ -79,7 +77,7 @@ namespace Content.Shared.Damage /// /// Constructor that takes a single damage type prototype and a damage value. /// - public DamageSpecifier(DamageTypePrototype type, int value) + public DamageSpecifier(DamageTypePrototype type, FixedPoint2 value) { DamageDict = new() { { type.ID, value } }; } @@ -87,14 +85,14 @@ namespace Content.Shared.Damage /// /// Constructor that takes a single damage group prototype and a damage value. The value is divided between members of the damage group. /// - public DamageSpecifier(DamageGroupPrototype group, int value) + public DamageSpecifier(DamageGroupPrototype group, FixedPoint2 value) { _damageGroupDictionary = new() { { group.ID, value } }; } #endregion constructors /// - /// Combines the damage group and type datafield dictionaries into a single damage dictionary. + /// Combines the damage group and type datafield dictionaries FixedPoint2o a single damage dictionary. /// public void DeserializeDamage() { @@ -128,7 +126,7 @@ namespace Content.Shared.Damage var remainingDamage = entry.Value; foreach (var damageType in group.DamageTypes) { - var damage = remainingDamage / remainingTypes; + var damage = remainingDamage / FixedPoint2.New(remainingTypes); if (!_damageDict.TryAdd(damageType, damage)) { // Key already exists, add values @@ -149,7 +147,7 @@ namespace Content.Shared.Damage public static DamageSpecifier ApplyModifierSet(DamageSpecifier damageSpec, DamageModifierSet modifierSet) { // Make a copy of the given data. Don't modify the one passed to this function. I did this before, and weapons became - // duller as you hit walls. Neat, but not intended. And confusing, when you realize your fists don't work no + // duller as you hit walls. Neat, but not FixedPoint2ended. And confusing, when you realize your fists don't work no // more cause they're just bloody stumps. DamageSpecifier newDamage = new(damageSpec); @@ -157,7 +155,7 @@ namespace Content.Shared.Damage { if (entry.Value <= 0) continue; - float newValue = entry.Value; + float newValue = entry.Value.Float(); if (modifierSet.FlatReduction.TryGetValue(entry.Key, out var reduction)) { @@ -165,7 +163,7 @@ namespace Content.Shared.Damage if (newValue <= 0) { // flat reductions cannot heal you - newDamage.DamageDict[entry.Key] = 0; + newDamage.DamageDict[entry.Key] = FixedPoint2.Zero; continue; } } @@ -173,10 +171,10 @@ namespace Content.Shared.Damage if (modifierSet.Coefficients.TryGetValue(entry.Key, out var coefficient)) { // negative coefficients **can** heal you. - newValue = MathF.Round(newValue*coefficient, MidpointRounding.AwayFromZero); + newValue = newValue * coefficient; } - newDamage.DamageDict[entry.Key] = (int) newValue; + newDamage.DamageDict[entry.Key] = FixedPoint2.New(newValue); } newDamage.TrimZeros(); @@ -218,7 +216,7 @@ namespace Content.Shared.Damage /// /// Clamps each damage value to be within the given range. /// - public void Clamp(int minValue = 0, int maxValue = 0) + public void Clamp(FixedPoint2 minValue, FixedPoint2 maxValue) { DebugTools.Assert(minValue < maxValue); ClampMax(maxValue); @@ -231,7 +229,7 @@ namespace Content.Shared.Damage /// /// Note that this only acts on damage types present in the dictionary. It will not add new damage types. /// - public void ClampMin(int minValue = 0) + public void ClampMin(FixedPoint2 minValue) { foreach (var (key, value) in DamageDict) { @@ -246,7 +244,7 @@ namespace Content.Shared.Damage /// Sets all damage values to be at most some number. Note that if a damage type is not present in the /// dictionary, these will not be added. /// - public void ClampMax(int maxValue = 0) + public void ClampMax(FixedPoint2 maxValue) { foreach (var (key, value) in DamageDict) { @@ -282,10 +280,10 @@ namespace Content.Shared.Damage /// /// If no members of the group are included in this specifier, returns false. /// - public bool TryGetDamageInGroup(DamageGroupPrototype group, out int total) + public bool TryGetDamageInGroup(DamageGroupPrototype group, out FixedPoint2 total) { bool containsMemeber = false; - total = 0; + total = FixedPoint2.Zero; foreach (var type in group.DamageTypes) { @@ -307,9 +305,9 @@ namespace Content.Shared.Damage /// total of each group. If no members of a group are present in this , the /// group is not included in the resulting dictionary. /// - public Dictionary GetDamagePerGroup() + public Dictionary GetDamagePerGroup() { - var damageGroupDict = new Dictionary(); + var damageGroupDict = new Dictionary(); foreach (var group in IoCManager.Resolve().EnumeratePrototypes()) { if (TryGetDamageInGroup(group, out var value)) @@ -321,7 +319,7 @@ namespace Content.Shared.Damage } #region Operators - public static DamageSpecifier operator *(DamageSpecifier damageSpec, int factor) + public static DamageSpecifier operator *(DamageSpecifier damageSpec, FixedPoint2 factor) { DamageSpecifier newDamage = new(); foreach (var entry in damageSpec.DamageDict) @@ -336,17 +334,17 @@ namespace Content.Shared.Damage DamageSpecifier newDamage = new(); foreach (var entry in damageSpec.DamageDict) { - newDamage.DamageDict.Add(entry.Key, (int) MathF.Round(entry.Value * factor, MidpointRounding.AwayFromZero)); + newDamage.DamageDict.Add(entry.Key, entry.Value * factor); } return newDamage; } - public static DamageSpecifier operator /(DamageSpecifier damageSpec, int factor) + public static DamageSpecifier operator /(DamageSpecifier damageSpec, FixedPoint2 factor) { DamageSpecifier newDamage = new(); foreach (var entry in damageSpec.DamageDict) { - newDamage.DamageDict.Add(entry.Key, (int) MathF.Round(entry.Value / (float) factor, MidpointRounding.AwayFromZero)); + newDamage.DamageDict.Add(entry.Key, entry.Value / factor); } return newDamage; } @@ -357,7 +355,7 @@ namespace Content.Shared.Damage foreach (var entry in damageSpec.DamageDict) { - newDamage.DamageDict.Add(entry.Key, (int) MathF.Round(entry.Value / factor, MidpointRounding.AwayFromZero)); + newDamage.DamageDict.Add(entry.Key, entry.Value / factor); } return newDamage; } @@ -387,7 +385,7 @@ namespace Content.Shared.Damage public static DamageSpecifier operator *(float factor, DamageSpecifier damageSpec) => damageSpec * factor; - public static DamageSpecifier operator *(int factor, DamageSpecifier damageSpec) => damageSpec * factor; + public static DamageSpecifier operator *(FixedPoint2 factor, DamageSpecifier damageSpec) => damageSpec * factor; } #endregion } diff --git a/Content.Shared/Damage/DamageableComponent.cs b/Content.Shared/Damage/DamageableComponent.cs index 52b77226f6..80283e52fe 100644 --- a/Content.Shared/Damage/DamageableComponent.cs +++ b/Content.Shared/Damage/DamageableComponent.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Content.Shared.Acts; using Content.Shared.Damage.Prototypes; +using Content.Shared.FixedPoint; using Content.Shared.Radiation; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; @@ -64,12 +65,12 @@ namespace Content.Shared.Damage /// Groups which have no members that are supported by this component will not be present in this /// dictionary. /// - [ViewVariables] public Dictionary DamagePerGroup = new(); + [ViewVariables] public Dictionary DamagePerGroup = new(); /// /// The sum of all damages in the DamageableComponent. /// - [ViewVariables] public int TotalDamage; + [ViewVariables] public FixedPoint2 TotalDamage; // Really these shouldn't be here. OnExplosion() and RadiationAct() should be handled elsewhere. [ViewVariables] @@ -82,7 +83,7 @@ namespace Content.Shared.Damage // TODO RADIATION Remove this. void IRadiationAct.RadiationAct(float frameTime, SharedRadiationPulseComponent radiation) { - var damageValue = Math.Max((int) (frameTime * radiation.RadsPerSecond), 1); + var damageValue = FixedPoint2.New(MathF.Max((frameTime * radiation.RadsPerSecond), 1)); // Radiation should really just be a damage group instead of a list of types. DamageSpecifier damage = new(); @@ -99,9 +100,9 @@ namespace Content.Shared.Damage { var damageValue = eventArgs.Severity switch { - ExplosionSeverity.Light => 20, - ExplosionSeverity.Heavy => 60, - ExplosionSeverity.Destruction => 250, + ExplosionSeverity.Light => FixedPoint2.New(20), + ExplosionSeverity.Heavy => FixedPoint2.New(60), + ExplosionSeverity.Destruction => FixedPoint2.New(250), _ => throw new ArgumentOutOfRangeException() }; @@ -119,11 +120,11 @@ namespace Content.Shared.Damage [Serializable, NetSerializable] public class DamageableComponentState : ComponentState { - public readonly Dictionary DamageDict; + public readonly Dictionary DamageDict; public readonly string? ModifierSetId; public DamageableComponentState( - Dictionary damageDict, + Dictionary damageDict, string? modifierSetId) { DamageDict = damageDict; diff --git a/Content.Shared/Damage/DamageableSystem.cs b/Content.Shared/Damage/DamageableSystem.cs index 8cd4680718..af450f80f9 100644 --- a/Content.Shared/Damage/DamageableSystem.cs +++ b/Content.Shared/Damage/DamageableSystem.cs @@ -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(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()) { - 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 /// /// Does nothing If the given damage value is negative. /// - public void SetAllDamage(DamageableComponent component, int newValue) + public void SetAllDamage(DamageableComponent component, FixedPoint2 newValue) { if (newValue < 0) { diff --git a/Content.Shared/Chemistry/Reagent/ReagentUnit.cs b/Content.Shared/FixedPoint/FixedPoint2.cs similarity index 54% rename from Content.Shared/Chemistry/Reagent/ReagentUnit.cs rename to Content.Shared/FixedPoint/FixedPoint2.cs index 6dcb02f93e..0b1bb1afb6 100644 --- a/Content.Shared/Chemistry/Reagent/ReagentUnit.cs +++ b/Content.Shared/FixedPoint/FixedPoint2.cs @@ -1,40 +1,42 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.Globalization; using System.Linq; using Robust.Shared.Serialization; -namespace Content.Shared.Chemistry.Reagent +namespace Content.Shared.FixedPoint { /// - /// Represents a quantity of reagent, to a precision of 0.01. + /// Represents a quantity of something, to a precision of 0.01. /// To enforce this level of precision, floats are shifted by 2 decimal points, rounded, and converted to an int. /// [Serializable] - public struct ReagentUnit : ISelfSerialize, IComparable, IEquatable + public struct FixedPoint2 : ISelfSerialize, IComparable, IEquatable { private int _value; private static readonly int Shift = 2; - public static ReagentUnit MaxValue { get; } = new(int.MaxValue); - public static ReagentUnit Epsilon { get; } = new(1); - public static ReagentUnit Zero { get; } = new(0); + public static FixedPoint2 MaxValue { get; } = new(int.MaxValue); + public static FixedPoint2 Epsilon { get; } = new(1); + public static FixedPoint2 Zero { get; } = new(0); private readonly double ShiftDown() { return _value / Math.Pow(10, Shift); } - private ReagentUnit(int value) + private FixedPoint2(int value) { _value = value; } - public static ReagentUnit New(int value) + public static FixedPoint2 New(int value) { return new(value * (int) Math.Pow(10, Shift)); } - public static ReagentUnit New(float value) + public static FixedPoint2 New(float value) { return new(FromFloat(value)); } @@ -44,12 +46,12 @@ namespace Content.Shared.Chemistry.Reagent return (int) MathF.Round(value * MathF.Pow(10, Shift), MidpointRounding.AwayFromZero); } - public static ReagentUnit New(double value) + public static FixedPoint2 New(double value) { return new((int) Math.Round(value * Math.Pow(10, Shift), MidpointRounding.AwayFromZero)); } - public static ReagentUnit New(string value) + public static FixedPoint2 New(string value) { return New(FloatFromString(value)); } @@ -59,41 +61,41 @@ namespace Content.Shared.Chemistry.Reagent return float.Parse(value, CultureInfo.InvariantCulture); } - public static ReagentUnit operator +(ReagentUnit a) => a; + public static FixedPoint2 operator +(FixedPoint2 a) => a; - public static ReagentUnit operator -(ReagentUnit a) => new(-a._value); + public static FixedPoint2 operator -(FixedPoint2 a) => new(-a._value); - public static ReagentUnit operator +(ReagentUnit a, ReagentUnit b) + public static FixedPoint2 operator +(FixedPoint2 a, FixedPoint2 b) => new(a._value + b._value); - public static ReagentUnit operator -(ReagentUnit a, ReagentUnit b) + public static FixedPoint2 operator -(FixedPoint2 a, FixedPoint2 b) => a + -b; - public static ReagentUnit operator *(ReagentUnit a, ReagentUnit b) + public static FixedPoint2 operator *(FixedPoint2 a, FixedPoint2 b) { var aD = a.ShiftDown(); var bD = b.ShiftDown(); return New(aD * bD); } - public static ReagentUnit operator *(ReagentUnit a, float b) + public static FixedPoint2 operator *(FixedPoint2 a, float b) { var aD = (float) a.ShiftDown(); return New(aD * b); } - public static ReagentUnit operator *(ReagentUnit a, double b) + public static FixedPoint2 operator *(FixedPoint2 a, double b) { var aD = a.ShiftDown(); return New(aD * b); } - public static ReagentUnit operator *(ReagentUnit a, int b) + public static FixedPoint2 operator *(FixedPoint2 a, int b) { return new(a._value * b); } - public static ReagentUnit operator /(ReagentUnit a, ReagentUnit b) + public static FixedPoint2 operator /(FixedPoint2 a, FixedPoint2 b) { if (b._value == 0) { @@ -104,62 +106,67 @@ namespace Content.Shared.Chemistry.Reagent return New(aD / bD); } - public static bool operator <=(ReagentUnit a, int b) + public static FixedPoint2 operator /(FixedPoint2 a, float b) + { + return a / FixedPoint2.New(b); + } + + public static bool operator <=(FixedPoint2 a, int b) { return a <= New(b); } - public static bool operator >=(ReagentUnit a, int b) + public static bool operator >=(FixedPoint2 a, int b) { return a >= New(b); } - public static bool operator <(ReagentUnit a, int b) + public static bool operator <(FixedPoint2 a, int b) { return a < New(b); } - public static bool operator >(ReagentUnit a, int b) + public static bool operator >(FixedPoint2 a, int b) { return a > New(b); } - public static bool operator ==(ReagentUnit a, int b) + public static bool operator ==(FixedPoint2 a, int b) { return a == New(b); } - public static bool operator !=(ReagentUnit a, int b) + public static bool operator !=(FixedPoint2 a, int b) { return a != New(b); } - public static bool operator ==(ReagentUnit a, ReagentUnit b) + public static bool operator ==(FixedPoint2 a, FixedPoint2 b) { return a.Equals(b); } - public static bool operator !=(ReagentUnit a, ReagentUnit b) + public static bool operator !=(FixedPoint2 a, FixedPoint2 b) { return !a.Equals(b); } - public static bool operator <=(ReagentUnit a, ReagentUnit b) + public static bool operator <=(FixedPoint2 a, FixedPoint2 b) { return a._value <= b._value; } - public static bool operator >=(ReagentUnit a, ReagentUnit b) + public static bool operator >=(FixedPoint2 a, FixedPoint2 b) { return a._value >= b._value; } - public static bool operator <(ReagentUnit a, ReagentUnit b) + public static bool operator <(FixedPoint2 a, FixedPoint2 b) { return a._value < b._value; } - public static bool operator >(ReagentUnit a, ReagentUnit b) + public static bool operator >(FixedPoint2 a, FixedPoint2 b) { return a._value > b._value; } @@ -179,22 +186,31 @@ namespace Content.Shared.Chemistry.Reagent return (int) ShiftDown(); } - public static ReagentUnit Min(params ReagentUnit[] reagentUnits) + // Implicit operators ftw + public static implicit operator FixedPoint2(float n) => FixedPoint2.New(n); + public static implicit operator FixedPoint2(double n) => FixedPoint2.New(n); + public static implicit operator FixedPoint2(int n) => FixedPoint2.New(n); + + public static explicit operator float(FixedPoint2 n) => n.Float(); + public static explicit operator double(FixedPoint2 n) => n.Double(); + public static explicit operator int(FixedPoint2 n) => n.Int(); + + public static FixedPoint2 Min(params FixedPoint2[] fixedPoints) { - return reagentUnits.Min(); + return fixedPoints.Min(); } - public static ReagentUnit Min(ReagentUnit a, ReagentUnit b) + public static FixedPoint2 Min(FixedPoint2 a, FixedPoint2 b) { return a < b ? a : b; } - public static ReagentUnit Max(ReagentUnit a, ReagentUnit b) + public static FixedPoint2 Max(FixedPoint2 a, FixedPoint2 b) { return a > b ? a : b; } - public static ReagentUnit Clamp(ReagentUnit reagent, ReagentUnit min, ReagentUnit max) + public static FixedPoint2 Clamp(FixedPoint2 reagent, FixedPoint2 min, FixedPoint2 max) { if (min > max) { @@ -206,7 +222,7 @@ namespace Content.Shared.Chemistry.Reagent public override readonly bool Equals(object? obj) { - return obj is ReagentUnit unit && + return obj is FixedPoint2 unit && _value == unit._value; } @@ -228,12 +244,12 @@ namespace Content.Shared.Chemistry.Reagent return ToString(); } - public readonly bool Equals(ReagentUnit other) + public readonly bool Equals(FixedPoint2 other) { return _value == other._value; } - public readonly int CompareTo(ReagentUnit other) + public readonly int CompareTo(FixedPoint2 other) { if(other._value > _value) { @@ -245,5 +261,21 @@ namespace Content.Shared.Chemistry.Reagent } return 0; } + + } + + public static class FixedPointEnumerableExt + { + public static FixedPoint2 Sum(this System.Collections.Generic.IEnumerable source) + { + var acc = FixedPoint2.Zero; + + foreach (var n in source) + { + acc += n; + } + + return acc; + } } } diff --git a/Content.Shared/MedicalScanner/SharedMedicalScannerComponent.cs b/Content.Shared/MedicalScanner/SharedMedicalScannerComponent.cs index a358aa8605..e3621fb936 100644 --- a/Content.Shared/MedicalScanner/SharedMedicalScannerComponent.cs +++ b/Content.Shared/MedicalScanner/SharedMedicalScannerComponent.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Content.Shared.Body.Components; using Content.Shared.Damage; using Content.Shared.DragDrop; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; @@ -16,8 +17,8 @@ namespace Content.Shared.MedicalScanner public class MedicalScannerBoundUserInterfaceState : BoundUserInterfaceState { public readonly EntityUid? Entity; - public readonly IReadOnlyDictionary DamagePerGroup; - public readonly IReadOnlyDictionary DamagePerType; + public readonly IReadOnlyDictionary DamagePerGroup; + public readonly IReadOnlyDictionary DamagePerType; public readonly bool IsScanned; public MedicalScannerBoundUserInterfaceState( diff --git a/Content.Shared/MobState/Components/MobStateComponent.cs b/Content.Shared/MobState/Components/MobStateComponent.cs index 7e00012368..10e42afaf3 100644 --- a/Content.Shared/MobState/Components/MobStateComponent.cs +++ b/Content.Shared/MobState/Components/MobStateComponent.cs @@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Shared.Alert; using Content.Shared.Damage; +using Content.Shared.FixedPoint; using Content.Shared.MobState.State; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; @@ -43,7 +44,7 @@ namespace Content.Shared.MobState.Components public IMobState? CurrentState { get; private set; } [ViewVariables] - public int? CurrentThreshold { get; private set; } + public FixedPoint2? CurrentThreshold { get; private set; } public IEnumerable> _highestToLowestStates => _lowestToHighestStates.Reverse(); @@ -59,7 +60,7 @@ namespace Content.Shared.MobState.Components else { // Initialize with some amount of damage, defaulting to 0. - UpdateState(Owner.GetComponentOrNull()?.TotalDamage ?? 0); + UpdateState(Owner.GetComponentOrNull()?.TotalDamage ?? FixedPoint2.Zero); } } @@ -122,7 +123,7 @@ namespace Content.Shared.MobState.Components return CurrentState?.IsIncapacitated() ?? false; } - public (IMobState state, int threshold)? GetState(int damage) + public (IMobState state, FixedPoint2 threshold)? GetState(FixedPoint2 damage) { foreach (var (threshold, state) in _highestToLowestStates) { @@ -136,9 +137,9 @@ namespace Content.Shared.MobState.Components } public bool TryGetState( - int damage, + FixedPoint2 damage, [NotNullWhen(true)] out IMobState? state, - out int threshold) + out FixedPoint2 threshold) { var highestState = GetState(damage); @@ -153,7 +154,7 @@ namespace Content.Shared.MobState.Components return true; } - private (IMobState state, int threshold)? GetEarliestState(int minimumDamage, Predicate predicate) + private (IMobState state, FixedPoint2 threshold)? GetEarliestState(FixedPoint2 minimumDamage, Predicate predicate) { foreach (var (threshold, state) in _lowestToHighestStates) { @@ -169,7 +170,7 @@ namespace Content.Shared.MobState.Components return null; } - private (IMobState state, int threshold)? GetPreviousState(int maximumDamage, Predicate predicate) + private (IMobState state, FixedPoint2 threshold)? GetPreviousState(FixedPoint2 maximumDamage, Predicate predicate) { foreach (var (threshold, state) in _highestToLowestStates) { @@ -185,30 +186,30 @@ namespace Content.Shared.MobState.Components return null; } - public (IMobState state, int threshold)? GetEarliestCriticalState(int minimumDamage) + public (IMobState state, FixedPoint2 threshold)? GetEarliestCriticalState(FixedPoint2 minimumDamage) { return GetEarliestState(minimumDamage, s => s.IsCritical()); } - public (IMobState state, int threshold)? GetEarliestIncapacitatedState(int minimumDamage) + public (IMobState state, FixedPoint2 threshold)? GetEarliestIncapacitatedState(FixedPoint2 minimumDamage) { return GetEarliestState(minimumDamage, s => s.IsIncapacitated()); } - public (IMobState state, int threshold)? GetEarliestDeadState(int minimumDamage) + public (IMobState state, FixedPoint2 threshold)? GetEarliestDeadState(FixedPoint2 minimumDamage) { return GetEarliestState(minimumDamage, s => s.IsDead()); } - public (IMobState state, int threshold)? GetPreviousCriticalState(int minimumDamage) + public (IMobState state, FixedPoint2 threshold)? GetPreviousCriticalState(FixedPoint2 minimumDamage) { return GetPreviousState(minimumDamage, s => s.IsCritical()); } private bool TryGetState( - (IMobState state, int threshold)? tuple, + (IMobState state, FixedPoint2 threshold)? tuple, [NotNullWhen(true)] out IMobState? state, - out int threshold) + out FixedPoint2 threshold) { if (tuple == null) { @@ -222,9 +223,9 @@ namespace Content.Shared.MobState.Components } public bool TryGetEarliestCriticalState( - int minimumDamage, + FixedPoint2 minimumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold) + out FixedPoint2 threshold) { var earliestState = GetEarliestCriticalState(minimumDamage); @@ -232,9 +233,9 @@ namespace Content.Shared.MobState.Components } public bool TryGetEarliestIncapacitatedState( - int minimumDamage, + FixedPoint2 minimumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold) + out FixedPoint2 threshold) { var earliestState = GetEarliestIncapacitatedState(minimumDamage); @@ -242,9 +243,9 @@ namespace Content.Shared.MobState.Components } public bool TryGetEarliestDeadState( - int minimumDamage, + FixedPoint2 minimumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold) + out FixedPoint2 threshold) { var earliestState = GetEarliestDeadState(minimumDamage); @@ -252,9 +253,9 @@ namespace Content.Shared.MobState.Components } public bool TryGetPreviousCriticalState( - int maximumDamage, + FixedPoint2 maximumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold) + out FixedPoint2 threshold) { var earliestState = GetPreviousCriticalState(maximumDamage); @@ -273,7 +274,7 @@ namespace Content.Shared.MobState.Components /// /// Updates the mob state.. /// - public void UpdateState(int damage) + public void UpdateState(FixedPoint2 damage) { if (!TryGetState(damage, out var newState, out var threshold)) { @@ -286,7 +287,7 @@ namespace Content.Shared.MobState.Components /// /// Sets the mob state and marks the component as dirty. /// - private void SetMobState(IMobState? old, (IMobState state, int threshold)? current) + private void SetMobState(IMobState? old, (IMobState state, FixedPoint2 threshold)? current) { if (!current.HasValue) { @@ -324,9 +325,9 @@ namespace Content.Shared.MobState.Components [Serializable, NetSerializable] public class MobStateComponentState : ComponentState { - public readonly int? CurrentThreshold; + public readonly FixedPoint2? CurrentThreshold; - public MobStateComponentState(int? currentThreshold) + public MobStateComponentState(FixedPoint2? currentThreshold) { CurrentThreshold = currentThreshold; } diff --git a/Content.Shared/MobState/IMobStateComponent.cs b/Content.Shared/MobState/IMobStateComponent.cs index 17d738205e..6f829170a5 100644 --- a/Content.Shared/MobState/IMobStateComponent.cs +++ b/Content.Shared/MobState/IMobStateComponent.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using Content.Shared.FixedPoint; using Content.Shared.MobState.State; using Robust.Shared.GameObjects; @@ -16,34 +17,34 @@ namespace Content.Shared.MobState bool IsIncapacitated(); - (IMobState state, int threshold)? GetEarliestIncapacitatedState(int minimumDamage); + (IMobState state, FixedPoint2 threshold)? GetEarliestIncapacitatedState(FixedPoint2 minimumDamage); - (IMobState state, int threshold)? GetEarliestCriticalState(int minimumDamage); + (IMobState state, FixedPoint2 threshold)? GetEarliestCriticalState(FixedPoint2 minimumDamage); - (IMobState state, int threshold)? GetEarliestDeadState(int minimumDamage); + (IMobState state, FixedPoint2 threshold)? GetEarliestDeadState(FixedPoint2 minimumDamage); - (IMobState state, int threshold)? GetPreviousCriticalState(int maximumDamage); + (IMobState state, FixedPoint2 threshold)? GetPreviousCriticalState(FixedPoint2 maximumDamage); bool TryGetEarliestIncapacitatedState( - int minimumDamage, + FixedPoint2 minimumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold); + out FixedPoint2 threshold); bool TryGetEarliestCriticalState( - int minimumDamage, + FixedPoint2 minimumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold); + out FixedPoint2 threshold); bool TryGetEarliestDeadState( - int minimumDamage, + FixedPoint2 minimumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold); + out FixedPoint2 threshold); bool TryGetPreviousCriticalState( - int maximumDamage, + FixedPoint2 maximumDamage, [NotNullWhen(true)] out IMobState? state, - out int threshold); + out FixedPoint2 threshold); - void UpdateState(int damage); + void UpdateState(FixedPoint2 damage); } } diff --git a/Content.Shared/MobState/State/BaseMobState.cs b/Content.Shared/MobState/State/BaseMobState.cs index 7c45cea2cf..620d48ca26 100644 --- a/Content.Shared/MobState/State/BaseMobState.cs +++ b/Content.Shared/MobState/State/BaseMobState.cs @@ -1,4 +1,5 @@ -using Robust.Shared.GameObjects; +using Content.Shared.FixedPoint; +using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.MobState.State @@ -32,6 +33,6 @@ namespace Content.Shared.MobState.State public virtual void ExitState(IEntity entity) { } - public virtual void UpdateState(IEntity entity, int threshold) { } + public virtual void UpdateState(IEntity entity, FixedPoint2 threshold) { } } } diff --git a/Content.Shared/MobState/State/IMobState.cs b/Content.Shared/MobState/State/IMobState.cs index 706baca857..c7c493e538 100644 --- a/Content.Shared/MobState/State/IMobState.cs +++ b/Content.Shared/MobState/State/IMobState.cs @@ -1,4 +1,5 @@ using Content.Shared.ActionBlocker; +using Content.Shared.FixedPoint; using Robust.Shared.GameObjects; namespace Content.Shared.MobState.State @@ -36,6 +37,6 @@ namespace Content.Shared.MobState.State /// /// Called when this state is updated. /// - void UpdateState(IEntity entity, int threshold); + void UpdateState(IEntity entity, FixedPoint2 threshold); } } diff --git a/Content.Tests/Shared/Chemistry/ReagentUnit_Tests.cs b/Content.Tests/Shared/Chemistry/FixedPoint2_Tests.cs similarity index 68% rename from Content.Tests/Shared/Chemistry/ReagentUnit_Tests.cs rename to Content.Tests/Shared/Chemistry/FixedPoint2_Tests.cs index c61cac87cb..b4e4c9772b 100644 --- a/Content.Tests/Shared/Chemistry/ReagentUnit_Tests.cs +++ b/Content.Tests/Shared/Chemistry/FixedPoint2_Tests.cs @@ -1,47 +1,48 @@ using System; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using NUnit.Framework; namespace Content.Tests.Shared.Chemistry { - [TestFixture, TestOf(typeof(ReagentUnit))] - public class ReagentUnit_Tests + [TestFixture, TestOf(typeof(FixedPoint2))] + public class FixedPoint2_Tests { [Test] [TestCase(1, "1")] [TestCase(0, "0")] [TestCase(-1, "-1")] - public void ReagentUnitIntegerTests(int value, string expected) + public void FixedPoint2IntegerTests(int value, string expected) { - var result = ReagentUnit.New(value); + var result = FixedPoint2.New(value); Assert.That($"{result}", Is.EqualTo(expected)); } [Test] [TestCase(1.001f, "1")] [TestCase(0.999f, "1")] - public void ReagentUnitFloatTests(float value, string expected) + public void FixedPoint2FloatTests(float value, string expected) { - var result = ReagentUnit.New(value); + var result = FixedPoint2.New(value); Assert.That($"{result}", Is.EqualTo(expected)); } [Test] [TestCase(1.001d, "1")] [TestCase(0.999d, "1")] - public void ReagentUnitDoubleTests(double value, string expected) + public void FixedPoint2DoubleTests(double value, string expected) { - var result = ReagentUnit.New(value); + var result = FixedPoint2.New(value); Assert.That($"{result}", Is.EqualTo(expected)); } [Test] [TestCase("1.005", "1.01")] [TestCase("0.999", "1")] - public void ReagentUnitStringTests(string value, string expected) + public void FixedPoint2StringTests(string value, string expected) { - var result = ReagentUnit.New(value); + var result = FixedPoint2.New(value); Assert.That($"{result}", Is.EqualTo(expected)); } @@ -52,8 +53,8 @@ namespace Content.Tests.Shared.Chemistry [TestCase(1f, 2.005f, "3.01")] public void CalculusPlus(float aFloat, float bFloat, string expected) { - var a = ReagentUnit.New(aFloat); - var b = ReagentUnit.New(bFloat); + var a = FixedPoint2.New(aFloat); + var b = FixedPoint2.New(bFloat); var result = a + b; @@ -66,8 +67,8 @@ namespace Content.Tests.Shared.Chemistry [TestCase(1f, 2.005f, "-1.01")] public void CalculusMinus(float aFloat, float bFloat, string expected) { - var a = ReagentUnit.New(aFloat); - var b = ReagentUnit.New(bFloat); + var a = FixedPoint2.New(aFloat); + var b = FixedPoint2.New(bFloat); var result = a - b; @@ -80,8 +81,8 @@ namespace Content.Tests.Shared.Chemistry [TestCase(2.1f, 3f, "0.7")] public void CalculusDivision(float aFloat, float bFloat, string expected) { - var a = ReagentUnit.New(aFloat); - var b = ReagentUnit.New(bFloat); + var a = FixedPoint2.New(aFloat); + var b = FixedPoint2.New(bFloat); var result = a / b; @@ -93,8 +94,8 @@ namespace Content.Tests.Shared.Chemistry [TestCase(0.999f, 3f, "3")] public void CalculusMultiplication(float aFloat, float bFloat, string expected) { - var a = ReagentUnit.New(aFloat); - var b = ReagentUnit.New(bFloat); + var a = FixedPoint2.New(aFloat); + var b = FixedPoint2.New(bFloat); var result = a * b; @@ -112,18 +113,18 @@ namespace Content.Tests.Shared.Chemistry } [Test] - public void ReagentUnitMin() + public void FixedPoint2Min() { var unorderedList = new[] { - ReagentUnit.New(5), - ReagentUnit.New(3), - ReagentUnit.New(1), - ReagentUnit.New(2), - ReagentUnit.New(4), + FixedPoint2.New(5), + FixedPoint2.New(3), + FixedPoint2.New(1), + FixedPoint2.New(2), + FixedPoint2.New(4), }; - var min = ReagentUnit.Min(unorderedList); - Assert.That(min, Is.EqualTo(ReagentUnit.New(1))); + var min = FixedPoint2.Min(unorderedList); + Assert.That(min, Is.EqualTo(FixedPoint2.New(1))); } [Test] @@ -133,10 +134,10 @@ namespace Content.Tests.Shared.Chemistry [TestCase(1, 1, true)] [TestCase(0, 1, false)] [TestCase(-1, 1, false)] - public void ReagentUnitEquals(int a, int b, bool expected) + public void FixedPoint2Equals(int a, int b, bool expected) { - var parameter = ReagentUnit.New(a); - var comparison = ReagentUnit.New(b); + var parameter = FixedPoint2.New(a); + var comparison = FixedPoint2.New(b); Assert.That(parameter.Equals(comparison), Is.EqualTo(comparison.Equals(parameter))); Assert.That(comparison.Equals(parameter), Is.EqualTo(expected)); } diff --git a/Content.Tests/Shared/Chemistry/Solution_Tests.cs b/Content.Tests/Shared/Chemistry/Solution_Tests.cs index 5f2abb2e7d..9e8969d604 100644 --- a/Content.Tests/Shared/Chemistry/Solution_Tests.cs +++ b/Content.Tests/Shared/Chemistry/Solution_Tests.cs @@ -1,5 +1,6 @@ using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using NUnit.Framework; namespace Content.Tests.Shared.Chemistry @@ -11,7 +12,7 @@ namespace Content.Tests.Shared.Chemistry public void AddReagentAndGetSolution() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); + solution.AddReagent("water", FixedPoint2.New(1000)); var quantity = solution.GetReagentQuantity("water"); Assert.That(quantity.Int(), Is.EqualTo(1000)); @@ -20,7 +21,7 @@ namespace Content.Tests.Shared.Chemistry [Test] public void ConstructorAddReagent() { - var solution = new Solution("water", ReagentUnit.New(1000)); + var solution = new Solution("water", FixedPoint2.New(1000)); var quantity = solution.GetReagentQuantity("water"); Assert.That(quantity.Int(), Is.EqualTo(1000)); @@ -38,7 +39,7 @@ namespace Content.Tests.Shared.Chemistry [Test] public void AddLessThanZeroReagentReturnsZero() { - var solution = new Solution("water", ReagentUnit.New(-1000)); + var solution = new Solution("water", FixedPoint2.New(-1000)); var quantity = solution.GetReagentQuantity("water"); Assert.That(quantity.Int(), Is.EqualTo(0)); @@ -48,8 +49,8 @@ namespace Content.Tests.Shared.Chemistry public void AddingReagentsSumsProperly() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); - solution.AddReagent("water", ReagentUnit.New(2000)); + solution.AddReagent("water", FixedPoint2.New(1000)); + solution.AddReagent("water", FixedPoint2.New(2000)); var quantity = solution.GetReagentQuantity("water"); Assert.That(quantity.Int(), Is.EqualTo(3000)); @@ -59,8 +60,8 @@ namespace Content.Tests.Shared.Chemistry public void ReagentQuantitiesStayUnique() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); - solution.AddReagent("fire", ReagentUnit.New(2000)); + solution.AddReagent("water", FixedPoint2.New(1000)); + solution.AddReagent("fire", FixedPoint2.New(2000)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(1000)); Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(2000)); @@ -70,8 +71,8 @@ namespace Content.Tests.Shared.Chemistry public void TotalVolumeIsCorrect() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); - solution.AddReagent("fire", ReagentUnit.New(2000)); + solution.AddReagent("water", FixedPoint2.New(1000)); + solution.AddReagent("fire", FixedPoint2.New(2000)); Assert.That(solution.TotalVolume.Int(), Is.EqualTo(3000)); } @@ -80,8 +81,8 @@ namespace Content.Tests.Shared.Chemistry public void CloningSolutionIsCorrect() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); - solution.AddReagent("fire", ReagentUnit.New(2000)); + solution.AddReagent("water", FixedPoint2.New(1000)); + solution.AddReagent("fire", FixedPoint2.New(2000)); var newSolution = solution.Clone(); @@ -94,10 +95,10 @@ namespace Content.Tests.Shared.Chemistry public void RemoveSolutionRecalculatesProperly() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); - solution.AddReagent("fire", ReagentUnit.New(2000)); + solution.AddReagent("water", FixedPoint2.New(1000)); + solution.AddReagent("fire", FixedPoint2.New(2000)); - solution.RemoveReagent("water", ReagentUnit.New(500)); + solution.RemoveReagent("water", FixedPoint2.New(500)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(500)); Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(2000)); @@ -107,9 +108,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void RemoveLessThanOneQuantityDoesNothing() { - var solution = new Solution("water", ReagentUnit.New(100)); + var solution = new Solution("water", FixedPoint2.New(100)); - solution.RemoveReagent("water", ReagentUnit.New(-100)); + solution.RemoveReagent("water", FixedPoint2.New(-100)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(100)); Assert.That(solution.TotalVolume.Int(), Is.EqualTo(100)); @@ -118,9 +119,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void RemoveMoreThanTotalRemovesAllReagent() { - var solution = new Solution("water", ReagentUnit.New(100)); + var solution = new Solution("water", FixedPoint2.New(100)); - solution.RemoveReagent("water", ReagentUnit.New(1000)); + solution.RemoveReagent("water", FixedPoint2.New(1000)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(0)); Assert.That(solution.TotalVolume.Int(), Is.EqualTo(0)); @@ -129,9 +130,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void RemoveNonExistReagentDoesNothing() { - var solution = new Solution("water", ReagentUnit.New(100)); + var solution = new Solution("water", FixedPoint2.New(100)); - solution.RemoveReagent("fire", ReagentUnit.New(1000)); + solution.RemoveReagent("fire", FixedPoint2.New(1000)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(100)); Assert.That(solution.TotalVolume.Int(), Is.EqualTo(100)); @@ -140,9 +141,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void RemoveSolution() { - var solution = new Solution("water", ReagentUnit.New(700)); + var solution = new Solution("water", FixedPoint2.New(700)); - solution.RemoveSolution(ReagentUnit.New(500)); + solution.RemoveSolution(FixedPoint2.New(500)); //Check that edited solution is correct Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(200)); @@ -152,9 +153,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void RemoveSolutionMoreThanTotalRemovesAll() { - var solution = new Solution("water", ReagentUnit.New(800)); + var solution = new Solution("water", FixedPoint2.New(800)); - solution.RemoveSolution(ReagentUnit.New(1000)); + solution.RemoveSolution(FixedPoint2.New(1000)); //Check that edited solution is correct Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(0)); @@ -165,10 +166,10 @@ namespace Content.Tests.Shared.Chemistry public void RemoveSolutionRatioPreserved() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); - solution.AddReagent("fire", ReagentUnit.New(2000)); + solution.AddReagent("water", FixedPoint2.New(1000)); + solution.AddReagent("fire", FixedPoint2.New(2000)); - solution.RemoveSolution(ReagentUnit.New(1500)); + solution.RemoveSolution(FixedPoint2.New(1500)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(500)); Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(1000)); @@ -178,9 +179,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void RemoveSolutionLessThanOneDoesNothing() { - var solution = new Solution("water", ReagentUnit.New(800)); + var solution = new Solution("water", FixedPoint2.New(800)); - solution.RemoveSolution(ReagentUnit.New(-200)); + solution.RemoveSolution(FixedPoint2.New(-200)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(800)); Assert.That(solution.TotalVolume.Int(), Is.EqualTo(800)); @@ -190,10 +191,10 @@ namespace Content.Tests.Shared.Chemistry public void SplitSolution() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1000)); - solution.AddReagent("fire", ReagentUnit.New(2000)); + solution.AddReagent("water", FixedPoint2.New(1000)); + solution.AddReagent("fire", FixedPoint2.New(2000)); - var splitSolution = solution.SplitSolution(ReagentUnit.New(750)); + var splitSolution = solution.SplitSolution(FixedPoint2.New(750)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(750)); Assert.That(solution.GetReagentQuantity("fire").Int(), Is.EqualTo(1500)); @@ -208,10 +209,10 @@ namespace Content.Tests.Shared.Chemistry public void SplitSolutionFractional() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1)); - solution.AddReagent("fire", ReagentUnit.New(2)); + solution.AddReagent("water", FixedPoint2.New(1)); + solution.AddReagent("fire", FixedPoint2.New(2)); - var splitSolution = solution.SplitSolution(ReagentUnit.New(1)); + var splitSolution = solution.SplitSolution(FixedPoint2.New(1)); Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(0.67f)); Assert.That(solution.GetReagentQuantity("fire").Float(), Is.EqualTo(1.33f)); @@ -226,10 +227,10 @@ namespace Content.Tests.Shared.Chemistry public void SplitSolutionFractionalOpposite() { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(1)); - solution.AddReagent("fire", ReagentUnit.New(2)); + solution.AddReagent("water", FixedPoint2.New(1)); + solution.AddReagent("fire", FixedPoint2.New(2)); - var splitSolution = solution.SplitSolution(ReagentUnit.New(2)); + var splitSolution = solution.SplitSolution(FixedPoint2.New(2)); Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(0.33f)); Assert.That(solution.GetReagentQuantity("fire").Float(), Is.EqualTo(0.67f)); @@ -246,9 +247,9 @@ namespace Content.Tests.Shared.Chemistry public void SplitSolutionTinyFractionalBigSmall(float initial, float reduce, float remainder) { var solution = new Solution(); - solution.AddReagent("water", ReagentUnit.New(initial)); + solution.AddReagent("water", FixedPoint2.New(initial)); - var splitSolution = solution.SplitSolution(ReagentUnit.New(reduce)); + var splitSolution = solution.SplitSolution(FixedPoint2.New(reduce)); Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(remainder)); Assert.That(solution.TotalVolume.Float(), Is.EqualTo(remainder)); @@ -265,11 +266,11 @@ namespace Content.Tests.Shared.Chemistry public void SplitRounding(int amount) { var solutionOne = new Solution(); - solutionOne.AddReagent("foo", ReagentUnit.New(amount)); - solutionOne.AddReagent("bar", ReagentUnit.New(amount)); - solutionOne.AddReagent("baz", ReagentUnit.New(amount)); + solutionOne.AddReagent("foo", FixedPoint2.New(amount)); + solutionOne.AddReagent("bar", FixedPoint2.New(amount)); + solutionOne.AddReagent("baz", FixedPoint2.New(amount)); - var splitAmount = ReagentUnit.New(5); + var splitAmount = FixedPoint2.New(5); var split = solutionOne.SplitSolution(splitAmount); Assert.That(split.TotalVolume, Is.EqualTo(splitAmount)); @@ -278,9 +279,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void SplitSolutionMoreThanTotalRemovesAll() { - var solution = new Solution("water", ReagentUnit.New(800)); + var solution = new Solution("water", FixedPoint2.New(800)); - var splitSolution = solution.SplitSolution(ReagentUnit.New(1000)); + var splitSolution = solution.SplitSolution(FixedPoint2.New(1000)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(0)); Assert.That(solution.TotalVolume.Int(), Is.EqualTo(0)); @@ -292,9 +293,9 @@ namespace Content.Tests.Shared.Chemistry [Test] public void SplitSolutionLessThanOneDoesNothing() { - var solution = new Solution("water", ReagentUnit.New(800)); + var solution = new Solution("water", FixedPoint2.New(800)); - var splitSolution = solution.SplitSolution(ReagentUnit.New(-200)); + var splitSolution = solution.SplitSolution(FixedPoint2.New(-200)); Assert.That(solution.GetReagentQuantity("water").Int(), Is.EqualTo(800)); Assert.That(solution.TotalVolume.Int(), Is.EqualTo(800)); @@ -307,33 +308,33 @@ namespace Content.Tests.Shared.Chemistry public void SplitSolutionZero() { var solution = new Solution(); - solution.AddReagent("Impedrezene", ReagentUnit.New(0.01 + 0.19)); - solution.AddReagent("Thermite", ReagentUnit.New(0.01 + 0.39)); - solution.AddReagent("Li", ReagentUnit.New(0.01 + 0.17)); - solution.AddReagent("F", ReagentUnit.New(0.01 + 0.17)); - solution.AddReagent("Na", ReagentUnit.New(0 + 0.13)); - solution.AddReagent("Hg", ReagentUnit.New(0.15 + 4.15)); - solution.AddReagent("Cu", ReagentUnit.New(0 + 0.13)); - solution.AddReagent("U", ReagentUnit.New(0.76 + 20.77)); - solution.AddReagent("Fe", ReagentUnit.New(0.01 + 0.36)); - solution.AddReagent("SpaceDrugs", ReagentUnit.New(0.02 + 0.41)); - solution.AddReagent("Al", ReagentUnit.New(0)); - solution.AddReagent("Glucose", ReagentUnit.New(0)); - solution.AddReagent("O", ReagentUnit.New(0)); + solution.AddReagent("Impedrezene", FixedPoint2.New(0.01 + 0.19)); + solution.AddReagent("Thermite", FixedPoint2.New(0.01 + 0.39)); + solution.AddReagent("Li", FixedPoint2.New(0.01 + 0.17)); + solution.AddReagent("F", FixedPoint2.New(0.01 + 0.17)); + solution.AddReagent("Na", FixedPoint2.New(0 + 0.13)); + solution.AddReagent("Hg", FixedPoint2.New(0.15 + 4.15)); + solution.AddReagent("Cu", FixedPoint2.New(0 + 0.13)); + solution.AddReagent("U", FixedPoint2.New(0.76 + 20.77)); + solution.AddReagent("Fe", FixedPoint2.New(0.01 + 0.36)); + solution.AddReagent("SpaceDrugs", FixedPoint2.New(0.02 + 0.41)); + solution.AddReagent("Al", FixedPoint2.New(0)); + solution.AddReagent("Glucose", FixedPoint2.New(0)); + solution.AddReagent("O", FixedPoint2.New(0)); - solution.SplitSolution(ReagentUnit.New(0.98)); + solution.SplitSolution(FixedPoint2.New(0.98)); } [Test] public void AddSolution() { var solutionOne = new Solution(); - solutionOne.AddReagent("water", ReagentUnit.New(1000)); - solutionOne.AddReagent("fire", ReagentUnit.New(2000)); + solutionOne.AddReagent("water", FixedPoint2.New(1000)); + solutionOne.AddReagent("fire", FixedPoint2.New(2000)); var solutionTwo = new Solution(); - solutionTwo.AddReagent("water", ReagentUnit.New(500)); - solutionTwo.AddReagent("earth", ReagentUnit.New(1000)); + solutionTwo.AddReagent("water", FixedPoint2.New(500)); + solutionTwo.AddReagent("earth", FixedPoint2.New(1000)); solutionOne.AddSolution(solutionTwo); diff --git a/Content.Tests/Shared/DamageTest.cs b/Content.Tests/Shared/DamageTest.cs index f3a877d398..634c57c1c6 100644 --- a/Content.Tests/Shared/DamageTest.cs +++ b/Content.Tests/Shared/DamageTest.cs @@ -5,6 +5,7 @@ using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager; using System.Collections.Generic; +using Content.Shared.FixedPoint; namespace Content.Tests.Shared { @@ -21,7 +22,7 @@ namespace Content.Tests.Shared // "missing" blunt entry { "Piercing", -2 },// Turn Piercing into Healing { "Slash", 3 }, - { "Radiation", 1.06f }, // Small change, paired with fractional reduction + { "Radiation", 1.5f }, }; static private Dictionary _resistanceReductionDict = new() @@ -59,75 +60,75 @@ namespace Content.Tests.Shared DamageSpecifier damageSpec = new(_damageSpec); // Check that it properly split up the groups into types - int damage; - Assert.That(damageSpec.Total, Is.EqualTo(8)); + FixedPoint2 damage; + Assert.That(damageSpec.Total, Is.EqualTo(FixedPoint2.New(8))); Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage)); - Assert.That(damage, Is.EqualTo(2)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(2))); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); - Assert.That(damage, Is.EqualTo(2)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(2))); Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage)); - Assert.That(damage, Is.EqualTo(1)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(1))); Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage)); - Assert.That(damage, Is.EqualTo(3)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(3))); // check that integer multiplication works damageSpec = damageSpec * 2; - Assert.That(damageSpec.Total, Is.EqualTo(16)); + Assert.That(damageSpec.Total, Is.EqualTo(FixedPoint2.New(16))); Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage)); - Assert.That(damage, Is.EqualTo(4)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(4))); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); - Assert.That(damage, Is.EqualTo(4)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(4))); Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage)); - Assert.That(damage, Is.EqualTo(2)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(2))); Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage)); - Assert.That(damage, Is.EqualTo(6)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(6))); // check that float multiplication works damageSpec = damageSpec * 2.2f; Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage)); - Assert.That(damage, Is.EqualTo(9)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(8.8))); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); - Assert.That(damage, Is.EqualTo(9)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(8.8))); Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage)); - Assert.That(damage, Is.EqualTo(4)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(4.4))); Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage)); - Assert.That(damage, Is.EqualTo(13)); - Assert.That(damageSpec.Total, Is.EqualTo(9 + 9 + 4 + 13)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(13.2))); + Assert.That(damageSpec.Total, Is.EqualTo(FixedPoint2.New(8.8 + 8.8 + 4.4 + 13.2))); // check that integer division works damageSpec = damageSpec / 2; Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage)); - Assert.That(damage, Is.EqualTo(5)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(4.4))); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); - Assert.That(damage, Is.EqualTo(5)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(4.4))); Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage)); - Assert.That(damage, Is.EqualTo(2)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(2.2))); Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage)); - Assert.That(damage, Is.EqualTo(7)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(6.6))); // check that float division works - damageSpec = damageSpec / 2.4f; + damageSpec = damageSpec / 2.2f; Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage)); - Assert.That(damage, Is.EqualTo(2)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(2))); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); - Assert.That(damage, Is.EqualTo(2)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(2))); Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage)); - Assert.That(damage, Is.EqualTo(1)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(1))); Assert.That(damageSpec.DamageDict.TryGetValue("Radiation", out damage)); - Assert.That(damage, Is.EqualTo(3)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(3))); // Lets also test the constructor with damage types and damage groups works properly. damageSpec = new(_prototypeManager.Index("Brute"), 4); Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage)); - Assert.That(damage, Is.EqualTo(1)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.33))); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); - Assert.That(damage, Is.EqualTo(2)); // integer rounding. Piercing is defined as last group member in yaml. + Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.33))); Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage)); - Assert.That(damage, Is.EqualTo(1)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.34))); // doesn't divide evenly, so the 0.01 goes to the last one damageSpec = new(_prototypeManager.Index("Piercing"), 4); Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage)); - Assert.That(damage, Is.EqualTo(4)); + Assert.That(damage, Is.EqualTo(FixedPoint2.New(4))); } //Check that DamageSpecifier will be properly adjusted by a resistance set @@ -146,21 +147,21 @@ namespace Content.Tests.Shared //damage is initially 20 / 20 / 10 / 30 //Each time we subtract -5 / 0 / 8 / 0.5 - //then multiply by 1 / -2 / 3 / 1.06 + //then multiply by 1 / -2 / 3 / 1.5 // Apply once damageSpec = DamageSpecifier.ApplyModifierSet(damageSpec, modifierSet); - Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(25)); - Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(-40)); // became healing - Assert.That(damageSpec.DamageDict["Slash"], Is.EqualTo(6)); - Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(31)); // would be 32 w/o fraction adjustment + Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(FixedPoint2.New(25))); + Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(FixedPoint2.New(-40))); // became healing + Assert.That(damageSpec.DamageDict["Slash"], Is.EqualTo(FixedPoint2.New(6))); + Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(44.25))); // And again, checking for some other behavior damageSpec = DamageSpecifier.ApplyModifierSet(damageSpec, modifierSet); - Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(30)); - Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(-40)); // resistances don't apply to healing + Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(FixedPoint2.New(30))); + Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(FixedPoint2.New(-40))); // resistances don't apply to healing Assert.That(!damageSpec.DamageDict.ContainsKey("Slash")); // Reduction reduced to 0, and removed from specifier - Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(32)); + Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(65.63))); } // Default damage Yaml