CatStation/Content.Server/Body/Systems/ThermalRegulatorSystem.cs
Princess Cheeseballs 2e9c4c0103
IHeatContainers for TemperatureComponent (#42785)
* Hope I'm not forgetting anything...

* They call me the sender the way I'm sending it.

* remove commented out YAML

* last of the slop

* fix test fails

* first batch of test fails

* no more test fails

* make cryo pods work again.

* Make cryo work better-er

* I didn't like that a firesuit helmet was so effective on its own so I decided to be a dick about it.

* review.com

* oop

* actually real quick do this

* fix YAML issues

* IHeatContainer my beloved <3

* borger

* not networked :(

* jackets

* burgeewqjfrwjkhaskfjfsahjkfsahjkfsahjkfsajhkfsa

* utter yaml nonsense

* phishing

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-07-26 07:56:44 +00:00

96 lines
3.5 KiB
C#

using Content.Server.Body.Components;
using Content.Server.Temperature.Systems;
using Content.Shared.ActionBlocker;
using Content.Shared.Temperature.Components;
using Robust.Shared.Timing;
namespace Content.Server.Body.Systems;
public sealed partial class ThermalRegulatorSystem : EntitySystem
{
[Dependency] private IGameTiming _gameTiming = default!;
[Dependency] private TemperatureSystem _tempSys = default!;
[Dependency] private ActionBlockerSystem _actionBlockerSys = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ThermalRegulatorComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ThermalRegulatorComponent, EntityUnpausedEvent>(OnUnpaused);
}
private void OnMapInit(Entity<ThermalRegulatorComponent> ent, ref MapInitEvent args)
{
ent.Comp.NextUpdate = _gameTiming.CurTime + ent.Comp.UpdateInterval;
}
private void OnUnpaused(Entity<ThermalRegulatorComponent> ent, ref EntityUnpausedEvent args)
{
ent.Comp.NextUpdate += args.PausedTime;
}
public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<ThermalRegulatorComponent>();
while (query.MoveNext(out var uid, out var regulator))
{
if (_gameTiming.CurTime < regulator.NextUpdate)
continue;
regulator.NextUpdate += regulator.UpdateInterval;
ProcessThermalRegulation((uid, regulator));
}
}
/// <summary>
/// Processes thermal regulation for a mob
/// </summary>
private void ProcessThermalRegulation(Entity<ThermalRegulatorComponent, TemperatureComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp2, logMissing: false))
return;
// TODO: Why do we have two datafields for this if they are only ever used once here?
var totalMetabolismTempChange = ent.Comp1.MetabolismHeat - ent.Comp1.RadiatedHeat;
// implicit heat regulation
var tempDiff = Math.Abs(ent.Comp2.Temperature - ent.Comp1.NormalBodyTemperature);
var heatCapacity = ent.Comp2.HeatCapacity;
var targetHeat = tempDiff * heatCapacity;
if (ent.Comp2.Temperature > ent.Comp1.NormalBodyTemperature)
{
totalMetabolismTempChange -= Math.Min(targetHeat, ent.Comp1.ImplicitHeatRegulation);
}
else
{
totalMetabolismTempChange += Math.Min(targetHeat, ent.Comp1.ImplicitHeatRegulation);
}
_tempSys.ChangeHeat((ent, ent.Comp2), totalMetabolismTempChange, ignoreHeatResistance: true);
// recalc difference and target heat
tempDiff = Math.Abs(ent.Comp2.Temperature - ent.Comp1.NormalBodyTemperature);
targetHeat = tempDiff * heatCapacity;
// if body temperature is not within comfortable, thermal regulation
// processes starts
if (tempDiff < ent.Comp1.ThermalRegulationTemperatureThreshold)
return;
if (ent.Comp2.Temperature > ent.Comp1.NormalBodyTemperature)
{
if (!_actionBlockerSys.CanSweat(ent))
return;
_tempSys.ChangeHeat((ent, ent.Comp2), -Math.Min(targetHeat, ent.Comp1.SweatHeatRegulation), ignoreHeatResistance: true);
}
else
{
if (!_actionBlockerSys.CanShiver(ent))
return;
_tempSys.ChangeHeat((ent, ent.Comp2), Math.Min(targetHeat, ent.Comp1.ShiveringHeatRegulation), ignoreHeatResistance: true);
}
}
}