]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Anomaly Vessel visuals + audio (#13927)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sun, 5 Feb 2023 19:52:30 +0000 (14:52 -0500)
committerGitHub <noreply@github.com>
Sun, 5 Feb 2023 19:52:30 +0000 (12:52 -0700)
14 files changed:
Content.Server/Anomaly/AnomalySystem.Vessel.cs
Content.Server/Anomaly/AnomalySystem.cs
Content.Server/Anomaly/Components/AnomalyVesselComponent.cs
Content.Shared/Anomaly/SharedAnomaly.cs
Resources/Audio/Machines/attributions.yml
Resources/Audio/Machines/vessel_warning.ogg [new file with mode: 0644]
Resources/Prototypes/Entities/Structures/Machines/anomaly_equipment.yml
Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-1.png [moved from Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly.png with 100% similarity]
Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-2.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-3.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/meta.json
Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-1.png [moved from Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered.png with 100% similarity]
Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-2.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-3.png [new file with mode: 0644]

index ce71cf4715c067aa777080b54bbda1ae423513cd..4809a613fd7357735ae57ef79dec7a2ff6de4282 100644 (file)
@@ -25,7 +25,9 @@ public sealed partial class AnomalySystem
         SubscribeLocalEvent<AnomalyVesselComponent, InteractUsingEvent>(OnVesselInteractUsing);
         SubscribeLocalEvent<AnomalyVesselComponent, ExaminedEvent>(OnExamined);
         SubscribeLocalEvent<AnomalyVesselComponent, ResearchServerGetPointsPerSecondEvent>(OnVesselGetPointsPerSecond);
+        SubscribeLocalEvent<AnomalyVesselComponent, EntityUnpausedEvent>(OnUnpaused);
         SubscribeLocalEvent<AnomalyShutdownEvent>(OnVesselAnomalyShutdown);
+        SubscribeLocalEvent<AnomalyStabilityChangedEvent>(OnVesselAnomalyStabilityChanged);
     }
 
     private void OnExamined(EntityUid uid, AnomalyVesselComponent component, ExaminedEvent args)
@@ -94,6 +96,11 @@ public sealed partial class AnomalySystem
         args.Points += (int) (GetAnomalyPointValue(anomaly) * component.PointMultiplier);
     }
 
+    private void OnUnpaused(EntityUid uid, AnomalyVesselComponent component, ref EntityUnpausedEvent args)
+    {
+        component.NextBeep += args.PausedTime;
+    }
+
     private void OnVesselAnomalyShutdown(ref AnomalyShutdownEvent args)
     {
         foreach (var component in EntityQuery<AnomalyVesselComponent>())
@@ -112,6 +119,18 @@ public sealed partial class AnomalySystem
         }
     }
 
+    private void OnVesselAnomalyStabilityChanged(ref AnomalyStabilityChangedEvent args)
+    {
+        foreach (var component in EntityQuery<AnomalyVesselComponent>())
+        {
+            var ent = component.Owner;
+            if (args.Anomaly != component.Anomaly)
+                continue;
+
+            UpdateVesselAppearance(ent,  component);
+        }
+    }
+
     /// <summary>
     /// Updates the appearance of an anomaly vessel
     /// based on whether or not it has an anomaly
@@ -125,11 +144,61 @@ public sealed partial class AnomalySystem
 
         var on = component.Anomaly != null;
 
-        Appearance.SetData(uid, AnomalyVesselVisuals.HasAnomaly, on);
+        if (!TryComp<AppearanceComponent>(uid, out var appearanceComponent))
+            return;
+
+        Appearance.SetData(uid, AnomalyVesselVisuals.HasAnomaly, on, appearanceComponent);
         if (TryComp<SharedPointLightComponent>(uid, out var pointLightComponent))
         {
             pointLightComponent.Enabled = on;
         }
