]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Swaps HV/MV/LV scaling to supply power scaling (#20880)
authorTemporalOroboros <TemporalOroboros@gmail.com>
Wed, 18 Oct 2023 21:04:47 +0000 (14:04 -0700)
committerGitHub <noreply@github.com>
Wed, 18 Oct 2023 21:04:47 +0000 (14:04 -0700)
Content.Server/Electrocution/Components/ElectrifiedComponent.cs
Content.Server/Electrocution/Components/ElectrocutionComponent.cs
Content.Server/Electrocution/ElectrocutionSystem.cs
Content.Server/Power/Pow3r/BatteryRampPegSolver.cs
Content.Server/Power/Pow3r/PowerState.cs

index d551aa15410ca23d4cc852ac1584feda9f3ba11f..2f3def6e061faae3df223b450853edd34e241e5e 100644 (file)
@@ -41,18 +41,6 @@ public sealed partial class ElectrifiedComponent : Component
     [DataField("lowVoltageNode")]
     public string? LowVoltageNode;
 
-    [DataField("highVoltageDamageMultiplier")]
-    public float HighVoltageDamageMultiplier = 3f;
-
-    [DataField("highVoltageTimeMultiplier")]
-    public float HighVoltageTimeMultiplier = 1.5f;
-
-    [DataField("mediumVoltageDamageMultiplier")]
-    public float MediumVoltageDamageMultiplier = 2f;
-
-    [DataField("mediumVoltageTimeMultiplier")]
-    public float MediumVoltageTimeMultiplier = 1.25f;
-
     [DataField("shockDamage")]
     public int ShockDamage = 20;
 
index 2534544f6ce81eb168e4933cec32c51d3a7f2767..9da78c9134f6ef3ec39200405c533b36219ff388 100644 (file)
@@ -7,15 +7,18 @@
 [Access(typeof(ElectrocutionSystem))]
 public sealed partial class ElectrocutionComponent : Component
 {
-    [DataField("timeLeft")]
-    public float TimeLeft;
-
     [DataField("electrocuting")]
     public EntityUid Electrocuting;
 
+    [DataField("source")]
+    public EntityUid Source;
+
+    [DataField("timeLeft")]
+    public float TimeLeft;
+
     [DataField("accumDamage")]
     public float AccumulatedDamage;
 
-    [DataField("source")]
-    public EntityUid Source;
+    [DataField("baseDamage")]
+    public float BaseDamage = 20f;
 }
index 48415c3953318b2f3486551bd18baca1d9ce377a..6c962667404a4fc87d6d57eccbaa75cfe48cca5f 100644 (file)
@@ -17,6 +17,7 @@ using Content.Shared.Interaction;
 using Content.Shared.Inventory;
 using Content.Shared.Jittering;
 using Content.Shared.Maps;
+using Content.Shared.Mobs;
 using Content.Shared.Popups;
 using Content.Shared.Pulling.Components;
 using Content.Shared.Speech.EntitySystems;
@@ -61,7 +62,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
     private const string DamageType = "Shock";
 
     // Yes, this is absurdly small for a reason.
-    private const float ElectrifiedDamagePerWatt = 0.0015f;
+    private const float ElectrifiedScalePerWatt = 1E-6f;
 
     private const float RecursiveDamageMultiplier = 0.75f;
     private const float RecursiveTimeMultiplier = 0.8f;
@@ -102,7 +103,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
             var timePassed = Math.Min(frameTime, electrocution.TimeLeft);
 
             electrocution.TimeLeft -= timePassed;
-            electrocution.AccumulatedDamage += consumer.ReceivedPower * ElectrifiedDamagePerWatt * timePassed;
+            electrocution.AccumulatedDamage += electrocution.BaseDamage * (consumer.ReceivedPower / consumer.DrawRate) * timePassed;
 
             if (!MathHelper.CloseTo(electrocution.TimeLeft, 0))
                 continue;
@@ -117,7 +118,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
                 if (actual != null)
                 {
                     _adminLogger.Add(LogType.Electrocution,
-                        $"{ToPrettyString(electrocution.Electrocuting):entity} received {actual.Total:damage} powered electrocution damage from {ToPrettyString(electrocution.Source):source}");
+                        $"{ToPrettyString(electrocution.Electrocuting):entity} received {actual.GetTotal():damage} powered electrocution damage from {ToPrettyString(electrocution.Source):source}");
                 }
             }
             QueueDel(uid);
