From 441dc2adbc5a4807292da2f7d8eaa4d9bbe608d4 Mon Sep 17 00:00:00 2001
From: Plykiya <58439124+Plykiya@users.noreply.github.com>
Date: Mon, 16 Sep 2024 23:40:24 -0700
Subject: [PATCH] make it an atmos device
---
.../Components/RadiantTemperatureComponent.cs | 5 +-
.../Systems/RadiantTemperatureSystem.cs | 62 ++++++++++++-------
.../Structures/Decoration/bonfire.yml | 3 +-
.../Structures/Decoration/fireplace.yml | 3 +-
4 files changed, 46 insertions(+), 27 deletions(-)
diff --git a/Content.Server/Temperature/Components/RadiantTemperatureComponent.cs b/Content.Server/Temperature/Components/RadiantTemperatureComponent.cs
index 60386f977ddb24..a6e83ae620c137 100644
--- a/Content.Server/Temperature/Components/RadiantTemperatureComponent.cs
+++ b/Content.Server/Temperature/Components/RadiantTemperatureComponent.cs
@@ -16,9 +16,8 @@ public sealed partial class RadiantTemperatureComponent : Component
public float GoalTemperature = Atmospherics.T20C;
///
- /// How much the temperature of the surrounding air will change in Kelvin per tick
- /// Positive means it will only heat, negative means it will only cool
+ /// How much energy (in joules) to add to or remove from the surrounding air per second
///
[DataField]
- public float TemperatureChangePerTick = 1f;
+ public float EnergyChangedPerSecond = 1f;
}
diff --git a/Content.Server/Temperature/Systems/RadiantTemperatureSystem.cs b/Content.Server/Temperature/Systems/RadiantTemperatureSystem.cs
index 61a777da8c0089..bf43237750e1bc 100644
--- a/Content.Server/Temperature/Systems/RadiantTemperatureSystem.cs
+++ b/Content.Server/Temperature/Systems/RadiantTemperatureSystem.cs
@@ -1,4 +1,5 @@
using Content.Server.Atmos.EntitySystems;
+using Content.Server.Atmos.Piping.Components;
using Content.Server.Temperature.Components;
using Robust.Server.GameObjects;
@@ -9,32 +10,49 @@ public sealed class RadiantTemperatureSystem : EntitySystem
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly TransformSystem _xform = default!;
- public override void Update(float frameTime)
+ public override void Initialize()
{
- base.Update(frameTime);
+ base.Initialize();
- var query = EntityQueryEnumerator();
- while (query.MoveNext(out var ent, out var comp, out var xform))
- {
- var grid = xform.GridUid;
- var map = xform.MapUid;
- var indices = _xform.GetGridTilePositionOrDefault((ent, xform));
- var mixture = _atmosphere.GetTileMixture(grid, map, indices, true);
-
- if (mixture is null)
- continue;
+ SubscribeLocalEvent(OnAtmosUpdate);
+ }
- // do not continue heating if air is hotter than goal temperature,
- // and the entity is a radiant HEAT source (positive temp changes)
- if (mixture.Temperature > comp.GoalTemperature && comp.TemperatureChangePerTick > 0)
- continue;
+ private void OnAtmosUpdate(Entity entity, ref AtmosDeviceUpdateEvent args)
+ {
+ var entXform = Transform(entity);
+ var grid = entXform.GridUid;
+ var map = entXform.MapUid;
+ var indices = _xform.GetGridTilePositionOrDefault((entity, entXform));
+ var mixture = _atmosphere.GetTileMixture(grid, map, indices, true);
+
+ if (mixture is null)
+ return;
+
+ // do not continue heating if air is hotter than goal temperature,
+ // and the entity is a radiant HEAT source (positive temp changes)
+ if (mixture.Temperature > entity.Comp.GoalTemperature && entity.Comp.EnergyChangedPerSecond > 0)
+ return;
+
+ // do not continue cooling if air is colder than goal temperature
+ // and the entity is a radiant COOLING source (negative temp changes)
+ if (mixture.Temperature < entity.Comp.GoalTemperature && entity.Comp.EnergyChangedPerSecond < 0)
+ return;
+
+ var dQ = entity.Comp.EnergyChangedPerSecond * args.dt;
+
+ // Clamps the heat transferred to not overshoot
+ // This is just taken straight from GasThermoMachineSystem.cs
+ var Cin = _atmosphere.GetHeatCapacity(mixture, true);
+ var dT = entity.Comp.GoalTemperature - mixture.Temperature;
+ var dQLim = dT * Cin;
+ var scale = 1f;
+ if (Math.Abs(dQ) > Math.Abs(dQLim))
+ {
+ scale = dQLim / dQ;
+ }
- // do not continue cooling if air is colder than goal temperature
- // and the entity is a radiant COOLING source (negative temp changes)
- if (mixture.Temperature < comp.GoalTemperature && comp.TemperatureChangePerTick < 0)
- continue;
+ var dQActual = dQ * scale;
+ _atmosphere.AddHeat(mixture, dQActual);
- mixture.Temperature += comp.TemperatureChangePerTick * frameTime;
- }
}
}
diff --git a/Resources/Prototypes/Entities/Structures/Decoration/bonfire.yml b/Resources/Prototypes/Entities/Structures/Decoration/bonfire.yml
index 33ffa1031407e4..0172d4d131d58a 100644
--- a/Resources/Prototypes/Entities/Structures/Decoration/bonfire.yml
+++ b/Resources/Prototypes/Entities/Structures/Decoration/bonfire.yml
@@ -33,9 +33,10 @@
- type: AlwaysHot
- type: IgnitionSource
ignited: true
+ - type: AtmosDevice
- type: RadiantTemperature
goalTemperature: 305
- temperatureChangePerTick: 30
+ energyChangedPerSecond: 2500
- type: entity
id: LegionnaireBonfire
diff --git a/Resources/Prototypes/Entities/Structures/Decoration/fireplace.yml b/Resources/Prototypes/Entities/Structures/Decoration/fireplace.yml
index 027eb4bde39a8e..e13e6e17a7908f 100644
--- a/Resources/Prototypes/Entities/Structures/Decoration/fireplace.yml
+++ b/Resources/Prototypes/Entities/Structures/Decoration/fireplace.yml
@@ -48,6 +48,7 @@
- type: AlwaysHot
- type: IgnitionSource
ignited: true
+ - type: AtmosDevice
- type: RadiantTemperature
goalTemperature: 305
- temperatureChangePerTick: 30
+ energyChangedPerSecond: 2500