CatStation/Content.Server/Temperature/Systems/TemperatureSystem.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

99 lines
3.9 KiB
C#

using Content.Server.Atmos.EntitySystems;
using Content.Server.Temperature.Components;
using Content.Shared.Atmos;
using Content.Shared.Inventory;
using Content.Shared.Rejuvenate;
using Content.Shared.Temperature;
using Content.Shared.Projectiles;
using Content.Shared.Temperature.Components;
using Content.Shared.Temperature.HeatContainer;
using Content.Shared.Temperature.Systems;
namespace Content.Server.Temperature.Systems;
public sealed partial class TemperatureSystem : SharedTemperatureSystem
{
[Dependency] private AtmosphereSystem _atmosphere = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TemperatureComponent, AtmosExposedUpdateEvent>(OnAtmosExposedUpdate);
SubscribeLocalEvent<TemperatureComponent, RejuvenateEvent>(OnRejuvenate);
Subs.SubscribeWithRelay<TemperatureProtectionComponent, BeforeHeatExchangeEvent>(OnBeforeHeatExchange, held: false);
SubscribeLocalEvent<InternalTemperatureComponent, MapInitEvent>(OnInit);
SubscribeLocalEvent<ChangeTemperatureOnCollideComponent, ProjectileHitEvent>(ChangeTemperatureOnCollide);
InitializeDamage();
}
protected override void OnMapInit(Entity<TemperatureComponent> entity, ref MapInitEvent args)
{
base.OnMapInit(entity, ref args);
// Make sure entities don't spawn cold!
if (_thermalRegulatorQuery.TryComp(entity, out var comp))
entity.Comp.Temperature = comp.NormalBodyTemperature;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
// conduct heat from the surface to the inside of entities with internal temperatures
var query = EntityQueryEnumerator<InternalTemperatureComponent, TemperatureComponent>();
while (query.MoveNext(out var uid, out var comp, out var temp))
{
// don't do anything if they equalized
var diff = Math.Abs(temp.Temperature - comp.Temperature);
if (diff < 0.1f)
continue;
ConductHeat((uid, temp), ref comp, frameTime, comp.Conductance, true);
}
UpdateDamage();
}
private void OnAtmosExposedUpdate(Entity<TemperatureComponent> entity, ref AtmosExposedUpdateEvent args)
{
var transform = args.Transform;
if (transform.MapUid == null)
return;
// TODO ATMOS: Atmos heat containers!!!
var atmosContainer = new HeatContainer(_atmosphere.GetHeatCapacity(args.GasMixture, false), args.GasMixture.Temperature);
ConductHeat(entity.AsNullable(), ref atmosContainer, args.DeltaTime, args.ConductivityMod);
args.GasMixture.Temperature = atmosContainer.Temperature;
}
private void OnInit(Entity<InternalTemperatureComponent> entity, ref MapInitEvent args)
{
if (!TemperatureQuery.TryComp(entity, out var temp))
return;
// TODO: This shouldn't copy temperature component, but this component is so niche it's not worth the effort of fixing.
entity.Comp.Temperature = temp.Temperature;
entity.Comp.HeatCapacity = temp.HeatCapacity;
}
private void OnRejuvenate(Entity<TemperatureComponent> entity, ref RejuvenateEvent args)
{
SetTemperature(entity.AsNullable(), _thermalRegulatorQuery.CompOrNull(entity)?.NormalBodyTemperature ?? Atmospherics.T20C);
}
private void OnBeforeHeatExchange(Entity<TemperatureProtectionComponent> entity, ref BeforeHeatExchangeEvent args)
{
// TODO: Proper coverage modifiers!!! This should be its own system which relays to inventory and then based on coverage spits out a modifier!
args.HeatTransferModifier *= entity.Comp.Coefficient;
}
private void ChangeTemperatureOnCollide(Entity<ChangeTemperatureOnCollideComponent> ent, ref ProjectileHitEvent args)
{
ChangeHeat(args.Target, ent.Comp.Heat, ent.Comp.IgnoreHeatResistance);// adjust the temperature
}
}