Optimize vent/scrubber (#7473)
This commit is contained in:
@@ -33,6 +33,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceUpdateEvent>(OnVentScrubberUpdated);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceEnabledEvent>(OnVentScrubberEnterAtmosphere);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceDisabledEvent>(OnVentScrubberLeaveAtmosphere);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
@@ -41,12 +42,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|
||||
private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, AtmosDeviceUpdateEvent args)
|
||||
{
|
||||
var appearance = EntityManager.GetComponentOrNull<AppearanceComponent>(scrubber.Owner);
|
||||
|
||||
if (scrubber.Welded)
|
||||
{
|
||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Welded);
|
||||
_ambientSoundSystem.SetAmbience(scrubber.Owner, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,40 +56,35 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|
||||
|| !nodeContainer.TryGetNode(scrubber.OutletName, out PipeNode? outlet))
|
||||
{
|
||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
||||
_ambientSoundSystem.SetAmbience(scrubber.Owner, false);
|
||||
return;
|
||||
}
|
||||
_ambientSoundSystem.SetAmbience(scrubber.Owner, true);
|
||||
|
||||
var environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent<TransformComponent>(scrubber.Owner).Coordinates, true);
|
||||
var xform = Transform(uid);
|
||||
var environment = _atmosphereSystem.GetTileMixture(xform.Coordinates, true);
|
||||
|
||||
Scrub(timeDelta, scrubber, appearance, environment, outlet);
|
||||
Scrub(timeDelta, scrubber, environment, outlet);
|
||||
|
||||
if (!scrubber.WideNet) return;
|
||||
|
||||
// Scrub adjacent tiles too.
|
||||
foreach (var adjacent in _atmosphereSystem.GetAdjacentTileMixtures(EntityManager.GetComponent<TransformComponent>(scrubber.Owner).Coordinates, false, true))
|
||||
foreach (var adjacent in _atmosphereSystem.GetAdjacentTileMixtures(xform.Coordinates, false, true))
|
||||
{
|
||||
Scrub(timeDelta, scrubber, null, adjacent, outlet);
|
||||
Scrub(timeDelta, scrubber, adjacent, outlet);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnVentScrubberLeaveAtmosphere(EntityUid uid, GasVentScrubberComponent component, AtmosDeviceDisabledEvent args)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
||||
}
|
||||
}
|
||||
private void OnVentScrubberLeaveAtmosphere(EntityUid uid, GasVentScrubberComponent component,
|
||||
AtmosDeviceDisabledEvent args) => UpdateState(uid, component);
|
||||
|
||||
private void Scrub(float timeDelta, GasVentScrubberComponent scrubber, AppearanceComponent? appearance, GasMixture? tile, PipeNode outlet)
|
||||
private void OnVentScrubberEnterAtmosphere(EntityUid uid, GasVentScrubberComponent component,
|
||||
AtmosDeviceEnabledEvent args) => UpdateState(uid, component);
|
||||
|
||||
private void Scrub(float timeDelta, GasVentScrubberComponent scrubber, GasMixture? tile, PipeNode outlet)
|
||||
{
|
||||
// Cannot scrub if tile is null or air-blocked.
|
||||
if (tile == null
|
||||
|| outlet.Air.Pressure >= 50 * Atmospherics.OneAtmosphere) // Cannot scrub if pressure too high.
|
||||
{
|
||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,8 +98,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|
||||
if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
|
||||
{
|
||||
appearance?.SetData(ScrubberVisuals.State, scrubber.WideNet ? ScrubberState.WideScrub : ScrubberState.Scrub);
|
||||
|
||||
_atmosphereSystem.ScrubInto(removed, outlet.Air, scrubber.FilterGases);
|
||||
|
||||
// Remix the gases.
|
||||
@@ -115,8 +105,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
}
|
||||
else if (scrubber.PumpDirection == ScrubberPumpDirection.Siphoning)
|
||||
{
|
||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Siphon);
|
||||
|
||||
_atmosphereSystem.Merge(outlet.Air, removed);
|
||||
}
|
||||
}
|
||||
@@ -131,10 +119,15 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
{
|
||||
component.Enabled = true;
|
||||
}
|
||||
|
||||
UpdateState(uid, component);
|
||||
}
|
||||
|
||||
private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, PowerChangedEvent args) =>
|
||||
private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, PowerChangedEvent args)
|
||||
{
|
||||
component.Enabled = args.Powered;
|
||||
UpdateState(uid, component);
|
||||
}
|
||||
|
||||
private void OnPacketRecv(EntityUid uid, GasVentScrubberComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
@@ -159,6 +152,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
break;
|
||||
|
||||
component.FromAirAlarmData(setData);
|
||||
UpdateState(uid, component);
|
||||
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
|
||||
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
|
||||
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
|
||||
@@ -168,5 +162,35 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a scrubber's appearance and ambience state.
|
||||
/// </summary>
|
||||
private void UpdateState(EntityUid uid, GasVentScrubberComponent scrubber,
|
||||
AppearanceComponent? appearance = null)
|
||||
{
|
||||
if (!Resolve(uid, ref appearance, false))
|
||||
return;
|
||||
|
||||
_ambientSoundSystem.SetAmbience(uid, true);
|
||||
if (!scrubber.Enabled)
|
||||
{
|
||||
_ambientSoundSystem.SetAmbience(uid, false);
|
||||
appearance.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
||||
}
|
||||
else if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
|
||||
{
|
||||
appearance.SetData(ScrubberVisuals.State, scrubber.WideNet ? ScrubberState.WideScrub : ScrubberState.Scrub);
|
||||
}
|
||||
else if (scrubber.PumpDirection == ScrubberPumpDirection.Siphoning)
|
||||
{
|
||||
appearance.SetData(ScrubberVisuals.State, ScrubberState.Siphon);
|
||||
}
|
||||
else if (scrubber.Welded)
|
||||
{
|
||||
_ambientSoundSystem.SetAmbience(uid, false);
|
||||
appearance.SetData(ScrubberVisuals.State, ScrubberState.Welded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user