]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
ciggie sounds (#32426)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Fri, 18 Apr 2025 22:01:52 +0000 (23:01 +0100)
committerGitHub <noreply@github.com>
Fri, 18 Apr 2025 22:01:52 +0000 (00:01 +0200)
* add sounds

* change _active to BurningComponent

* play sound when lighting and snuffing a cigar

* network it

* mono

* attribution

* doc

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Nutrition/EntitySystems/SmokingSystem.cs
Content.Shared/Nutrition/Components/SmokableComponent.cs
Content.Shared/Smoking/BurningComponent.cs [new file with mode: 0644]
Resources/Audio/Effects/attributions.yml
Resources/Audio/Effects/cig_light.ogg [new file with mode: 0644]
Resources/Audio/Effects/cig_snuff.ogg [new file with mode: 0644]

index d2074a3d82d76d8e8625253a814412c06c33728c..b3ef8bff6919af651261f39aaaaf56211feae6ab 100644 (file)
@@ -15,6 +15,7 @@ using Content.Shared.Nutrition.Components;
 using Content.Shared.Smoking;
 using Content.Shared.Temperature;
 using Robust.Server.GameObjects;
+using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
 using System.Linq;
 using Content.Shared.Atmos;
@@ -30,6 +31,7 @@ namespace Content.Server.Nutrition.EntitySystems
         [Dependency] private readonly TransformSystem _transformSystem = default!;
         [Dependency] private readonly InventorySystem _inventorySystem = default!;
         [Dependency] private readonly ClothingSystem _clothing = default!;
+        [Dependency] private readonly SharedAudioSystem _audio = default!;
         [Dependency] private readonly SharedItemSystem _items = default!;
         [Dependency] private readonly SharedContainerSystem _container = default!;
         [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
@@ -39,11 +41,6 @@ namespace Content.Server.Nutrition.EntitySystems
 
         private float _timer;
 
-        /// <summary>
-        ///     We keep a list of active smokables, because iterating all existing smokables would be dumb.
-        /// </summary>
-        private readonly HashSet<EntityUid> _active = new();
-
         public override void Initialize()
         {
             SubscribeLocalEvent<SmokableComponent, IsHotEvent>(OnSmokableIsHotEvent);
@@ -65,7 +62,7 @@ namespace Content.Server.Nutrition.EntitySystems
         public void SetSmokableState(EntityUid uid, SmokableState state, SmokableComponent? smokable = null,
             AppearanceComponent? appearance = null, ClothingComponent? clothing = null)
         {
-            if (!Resolve(uid, ref smokable, ref appearance, ref clothing))
+            if (!Resolve(uid, ref smokable, ref appearance, ref clothing) || smokable.State == state)
                 return;
 
             smokable.State = state;
@@ -83,17 +80,17 @@ namespace Content.Server.Nutrition.EntitySystems
 
             if (state == SmokableState.Lit)
             {
+                EnsureComp<BurningComponent>(uid);
+                _audio.PlayPvs(smokable.LightSound, uid);
                 var igniteEvent = new IgnitedEvent();
                 RaiseLocalEvent(uid, ref igniteEvent);
-
-                _active.Add(uid);
             }
             else
             {
-                var igniteEvent = new ExtinguishedEvent();
-                RaiseLocalEvent(uid, ref igniteEvent);
-
-                _active.Remove(uid);
+                RemComp<BurningComponent>(uid);
+                _audio.PlayPvs(smokable.SnuffSound, uid);
+                var extinguishEvent = new ExtinguishedEvent();
+                RaiseLocalEvent(uid, ref extinguishEvent);
             }
         }
 
@@ -104,7 +101,7 @@ namespace Content.Server.Nutrition.EntitySystems
 
         private void OnSmokableShutdownEvent(Entity<SmokableComponent> entity, ref ComponentShutdown args)
         {
-            _active.Remove(entity);
+            RemComp<BurningComponent>(entity);
         }
 
         private void OnSmokeableEquipEvent(Entity<SmokableComponent> entity, ref GotEquippedEvent args)
@@ -122,18 +119,12 @@ namespace Content.Server.Nutrition.EntitySystems
             if (_timer < UpdateTimer)
                 return;
 
-            // TODO Use an "active smoke" component instead, EntityQuery over that.
-            foreach (var uid in _active.ToArray())
+            var query = EntityQueryEnumerator<BurningComponent, SmokableComponent>();
+            while (query.MoveNext(out var uid, out _, out var smokable))
             {
-                if (!TryComp(uid, out SmokableComponent? smokable))
-                {
-                    _active.Remove(uid);
-                    continue;
-                }
-
                 if (!_solutionContainerSystem.TryGetSolution(uid, smokable.Solution, out var soln, out var solution))
                 {
-                    _active.Remove(uid);
+                    SetSmokableState(uid, SmokableState.Unlit, smokable);
                     continue;
                 }
 
index e5cbd27242c40f7bdb15190e9fb591563c9b191f..28e84dc19085d1ede51f58d225a0f78b08ecaff6 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Shared.FixedPoint;
 using Content.Shared.Smoking;
+using Robust.Shared.Audio;
 using Robust.Shared.GameStates;
 
 namespace Content.Shared.Nutrition.Components
@@ -32,5 +33,17 @@ namespace Content.Shared.Nutrition.Components
         public string LitPrefix = "lit";
         [DataField("unlitPrefix")]
         public string UnlitPrefix = "unlit";
+
+        /// <summary>
+        /// Sound played when lighting this smokable.
+        /// </summary>
+        [DataField]
+        public SoundSpecifier? LightSound = new SoundPathSpecifier("/Audio/Effects/cig_light.ogg");
+
+        /// <summary>
+        /// Sound played when this smokable is extinguished or runs out.
+        /// </summary>
+        [DataField]
+        public SoundSpecifier? SnuffSound = new SoundPathSpecifier("/Audio/Effects/cig_snuff.ogg");
     }
 }
diff --git a/Content.Shared/Smoking/BurningComponent.cs b/Content.Shared/Smoking/BurningComponent.cs
new file mode 100644 (file)
index 0000000..bbb9765
--- /dev/null
@@ -0,0 +1,12 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Smoking;
+
+/// <summary>
+/// Marker component used to track active burning objects.
+/// </summary>
+/// <remarks>
+/// Right now only smoking uses this, but flammable could use it as well in the future.
+/// </remarks>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class BurningComponent : Component;
index add8884a7d506305fa20e7e580e572ce2791ebfa..9cfaa54122156435b7b68f67d362eed014ab6f5d 100644 (file)
   copyright: 'created by Vrymaa on Freesound and modified by Chaboricks'
   license: "CC0-1.0"
   source: https://freesound.org/people/Vrymaa/sounds/785128/
+
+- files: ["cig_light.ogg", "cig_snuff.ogg"]
+  license: "CC-BY-SA-3.0"
+  copyright: "Created by mattroks101 for Bee Station. cig_snuff converted to mono"
+  source: "https://github.com/BeeStation/BeeStation-Hornet/pull/29"
diff --git a/Resources/Audio/Effects/cig_light.ogg b/Resources/Audio/Effects/cig_light.ogg
new file mode 100644 (file)
index 0000000..48aef9c
Binary files /dev/null and b/Resources/Audio/Effects/cig_light.ogg differ
diff --git a/Resources/Audio/Effects/cig_snuff.ogg b/Resources/Audio/Effects/cig_snuff.ogg
new file mode 100644 (file)
index 0000000..b97cd5c
Binary files /dev/null and b/Resources/Audio/Effects/cig_snuff.ogg differ