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.

This commit is contained in:
Joonas Rikkonen
2018-01-11 20:53:34 +02:00
parent 1eaccef8c7
commit b4064adc9a
2 changed files with 14 additions and 5 deletions
@@ -60,7 +60,7 @@ namespace Barotrauma
reqFrame.UserData = requirement; 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.OnClicked = FixButtonPressed;
fixButton.UserData = requirement; fixButton.UserData = requirement;
@@ -77,6 +77,7 @@ namespace Barotrauma.Items.Components
if (!isBroken) if (!isBroken)
{ {
SetAllConnectionsDirty(); SetAllConnectionsDirty();
RefreshConnections();
isBroken = true; isBroken = true;
} }
} }
@@ -110,6 +111,7 @@ namespace Barotrauma.Items.Components
CheckPower(deltaTime); CheckPower(deltaTime);
updateTimer = 0; updateTimer = 0;
int n = 0;
foreach (PowerTransfer pt in connectedPoweredList) foreach (PowerTransfer pt in connectedPoweredList)
{ {
pt.powerLoad += (fullLoad - pt.powerLoad) / inertia; pt.powerLoad += (fullLoad - pt.powerLoad) / inertia;
@@ -120,10 +122,17 @@ namespace Barotrauma.Items.Components
//damage the item if voltage is too high //damage the item if voltage is too high
//(except if running as a client) //(except if running as a client)
if (GameMain.Client != null) continue; 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; 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) if (pt.item.Condition <= 0.0f && prevCondition > 0.0f)
{ {
@@ -145,7 +154,7 @@ namespace Barotrauma.Items.Components
new FireSource(pt.item.WorldPosition); new FireSource(pt.item.WorldPosition);
} }
} }
n++;
} }
} }