From b4064adc9aff557220b64d4ad82104a43ecab423 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 11 Jan 2018 20:53:34 +0200 Subject: [PATCH] Fixed connections not being refreshed when a junction box breaks, made junction box deterioration rate proportional to the ratio between the available power and the load (i.e. more power makes the boxes break faster) & added some more variation between the deterioration rates of boxes to prevent all of them breaking at the same time. --- .../Source/Items/FixRequirement.cs | 2 +- .../Items/Components/Power/PowerTransfer.cs | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Items/FixRequirement.cs b/Barotrauma/BarotraumaClient/Source/Items/FixRequirement.cs index 454b4dbe6..93dd80f4f 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/FixRequirement.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/FixRequirement.cs @@ -60,7 +60,7 @@ namespace Barotrauma reqFrame.UserData = requirement; - var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), TextManager.Get("Fix"), "", reqFrame); + var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), TextManager.Get("FixButton"), "", reqFrame); fixButton.OnClicked = FixButtonPressed; fixButton.UserData = requirement; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerTransfer.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerTransfer.cs index 4e0680e11..c3238b640 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerTransfer.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerTransfer.cs @@ -77,6 +77,7 @@ namespace Barotrauma.Items.Components if (!isBroken) { SetAllConnectionsDirty(); + RefreshConnections(); isBroken = true; } } @@ -110,6 +111,7 @@ namespace Barotrauma.Items.Components CheckPower(deltaTime); updateTimer = 0; + int n = 0; foreach (PowerTransfer pt in connectedPoweredList) { pt.powerLoad += (fullLoad - pt.powerLoad) / inertia; @@ -120,10 +122,17 @@ namespace Barotrauma.Items.Components //damage the item if voltage is too high //(except if running as a client) if (GameMain.Client != null) continue; - if (-pt.currPowerConsumption < Math.Max(pt.powerLoad * Rand.Range(1.9f,2.1f), 200.0f)) continue; - + if (-pt.currPowerConsumption < Math.Max(pt.powerLoad * Rand.Range(1.9f, 2.1f), 200.0f)) continue; + float prevCondition = pt.item.Condition; - pt.item.Condition -= deltaTime * 10.0f; + + //deterioration rate is directly proportional to the ratio between the available power and the load (up to a max of 10x) + float conditionDeteriorationSpeed = MathHelper.Clamp(-pt.currPowerConsumption / Math.Max(pt.powerLoad, 1.0f), 0.0f, 10.0f); + + //make the deterioration speed vary between items to prevent every junction box breaking at the same time + conditionDeteriorationSpeed += ((n + (float)Timing.TotalTime / 60.0f) % 10) * 0.5f; + + pt.item.Condition -= deltaTime * conditionDeteriorationSpeed; if (pt.item.Condition <= 0.0f && prevCondition > 0.0f) { @@ -145,7 +154,7 @@ namespace Barotrauma.Items.Components new FireSource(pt.item.WorldPosition); } } - + n++; } }