Skip to content

Commit

Permalink
make it an atmos device
Browse files Browse the repository at this point in the history
  • Loading branch information
Plykiya committed Sep 17, 2024
1 parent fa6031f commit 441dc2a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ public sealed partial class RadiantTemperatureComponent : Component
public float GoalTemperature = Atmospherics.T20C;

/// <summary>
/// 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
/// </summary>
[DataField]
public float TemperatureChangePerTick = 1f;
public float EnergyChangedPerSecond = 1f;
}
62 changes: 40 additions & 22 deletions Content.Server/Temperature/Systems/RadiantTemperatureSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Temperature.Components;
using Robust.Server.GameObjects;

Expand All @@ -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<RadiantTemperatureComponent, TransformComponent>();
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<RadiantTemperatureComponent, AtmosDeviceUpdateEvent>(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<RadiantTemperatureComponent> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
- type: AlwaysHot
- type: IgnitionSource
ignited: true
- type: AtmosDevice
- type: RadiantTemperature
goalTemperature: 305
temperatureChangePerTick: 30
energyChangedPerSecond: 2500

- type: entity
id: LegionnaireBonfire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- type: AlwaysHot
- type: IgnitionSource
ignited: true
- type: AtmosDevice
- type: RadiantTemperature
goalTemperature: 305
temperatureChangePerTick: 30
energyChangedPerSecond: 2500

0 comments on commit 441dc2a

Please sign in to comment.