2022-03-09 07:39:03 +01:00
|
|
|
using Content.Server.Atmos.Components;
|
2022-06-16 15:28:16 +10:00
|
|
|
using Content.Server.Shuttles.Systems;
|
2022-03-07 06:09:54 -06:00
|
|
|
using Content.Shared.Maps;
|
|
|
|
|
using Robust.Shared.Map;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
2022-03-07 06:09:54 -06:00
|
|
|
|
|
|
|
|
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 ITileDefinitionManager _tileDefinitionManager = default!;
|
2022-07-04 16:51:34 +02:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
2022-03-07 06:09:54 -06:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2022-03-09 07:39:03 +01:00
|
|
|
SubscribeLocalEvent<TileChangedEvent>(OnTileChanged);
|
2022-03-07 06:09:54 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-09 13:45:21 +11:00
|
|
|
private void OnTileChanged(ref TileChangedEvent ev)
|
2022-03-07 06:09:54 -06:00
|
|
|
{
|
|
|
|
|
// Only if a atmos-holding tile has been added or removed.
|
|
|
|
|
// Also, these calls are surprisingly slow.
|
|
|
|
|
// TODO: Make tiledefmanager cache the IsSpace property, and turn this lookup-through-two-interfaces into
|
|
|
|
|
// TODO: a simple array lookup, as tile IDs are likely contiguous, and there's at most 2^16 possibilities anyway.
|
2022-03-09 07:39:03 +01:00
|
|
|
if (!((ev.OldTile.IsSpace(_tileDefinitionManager) && !ev.NewTile.IsSpace(_tileDefinitionManager)) ||
|
2022-04-24 13:54:25 +10:00
|
|
|
(!ev.OldTile.IsSpace(_tileDefinitionManager) && ev.NewTile.IsSpace(_tileDefinitionManager))) ||
|
2022-07-04 16:51:34 +02:00
|
|
|
_atmosphereSystem.HasAtmosphere(ev.Entity))
|
2022-03-07 06:09:54 -06:00
|
|
|
return;
|
|
|
|
|
|
2022-04-24 13:54:25 +10:00
|
|
|
if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
|
2022-03-07 06:09:54 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// We can't actually count how many tiles there are efficiently, so instead estimate with the mass.
|
2022-04-24 13:54:25 +10:00
|
|
|
if (physics.Mass / ShuttleSystem.TileMassMultiplier >= 7.0f)
|
2022-03-07 06:09:54 -06:00
|
|
|
{
|
2022-04-24 13:54:25 +10:00
|
|
|
AddComp<GridAtmosphereComponent>(ev.Entity);
|
2024-03-10 01:15:13 +01:00
|
|
|
Log.Info($"Giving grid {ev.Entity} GridAtmosphereComponent.");
|
2022-03-07 06:09:54 -06:00
|
|
|
}
|
|
|
|
|
// 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.
|
|
|
|
|
}
|
|
|
|
|
}
|