Adds temperature to solutions (#5834)

This commit is contained in:
TemporalOroboros
2021-12-24 01:22:34 -08:00
committed by GitHub
parent c94f93732b
commit 201952e618
18 changed files with 858 additions and 21 deletions

View File

@@ -1,5 +1,7 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -48,5 +50,45 @@ namespace Content.Shared.Chemistry.Components
[ViewVariables]
public FixedPoint2 CurrentVolume => TotalVolume;
/// <summary>
/// The total heat capacity of all reagents in the solution.
/// </summary>
[ViewVariables]
public float HeatCapacity => GetHeatCapacity();
/// <summary>
/// The average specific heat of all reagents in the solution.
/// </summary>
[ViewVariables]
public float SpecificHeat => HeatCapacity / (float) TotalVolume;
/// <summary>
/// The total thermal energy of the reagents in the solution.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float ThermalEnergy {
get { return Temperature * HeatCapacity; }
set { Temperature = ((HeatCapacity == 0.0f) ? 0.0f : (value / HeatCapacity)); }
}
/// <summary>
/// Returns the total heat capacity of the reagents in this solution.
/// </summary>
/// <returns>The total heat capacity of the reagents in this solution.</returns>
private float GetHeatCapacity()
{
var heatCapacity = 0.0f;
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach(var reagent in Contents)
{
if (!prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto))
proto = new ReagentPrototype();
heatCapacity += (float) reagent.Quantity * proto.SpecificHeat;
}
return heatCapacity;
}
}
}