Relay fix attempt number n + 2

This commit is contained in:
Joonas Rikkonen
2018-03-02 21:27:08 +02:00
parent c624ff2c8c
commit e15fad6986
2 changed files with 15 additions and 7 deletions
@@ -186,7 +186,7 @@ namespace Barotrauma.Items.Components
if (connection.Name == "power_in") if (connection.Name == "power_in")
{ {
rechargeVoltage = power; rechargeVoltage = Math.Min(power, 1.0f);
} }
else else
{ {
@@ -109,7 +109,7 @@ namespace Barotrauma.Items.Components
SetAllConnectionsDirty(); SetAllConnectionsDirty();
isBroken = false; isBroken = false;
} }
if (updateCount > 0) if (updateCount > 0)
{ {
//this junction box has already been updated this frame //this junction box has already been updated this frame
@@ -124,20 +124,24 @@ namespace Barotrauma.Items.Components
connectedList.Clear(); connectedList.Clear();
CheckJunctions(deltaTime);
updateCount = 0; updateCount = 0;
CheckJunctions(deltaTime);
foreach (Powered p in connectedList) foreach (Powered p in connectedList)
{ {
PowerTransfer pt = p as PowerTransfer; PowerTransfer pt = p as PowerTransfer;
if (pt == null) continue; if (pt == null || pt.updateCount == 0) continue;
if (pt is RelayComponent != this is RelayComponent) continue; if (pt is RelayComponent != this is RelayComponent) continue;
pt.powerLoad += (fullLoad - pt.powerLoad) / inertia; pt.powerLoad += (fullLoad - pt.powerLoad) / inertia;
pt.currPowerConsumption += (-fullPower - pt.currPowerConsumption) / inertia; pt.currPowerConsumption += (-fullPower - pt.currPowerConsumption) / inertia;
pt.Item.SendSignal(0, "", "power", null, fullPower / Math.Max(fullLoad, 1.0f));
pt.Item.SendSignal(0, "", "power_out", null, fullPower / Math.Max(fullLoad, 1.0f)); float voltage = fullPower / Math.Max(fullLoad, 1.0f);
if (this is RelayComponent) voltage = Math.Min(voltage, 1.0f);
pt.Item.SendSignal(0, "", "power", null, voltage);
pt.Item.SendSignal(0, "", "power_out", null, voltage);
//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)
@@ -172,6 +176,8 @@ namespace Barotrauma.Items.Components
} }
} }
} }
updateCount = 0;
} }
public override bool Pick(Character picker) public override bool Pick(Character picker)
@@ -294,7 +300,7 @@ namespace Barotrauma.Items.Components
else else
{ {
if (!powerTransfer.CanTransfer) continue; if (!powerTransfer.CanTransfer) continue;
powerTransfer.CheckJunctions(deltaTime, false, !c.IsOutput); powerTransfer.CheckJunctions(deltaTime, false, !c.IsOutput || inputOnly);
} }
continue; continue;
@@ -363,6 +369,8 @@ namespace Barotrauma.Items.Components
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power) public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power)
{ {
if (connection.IsPower) return;
base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power); base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power);
if (!connectedRecipients.ContainsKey(connection)) return; if (!connectedRecipients.ContainsKey(connection)) return;