@@ -257,15 +258,17 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
         }
 
         var node = PoweredNode(uid, electrified, nodeContainer);
-        if (node == null)
+        if (node?.NodeGroup is not IBasePowerNet powerNet)
             return false;
 
-        var (damageMult, timeMult) = node.NodeGroupID switch
-        {
-            NodeGroupID.HVPower => (electrified.HighVoltageDamageMultiplier, electrified.HighVoltageTimeMultiplier),
-            NodeGroupID.MVPower => (electrified.MediumVoltageDamageMultiplier, electrified.MediumVoltageTimeMultiplier),
-            _ => (1f, 1f)
-        };
+        var net = powerNet.NetworkNode;
+        var supp = net.LastCombinedSupply;
+
+        if (supp <= 0f)
+            return false;
+
+        // Initial damage scales off of the available supply on the principle that the victim has shorted the entire powernet through their body.
+        var damageScale = supp * ElectrifiedScalePerWatt;
 
         {
             var lastRet = true;
@@ -276,8 +279,8 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
                     entity,
                     uid,
                     node,
-                    (int) (electrified.ShockDamage * MathF.Pow(RecursiveDamageMultiplier, depth) * damageMult),
-                    TimeSpan.FromSeconds(electrified.ShockTime * MathF.Pow(RecursiveTimeMultiplier, depth) * timeMult),
+                    (int) (electrified.ShockDamage * damageScale * MathF.Pow(RecursiveDamageMultiplier, depth)),
+                    TimeSpan.FromSeconds(electrified.ShockTime * MathF.Min(1f + MathF.Log2(1f + damageScale), 3f) * MathF.Pow(RecursiveTimeMultiplier, depth)),
                     true,
                     electrified.SiemensCoefficient);
             }
@@ -304,18 +307,18 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
         }
     }
 
-        /// <inheritdoc/>
-        public override bool TryDoElectrocution(
-            EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
-            StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
-        {
-            if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient, ignoreInsulation)
-                || !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
-                return false;
+    /// <inheritdoc/>
+    public override bool TryDoElectrocution(
+        EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
+        StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
+    {
+        if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient, ignoreInsulation)
+            || !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
+            return false;
 
-            RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient), true);
-            return true;
-        }
+        RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient), true);
+        return true;
+    }
 
     private bool TryDoElectrocutionPowered(
         EntityUid uid,
@@ -331,12 +334,12 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
         if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient))
             return false;
 
+        if (!DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
+            return false;
+
         // Coefficient needs to be higher than this to do a powered electrocution!
         if (siemensCoefficient <= 0.5f)
-            return DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects);
-
-        if (!DoCommonElectrocution(uid, sourceUid, null, time, refresh, siemensCoefficient, statusEffects))
-            return false;
+            return true;
 
         if (!Resolve(sourceUid, ref sourceTransform)) // This shouldn't really happen, but just in case...
             return true;
@@ -422,7 +425,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
             if (actual != null)
             {
                 _adminLogger.Add(LogType.Electrocution,
-                    $"{ToPrettyString(uid):entity} received {actual.Total:damage} powered electrocution damage{(sourceUid != null ? " from " + ToPrettyString(sourceUid.Value) : ""):source}");
+                    $"{ToPrettyString(uid):entity} received {actual.GetTotal():damage} powered electrocution damage{(sourceUid != null ? " from " + ToPrettyString(sourceUid.Value) : ""):source}");
             }
         }
 
index e2399d8f7797114848018a2bf8b9e987b48e6b40..d0c0a297b472055adcd4537fee8640e2c58b669a 100644 (file)
@@ -170,6 +170,7 @@ namespace Content.Server.Power.Pow3r
                 }
             }
 
+            network.LastCombinedLoad = demand;
             network.LastCombinedSupply = totalSupply + totalBatterySupply;
             network.LastCombinedMaxSupply = totalMaxSupply + totalMaxBatterySupply;
 
index 2b94af97b22c429d3c82dbe53a7fd37128e4b756..78ba97bb22acdc495ed99b3ccee223c533f0a462 100644 (file)
@@ -488,6 +488,11 @@ namespace Content.Server.Power.Pow3r
             /// </summary>
             [ViewVariables] public List<NodeId> BatterySupplies = new();
 
+            /// <summary>
+            ///     The total load on the power network as of last tick.
+            /// </summary>
+            [ViewVariables] public float LastCombinedLoad = 0f;
+
             /// <summary>
             ///     Available supply, including both normal supplies and batteries.
             /// </summary>