Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fires now play a sound effect. #6138

Merged
merged 4 commits into from Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions Content.Server/Atmos/EntitySystems/AirtightSystem.cs
Expand Up @@ -20,7 +20,6 @@ public override void Initialize()
{
SubscribeLocalEvent<AirtightComponent, ComponentInit>(OnAirtightInit);
SubscribeLocalEvent<AirtightComponent, ComponentShutdown>(OnAirtightShutdown);
SubscribeLocalEvent<AirtightComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<AirtightComponent, AnchorStateChangedEvent>(OnAirtightPositionChanged);
SubscribeLocalEvent<AirtightComponent, RotateEvent>(OnAirtightRotated);
}
Expand Down Expand Up @@ -58,10 +57,6 @@ private void OnAirtightShutdown(EntityUid uid, AirtightComponent airtight, Compo
RaiseLocalEvent(new AirtightChanged(airtight));
}

private void OnMapInit(EntityUid uid, AirtightComponent airtight, MapInitEvent args)
{
}

private void OnAirtightPositionChanged(EntityUid uid, AirtightComponent airtight, ref AnchorStateChangedEvent args)
{
var xform = EntityManager.GetComponent<TransformComponent>(uid);
Expand Down
Expand Up @@ -9,7 +9,6 @@ public partial class AtmosphereSystem
[Dependency] private readonly IConfigurationManager _cfg = default!;

public bool SpaceWind { get; private set; }
public string? SpaceWindSound { get; private set; }
public bool MonstermosEqualization { get; private set; }
public bool MonstermosDepressurization { get; private set; }
public bool MonstermosRipTiles { get; private set; }
Expand All @@ -24,7 +23,6 @@ public partial class AtmosphereSystem
private void InitializeCVars()
{
_cfg.OnValueChanged(CCVars.SpaceWind, value => SpaceWind = value, true);
_cfg.OnValueChanged(CCVars.SpaceWindSound, value => SpaceWindSound = value, true);
_cfg.OnValueChanged(CCVars.MonstermosEqualization, value => MonstermosEqualization = value, true);
_cfg.OnValueChanged(CCVars.MonstermosDepressurization, value => MonstermosDepressurization = value, true);
_cfg.OnValueChanged(CCVars.MonstermosRipTiles, value => MonstermosRipTiles = value, true);
Expand Down
37 changes: 36 additions & 1 deletion Content.Server/Atmos/EntitySystems/AtmosphereSystem.Gases.cs
Expand Up @@ -21,6 +21,10 @@ public partial class AtmosphereSystem
/// List of gas reactions ordered by priority.
/// </summary>
public IEnumerable<GasReactionPrototype> GasReactions => _gasReactions!;

/// <summary>
/// Cached array of gas specific heats.
/// </summary>
public float[] GasSpecificHeats => _gasSpecificHeats;

private void InitializeGases()
Expand All @@ -36,11 +40,17 @@ private void InitializeGases()
}
}

/// <summary>
/// Calculates the heat capacity for a gas mixture.
/// </summary>
public float GetHeatCapacity(GasMixture mixture)
{
return GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable);
}

/// <summary>
/// Calculates the heat capacity for a gas mixture, using the archived values.
/// </summary>
public float GetHeatCapacityArchived(GasMixture mixture)
{
return GetHeatCapacityCalculation(mixture.MolesArchived, mixture.Immutable);
Expand All @@ -60,16 +70,26 @@ private float GetHeatCapacityCalculation(float[] moles, bool immutable)
return MathF.Max(NumericsHelpers.HorizontalAdd(tmp), Atmospherics.MinimumHeatCapacity);
}

/// <summary>
/// Calculates the thermal energy for a gas mixture.
/// </summary>
public float GetThermalEnergy(GasMixture mixture)
{
return mixture.Temperature * GetHeatCapacity(mixture);
}

/// <summary>
/// Calculates the thermal energy for a gas mixture, using a cached heat capacity value.
/// </summary>
public float GetThermalEnergy(GasMixture mixture, float cachedHeatCapacity)
{
return mixture.Temperature * cachedHeatCapacity;
}

