Files
tbd-station-14/Content.Server/Atmos/EntitySystems/AutomaticAtmosSystem.cs
Krunklehorn abec27737e AutomaticAtmosSystem uses MassDataChangedEvent, clarifies TileMassMultiplier (#37548)
* Initial commit, no tile changes, just mass

* Rename TileMassMultiplier to TileDensityMultiplier
2025-05-17 21:57:50 -04:00

40 lines
1.4 KiB
C#

using Content.Server.Atmos.Components;
using Content.Server.Shuttles.Systems;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Events;
namespace Content.Server.Atmos.EntitySystems;
/// <summary>
/// Handles automatically adding a grid atmosphere to grids that become large enough, allowing players to build shuttles
/// with a sealed atmosphere from scratch.
/// </summary>
public sealed class AutomaticAtmosSystem : EntitySystem
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MapGridComponent, MassDataChangedEvent>(OnMassDataChanged);
}
private void OnMassDataChanged(Entity<MapGridComponent> ent, ref MassDataChangedEvent ev)
{
if (_atmosphereSystem.HasAtmosphere(ent))
return;
// We can't actually count how many tiles there are efficiently, so instead estimate with the mass.
if (ev.NewMass / ShuttleSystem.TileDensityMultiplier >= 7.0f)
{
AddComp<GridAtmosphereComponent>(ent);
Log.Info($"Giving grid {ent} GridAtmosphereComponent.");
}
// It's not super important to remove it should the grid become too small again.
// If explosions ever gain the ability to outright shatter grids, do rethink this.
return;
}
}