+
+        // arbitrary value for the generic visualizer to use.
+        // i didn't feel like making an enum for this.
+        var value = 1;
+        if (TryComp<AnomalyComponent>(component.Anomaly, out var anomalyComp))
+        {
+            if (anomalyComp.Stability <= anomalyComp.DecayThreshold)
+            {
+                value = 2;
+            }
+            else if (anomalyComp.Stability >= anomalyComp.GrowthThreshold)
+            {
+                value = 3;
+            }
+        }
+        Appearance.SetData(uid, AnomalyVesselVisuals.AnomalyState, value, appearanceComponent);
+
         _ambient.SetAmbience(uid, on);
     }
+
+    private void UpdateVessels()
+    {
+        foreach (var vessel in EntityQuery<AnomalyVesselComponent>())
+        {
+            var vesselEnt = vessel.Owner;
+            if (vessel.Anomaly is not { } anomUid)
+                continue;
+
+            if (!TryComp<AnomalyComponent>(anomUid, out var anomaly))
+                continue;
+
+            if (Timing.CurTime < vessel.NextBeep)
+                continue;
+
+            // a lerp between the max and min values for each threshold.
+            // longer beeps that get shorter as the anomaly gets more extreme
+            float timerPercentage;
+            if (anomaly.Stability <= anomaly.DecayThreshold)
+                timerPercentage = (anomaly.DecayThreshold - anomaly.Stability) / anomaly.DecayThreshold;
+            else if (anomaly.Stability >= anomaly.GrowthThreshold)
+                timerPercentage = (anomaly.Stability - anomaly.GrowthThreshold) / (1 - anomaly.GrowthThreshold);
+            else //it's not unstable
+                continue;
+
+            Audio.PlayPvs(vessel.BeepSound, vesselEnt);
+            var beepInterval = (vessel.MaxBeepInterval - vessel.MinBeepInterval) * (1 - timerPercentage) + vessel.MinBeepInterval;
+            vessel.NextBeep = beepInterval + Timing.CurTime;
+        }
+    }
 }
index f85ddbe990d93b8756de6385c0205898ecb9eef7..8dce08c40601570b776cfedd3d456557ff48428f 100644 (file)
@@ -124,4 +124,11 @@ public sealed partial class AnomalySystem : SharedAnomalySystem
             _ => throw new ArgumentOutOfRangeException()
         };
     }
+
+    public override void Update(float frameTime)
+    {
+        base.Update(frameTime);
+
+        UpdateVessels();
+    }
 }
index c833cf636b699f77fa46666673504004038135d1..2d502f0ea31f59b347dbbcce9ff27dc218a38ede 100644 (file)
@@ -1,4 +1,6 @@
 using Content.Shared.Construction.Prototypes;
+using Robust.Shared.Audio;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
 
 namespace Content.Server.Anomaly.Components;
@@ -37,4 +39,28 @@ public sealed class AnomalyVesselComponent : Component
     /// </summary>
     [DataField("partRatingPointModifier")]
     public float PartRatingPointModifier = 1.5f;
+
+    /// <summary>
+    /// The maximum time between each beep
+    /// </summary>
+    [DataField("maxBeepInterval")]
+    public TimeSpan MaxBeepInterval = TimeSpan.FromSeconds(2f);
+
+    /// <summary>
+    /// The minimum time between each beep
+    /// </summary>
+    [DataField("minBeepInterval")]
+    public TimeSpan MinBeepInterval = TimeSpan.FromSeconds(0.75f);
+
+    /// <summary>
+    /// When the next beep sound will play
+    /// </summary>
+    [DataField("nextBeep", customTypeSerializer:typeof(TimeOffsetSerializer))]
+    public TimeSpan NextBeep = TimeSpan.Zero;
+
+    /// <summary>
+    /// The sound that is played repeatedly when the anomaly is destabilizing/decaying
+    /// </summary>
+    [DataField("beepSound")]
+    public SoundSpecifier BeepSound = new SoundPathSpecifier("/Audio/Machines/vessel_warning.ogg");
 }