/// <summary>
/// Merges the <see cref="giver"/> gas mixture into the <see cref="receiver"/> gas mixture.
/// The <see cref="giver"/> gas mixture is not modified by this method.
/// </summary>
public void Merge(GasMixture receiver, GasMixture giver)
{
if (receiver.Immutable) return;
Expand All @@ -88,6 +108,9 @@ public void Merge(GasMixture receiver, GasMixture giver)
NumericsHelpers.Add(receiver.Moles, giver.Moles);
}

/// <summary>
/// Shares gas between two gas mixtures. Part of LINDA.
/// </summary>
public float Share(GasMixture receiver, GasMixture sharer, int atmosAdjacentTurfs)
{
var temperatureDelta = receiver.TemperatureArchived - sharer.TemperatureArchived;
Expand Down Expand Up @@ -169,6 +192,9 @@ public float Share(GasMixture receiver, GasMixture sharer, int atmosAdjacentTurf

}

/// <summary>
/// Shares temperature between two mixtures, taking a conduction coefficient into account.
/// </summary>
public float TemperatureShare(GasMixture receiver, GasMixture sharer, float conductionCoefficient)
{
var temperatureDelta = receiver.TemperatureArchived - sharer.TemperatureArchived;
Expand All @@ -192,6 +218,9 @@ public float TemperatureShare(GasMixture receiver, GasMixture sharer, float cond
return sharer.Temperature;
}

/// <summary>
/// Shares temperature between a gas mixture and an abstract sharer, taking a conduction coefficient into account.
/// </summary>
public float TemperatureShare(GasMixture receiver, float conductionCoefficient, float sharerTemperature, float sharerHeatCapacity)
{
var temperatureDelta = receiver.TemperatureArchived - sharerTemperature;
Expand Down Expand Up @@ -271,6 +300,9 @@ public bool PumpGasTo(GasMixture mixture, GasMixture output, float targetPressur
return true;
}

/// <summary>
/// Scrubs specified gases from a gas mixture into a <see cref="destination"/> gas mixture.
/// </summary>
public void ScrubInto(GasMixture mixture, GasMixture destination, IReadOnlyCollection<Gas> filterGases)
{
var buffer = new GasMixture(mixture.Volume){Temperature = mixture.Temperature};
Expand All @@ -284,6 +316,9 @@ public void ScrubInto(GasMixture mixture, GasMixture destination, IReadOnlyColle
Merge(destination, buffer);
}

/// <summary>
/// Performs reactions for a given gas mixture on an optional holder.
/// </summary>
public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder)
{
var reaction = ReactionResult.NoReaction;
Expand All @@ -300,7 +335,7 @@ public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder)
var doReaction = true;
for (var i = 0; i < prototype.MinimumRequirements.Length; i++)
{
if(i > Atmospherics.TotalNumberOfGases)
if(i >= Atmospherics.TotalNumberOfGases)
throw new IndexOutOfRangeException("Reaction Gas Minimum Requirements Array Prototype exceeds total number of gases!");

var req = prototype.MinimumRequirements[i];
Expand Down
Expand Up @@ -9,25 +9,31 @@
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.ViewVariables;

namespace Content.Server.Atmos.EntitySystems
{
public partial class AtmosphereSystem
{
private const int SpaceWindSoundCooldownCycles = 75;

private int _spaceWindSoundCooldown = 0;

[ViewVariables(VVAccess.ReadWrite)]
public string? SpaceWindSound { get; private set; } = "/Audio/Effects/space_wind.ogg";

private void HighPressureMovements(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
{
// TODO ATMOS finish this

if(tile.PressureDifference > 15)
// Don't play the space wind sound on tiles that are on fire...
if(tile.PressureDifference > 15 && !tile.Hotspot.Valid)
{
if(_spaceWindSoundCooldown == 0)
if(_spaceWindSoundCooldown == 0 && !string.IsNullOrEmpty(SpaceWindSound))
{
var coordinates = tile.GridIndices.ToEntityCoordinates(tile.GridIndex, _mapManager);
if(!string.IsNullOrEmpty(SpaceWindSound))
SoundSystem.Play(Filter.Pvs(coordinates), SpaceWindSound, coordinates,
AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(tile.PressureDifference / 10, 10, 100)));
SoundSystem.Play(Filter.Pvs(coordinates), SpaceWindSound, coordinates,
AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(tile.PressureDifference / 10, 10, 100)));
}
}

Expand All @@ -51,8 +57,7 @@ private void HighPressureMovements(GridAtmosphereComponent gridAtmosphere, TileA
// TODO ATMOS Do space wind graphics here!
}

_spaceWindSoundCooldown++;
if (_spaceWindSoundCooldown > 75)
if (_spaceWindSoundCooldown++ > SpaceWindSoundCooldownCycles)
_spaceWindSoundCooldown = 0;
}

Expand Down
26 changes: 26 additions & 0 deletions Content.Server/Atmos/EntitySystems/AtmosphereSystem.Hotspot.cs
@@ -1,16 +1,29 @@
using Content.Server.Atmos.Components;
using Content.Server.Atmos.Reactions;
using Content.Shared.Atmos;
using Content.Shared.Audio;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.ViewVariables;

namespace Content.Server.Atmos.EntitySystems
{
public partial class AtmosphereSystem
{
[Dependency] private readonly IEntityLookup _lookup = default!;

private const int HotspotSoundCooldownCycles = 200;

private int _hotspotSoundCooldown = 0;

[ViewVariables(VVAccess.ReadWrite)]
public string? HotspotSound { get; private set; } = "/Audio/Effects/fire.ogg";

private void ProcessHotspot(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
{
if (!tile.Hotspot.Valid)
Expand Down Expand Up @@ -70,6 +83,19 @@ private void ProcessHotspot(GridAtmosphereComponent gridAtmosphere, TileAtmosphe
if (tile.Hotspot.Temperature > tile.MaxFireTemperatureSustained)
tile.MaxFireTemperatureSustained = tile.Hotspot.Temperature;

if (_hotspotSoundCooldown++ == 0 && !string.IsNullOrEmpty(HotspotSound))
{
var coordinates = tile.GridIndices.ToEntityCoordinates(tile.GridIndex, _mapManager);
// A few details on the audio parameters for fire.
// The greater the fire state, the lesser the pitch variation.
// The greater the fire state, the greater the volume.
SoundSystem.Play(Filter.Pvs(coordinates), HotspotSound, coordinates,
AudioHelpers.WithVariation(0.15f/tile.Hotspot.State).WithVolume(-5f + 5f * tile.Hotspot.State));
}

if (_hotspotSoundCooldown > HotspotSoundCooldownCycles)
_hotspotSoundCooldown = 0;

// TODO ATMOS Maybe destroy location here?
}

Expand Down
6 changes: 0 additions & 6 deletions Content.Shared/CCVar/CCVars.cs
Expand Up @@ -381,12 +381,6 @@ public sealed class CCVars : CVars
public static readonly CVarDef<bool> SpaceWind =
CVarDef.Create("atmos.space_wind", true, CVar.SERVERONLY);

/// <summary>
/// The sound that plays when space wind occurs.
/// </summary>
public static readonly CVarDef<string> SpaceWindSound =
CVarDef.Create("atmos.space_wind_sound", "/Audio/Effects/space_wind.ogg", CVar.SERVERONLY);

/// <summary>
/// Whether monstermos tile equalization is enabled.
/// </summary>
Expand Down
Binary file added Resources/Audio/Effects/fire.ogg
Binary file not shown.
2 changes: 2 additions & 0 deletions Resources/Audio/Effects/license.txt
Expand Up @@ -14,3 +14,5 @@ voteding.ogg taken from "Bike, Bell Ding, Single, 01-01.wav" by InspectorJ (www.
poster_broken.ogg taken from https://github.com/tgstation/tgstation/blob/2834383245d2129a106acef3afd17b81e1e64777/sound/items/poster_ripped.ogg

poster_being_set.ogg taken from https://github.com/tgstation/tgstation/blob/2834383245d2129a106acef3afd17b81e1e64777/sound/items/poster_ripped.ogg

fire.ogg taken and edited from https://freesound.org/people/raremess/sounds/222557/