2024-06-14 19:10:16 +03:00
|
|
|
using Content.Server.Atmos.Components;
|
2024-07-23 10:29:41 +03:00
|
|
|
using Content.Server.Temperature.Components;
|
|
|
|
|
using Content.Server.Temperature.Systems;
|
2024-06-14 19:10:16 +03:00
|
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
2024-07-23 10:29:41 +03:00
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2024-06-14 19:10:16 +03:00
|
|
|
using Content.Shared.FixedPoint;
|
|
|
|
|
using Content.Shared.Placeable;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.Temperature;
|
|
|
|
|
|
2024-07-23 10:29:41 +03:00
|
|
|
public sealed partial class CP14TemperatureSystem : EntitySystem
|
2024-06-14 19:10:16 +03:00
|
|
|
{
|
2024-07-23 10:29:41 +03:00
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
|
2024-06-14 19:10:16 +03:00
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
2024-07-23 10:29:41 +03:00
|
|
|
[Dependency] private readonly TemperatureSystem _temperature = default!;
|
2024-06-14 19:10:16 +03:00
|
|
|
|
2024-07-23 10:29:41 +03:00
|
|
|
private readonly TimeSpan _updateTick = TimeSpan.FromSeconds(1f);
|
2024-06-14 19:10:16 +03:00
|
|
|
private TimeSpan _timeToNextUpdate = TimeSpan.Zero;
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
2024-07-23 10:29:41 +03:00
|
|
|
FlammableEntityHeating(frameTime);
|
|
|
|
|
|
2024-06-14 19:10:16 +03:00
|
|
|
if (_timing.CurTime <= _timeToNextUpdate)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_timeToNextUpdate = _timing.CurTime + _updateTick;
|
|
|
|
|
|
2024-07-23 10:29:41 +03:00
|
|
|
FlammableSolutionHeating();
|
|
|
|
|
NormalizeSolutionTemperature();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float GetTargetTemperature(FlammableComponent flammable, CP14FlammableSolutionHeaterComponent heater)
|
|
|
|
|
{
|
|
|
|
|
return flammable.FireStacks * heater.DegreesPerStack;
|
2024-06-14 19:10:16 +03:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 10:29:41 +03:00
|
|
|
private void FlammableEntityHeating(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
var flammableQuery = EntityQueryEnumerator<CP14FlammableEntityHeaterComponent, ItemPlacerComponent, FlammableComponent>();
|
|
|
|
|
while (flammableQuery.MoveNext(out var uid, out var heater, out var placer, out var flammable))
|
|
|
|
|
{
|
|
|
|
|
if (!flammable.OnFire)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var energy = flammable.FireStacks * frameTime * heater.DegreesPerStack;
|
|
|
|
|
foreach (var ent in placer.PlacedEntities)
|
|
|
|
|
{
|
|
|
|
|
_temperature.ChangeHeat(ent, energy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NormalizeSolutionTemperature()
|
2024-06-14 19:10:16 +03:00
|
|
|
{
|
|
|
|
|
var query = EntityQueryEnumerator<CP14SolutionTemperatureComponent, SolutionContainerManagerComponent>();
|
|
|
|
|
while (query.MoveNext(out var uid, out var temp, out var container))
|
|
|
|
|
{
|
|
|
|
|
foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((uid, container)))
|
|
|
|
|
{
|
|
|
|
|
if (TryAffectTemp(soln.Comp.Solution.Temperature, temp.StandardTemp, soln.Comp.Solution.Volume, out var newT, power: 0.05f))
|
|
|
|
|
_solutionContainer.SetTemperature(soln, newT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-23 10:29:41 +03:00
|
|
|
|
|
|
|
|
private void FlammableSolutionHeating()
|
2024-06-14 19:10:16 +03:00
|
|
|
{
|
|
|
|
|
var query =
|
|
|
|
|
EntityQueryEnumerator<CP14FlammableSolutionHeaterComponent, ItemPlacerComponent, FlammableComponent>();
|
|
|
|
|
while (query.MoveNext(out _, out var heater, out var itemPlacer, out var flammable))
|
|
|
|
|
{
|
|
|
|
|
foreach (var heatingEntity in itemPlacer.PlacedEntities)
|
|
|
|
|
{
|
|
|
|
|
if (!flammable.OnFire)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<SolutionContainerManagerComponent>(heatingEntity, out var container))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((heatingEntity, container)))
|
|
|
|
|
{
|
2024-07-23 10:29:41 +03:00
|
|
|
if (TryAffectTemp(soln.Comp.Solution.Temperature, GetTargetTemperature(flammable, heater), soln.Comp.Solution.Volume, out var newT))
|
2024-06-14 19:10:16 +03:00
|
|
|
_solutionContainer.SetTemperature(soln, newT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool TryAffectTemp(float oldT, float targetT, FixedPoint2 mass, out float newT, float power = 1)
|
|
|
|
|
{
|
|
|
|
|
newT = oldT;
|
|
|
|
|
|
|
|
|
|
if (mass == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-07-23 10:29:41 +03:00
|
|
|
newT = (float) (oldT + (targetT - oldT) / mass * power);
|
2024-06-14 19:10:16 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|