index fe93cff117ef48506d2ef2a85f55908f74669b5e..9ee1f847a95d5fd7dcb39e2d308c48262299d53d 100644 (file)
@@ -38,7 +38,8 @@ public enum AnomalousParticleType : byte
 [Serializable, NetSerializable]
 public enum AnomalyVesselVisuals : byte
 {
-    HasAnomaly
+    HasAnomaly,
+    AnomalyState
 }
 
 [Serializable, NetSerializable]
index 64bb2793db13e77062cbb56066bb35e7ca5ba21f..4ac0ac9cfbfa5139401a5aba2b08ce7d5b8d5700 100644 (file)
@@ -12,3 +12,8 @@
   license: "CC0-1.0"
   copyright: "receipt printing.wav by 13F_Panska_Tlolkova_Matilda. This version is cleaned up, shortened, and converted to OGG."
   source: "https://freesound.org/people/13F_Panska_Tlolkova_Matilda/sounds/378331"
+
+- files: ["vessel_warning.ogg"]
+  license: "CC-BY-4.0"
+  copyright: "Created by AUDACITIER (freesound), converted to MONO and .ogg and edited by EmoGarbage404 (github)."
+  source: "https://freesound.org/people/AUDACITIER/sounds/629196/"
\ No newline at end of file
diff --git a/Resources/Audio/Machines/vessel_warning.ogg b/Resources/Audio/Machines/vessel_warning.ogg
new file mode 100644 (file)
index 0000000..6343103
Binary files /dev/null and b/Resources/Audio/Machines/vessel_warning.ogg differ
index 581e15e5f8b6ce94829df48cddaf9deb1a2bb3e5..cfce5ca910a2e942ce406a464b53c0dafd72fae1 100644 (file)
@@ -9,10 +9,11 @@
     sprite: Structures/Machines/Anomaly/anomaly_vessel.rsi
     layers:
     - state: base
-    - state: powered
+    - state: powered-1
       shader: unshaded
       map: ["enum.PowerDeviceVisualLayers.Powered"]
-    - state: anomaly
+    - state: anomaly-1
+      visible: false
       shader: unshaded
       map: ["enum.AnomalyVesselVisualLayers.Base"]
     - state: panel
         enum.AnomalyVesselVisualLayers.Base:
           True: { visible: true }
           False: { visible: false }
+      enum.AnomalyVesselVisuals.AnomalyState:
+        enum.PowerDeviceVisualLayers.Powered:
+          1: { state: powered-1 }
+          2: { state: powered-2 }
+          3: { state: powered-3 }
+        enum.AnomalyVesselVisualLayers.Base:
+          1: { state: anomaly-1 }
+          2: { state: anomaly-2 }
+          3: { state: anomaly-3 }
       enum.WiresVisuals.MaintenancePanelState:
         enum.WiresVisualLayers.MaintenancePanel:
           True: { visible: false }
diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-2.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-2.png
new file mode 100644 (file)
index 0000000..2e4aebe
Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-2.png differ
diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-3.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-3.png
new file mode 100644 (file)
index 0000000..da20f91
Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-3.png differ
index 1a9a61933d1f40bc2088c9a8ec13835872ee6ac3..7a503b2cf8e6a60caa6111df139db2c7a9ef6a38 100644 (file)
@@ -1,14 +1,20 @@
 {
   "version": 1,
   "license": "CC0-1.0",
-  "copyright": "Created by EmoGarbage404",
+  "copyright": "Created by EmoGarbage404 (github)",
   "size": {
     "x": 32,
     "y": 32
   },
   "states": [
     {
-      "name": "anomaly"
+      "name": "anomaly-1"
+    },
+    {
+      "name": "anomaly-2"
+    },
+    {
+      "name": "anomaly-3"
     },
     {
       "name": "base"
       "name": "panel"
     },
     {
-      "name": "powered"
+      "name": "powered-1"
+    },
+    {
+      "name": "powered-2"
+    },
+    {
+      "name": "powered-3"
     }
   ]
 }
diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-2.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-2.png
new file mode 100644 (file)
index 0000000..b1f7b7c
Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-2.png differ
diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-3.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-3.png
new file mode 100644 (file)
index 0000000..59af1c9
Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-3.png differ