Fixed relays burning out when connected to the main power grid. The changes in bb98767 caused relay components to be considered parts of whichever power grid they're connected to, causing their power and load to match the rest of the grid which usually causes them to go over the max power value. Closes #279
+ Fixed "powerConnections" field not being updated when creating PowerTransfer components mid-round, which made fabricated relays unusable for power transfer.
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components
|
|||||||
static float fullPower;
|
static float fullPower;
|
||||||
static float fullLoad;
|
static float fullLoad;
|
||||||
|
|
||||||
private int updateTimer;
|
private int updateCount;
|
||||||
|
|
||||||
const float FireProbability = 0.15f;
|
const float FireProbability = 0.15f;
|
||||||
|
|
||||||
@@ -19,6 +19,20 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
private HashSet<PowerTransfer> connectedPoweredList = new HashSet<PowerTransfer>();
|
private HashSet<PowerTransfer> connectedPoweredList = new HashSet<PowerTransfer>();
|
||||||
private List<Connection> powerConnections;
|
private List<Connection> powerConnections;
|
||||||
|
public List<Connection> PowerConnections
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (powerConnections == null)
|
||||||
|
{
|
||||||
|
var connections = Item.Connections;
|
||||||
|
powerConnections = connectedPoweredList == null ? new List<Connection>() : connections.FindAll(c => c.IsPower);
|
||||||
|
|
||||||
|
}
|
||||||
|
return powerConnections;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private Dictionary<Connection, bool> connectionDirty = new Dictionary<Connection, bool>();
|
private Dictionary<Connection, bool> connectionDirty = new Dictionary<Connection, bool>();
|
||||||
|
|
||||||
@@ -58,6 +72,8 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
if (base.IsActive == value) return;
|
if (base.IsActive == value) return;
|
||||||
base.IsActive = value;
|
base.IsActive = value;
|
||||||
|
powerLoad = 0.0f;
|
||||||
|
currPowerConsumption = 0.0f;
|
||||||
|
|
||||||
SetAllConnectionsDirty();
|
SetAllConnectionsDirty();
|
||||||
if (!base.IsActive)
|
if (!base.IsActive)
|
||||||
@@ -73,8 +89,6 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
canTransfer = true;
|
canTransfer = true;
|
||||||
|
|
||||||
powerConnections = new List<Connection>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||||
@@ -83,6 +97,8 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (!isBroken)
|
if (!isBroken)
|
||||||
{
|
{
|
||||||
|
powerLoad = 0.0f;
|
||||||
|
currPowerConsumption = 0.0f;
|
||||||
SetAllConnectionsDirty();
|
SetAllConnectionsDirty();
|
||||||
RefreshConnections();
|
RefreshConnections();
|
||||||
isBroken = true;
|
isBroken = true;
|
||||||
@@ -100,10 +116,10 @@ namespace Barotrauma.Items.Components
|
|||||||
isBroken = false;
|
isBroken = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateTimer > 0)
|
if (updateCount > 0)
|
||||||
{
|
{
|
||||||
//this junction box has already been updated this frame
|
//this junction box has already been updated this frame
|
||||||
updateTimer--;
|
updateCount--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +131,7 @@ namespace Barotrauma.Items.Components
|
|||||||
connectedPoweredList.Clear();
|
connectedPoweredList.Clear();
|
||||||
|
|
||||||
CheckPower(deltaTime);
|
CheckPower(deltaTime);
|
||||||
updateTimer = 0;
|
updateCount = 0;
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
foreach (PowerTransfer pt in connectedPoweredList)
|
foreach (PowerTransfer pt in connectedPoweredList)
|
||||||
@@ -125,9 +141,11 @@ namespace Barotrauma.Items.Components
|
|||||||
pt.Item.SendSignal(0, "", "power", null, fullPower / Math.Max(fullLoad, 1.0f));
|
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));
|
pt.Item.SendSignal(0, "", "power_out", null, fullPower / Math.Max(fullLoad, 1.0f));
|
||||||
|
|
||||||
//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;
|
//relay components work differently, they can be connected to a high-powered junction box
|
||||||
|
//and only break if the output (~the power running through the relay) is too high
|
||||||
|
if (GameMain.Client != null || this is RelayComponent) 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;
|
||||||
@@ -247,11 +265,10 @@ namespace Barotrauma.Items.Components
|
|||||||
//all the generated/consumed power of the constructions connected to the grid
|
//all the generated/consumed power of the constructions connected to the grid
|
||||||
private void CheckPower(float deltaTime)
|
private void CheckPower(float deltaTime)
|
||||||
{
|
{
|
||||||
updateTimer = 1;
|
updateCount = 1;
|
||||||
|
|
||||||
connectedPoweredList.Clear();
|
connectedPoweredList.Clear();
|
||||||
|
|
||||||
foreach (Connection c in powerConnections)
|
foreach (Connection c in PowerConnections)
|
||||||
{
|
{
|
||||||
HashSet<Connection> recipients = connectedRecipients[c];
|
HashSet<Connection> recipients = connectedRecipients[c];
|
||||||
foreach (Connection recipient in recipients)
|
foreach (Connection recipient in recipients)
|
||||||
@@ -267,8 +284,21 @@ namespace Barotrauma.Items.Components
|
|||||||
PowerTransfer powerTransfer = powered as PowerTransfer;
|
PowerTransfer powerTransfer = powered as PowerTransfer;
|
||||||
if (powerTransfer != null)
|
if (powerTransfer != null)
|
||||||
{
|
{
|
||||||
connectedPoweredList.Add(powerTransfer);
|
if (!powerTransfer.CanTransfer) continue;
|
||||||
powerTransfer.updateTimer = 1;
|
if (powerTransfer is RelayComponent != this is RelayComponent && c.IsPower)
|
||||||
|
{
|
||||||
|
//relay components and junction boxes aren't treated as parts of the same power grid
|
||||||
|
//connected relays simply increase the load of the grid (and jbs connected to relays increase the load of the relay)
|
||||||
|
if (c.IsOutput)
|
||||||
|
{
|
||||||
|
fullLoad += powerTransfer.powerLoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
connectedPoweredList.Add(powerTransfer);
|
||||||
|
powerTransfer.updateCount = 1;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +307,8 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
if (recipient.Name == "power_in")
|
if (recipient.Name == "power_in")
|
||||||
{
|
{
|
||||||
fullLoad += powerContainer.CurrPowerConsumption;
|
//batteries connected to power_in never increase load
|
||||||
|
if (c.IsOutput) fullLoad += powerContainer.CurrPowerConsumption;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -289,10 +320,10 @@ namespace Barotrauma.Items.Components
|
|||||||
//positive power consumption = the construction requires power -> increase load
|
//positive power consumption = the construction requires power -> increase load
|
||||||
if (powered.CurrPowerConsumption > 0.0f)
|
if (powered.CurrPowerConsumption > 0.0f)
|
||||||
{
|
{
|
||||||
fullLoad += powered.CurrPowerConsumption;
|
//items connected to power_in never increase load
|
||||||
|
if (c.IsOutput) fullLoad += powered.CurrPowerConsumption;
|
||||||
}
|
}
|
||||||
else if (powered.CurrPowerConsumption < 0.0f)
|
else if (powered.CurrPowerConsumption < 0.0f) //negative power consumption = the construction is a generator/battery
|
||||||
//negative power consumption = the construction is a /generator/battery
|
|
||||||
{
|
{
|
||||||
fullPower -= powered.CurrPowerConsumption;
|
fullPower -= powered.CurrPowerConsumption;
|
||||||
}
|
}
|
||||||
@@ -327,9 +358,6 @@ namespace Barotrauma.Items.Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
powerConnections = connections.FindAll(c => c.IsPower);
|
|
||||||
if (powerConnections.Count == 0) IsActive = false;
|
|
||||||
|
|
||||||
SetAllConnectionsDirty();
|
SetAllConnectionsDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,28 +41,10 @@ namespace Barotrauma.Items.Components
|
|||||||
Connection recipient = Wires[i].OtherConnection(this);
|
Connection recipient = Wires[i].OtherConnection(this);
|
||||||
if (recipient != null) recipients.Add(recipient);
|
if (recipient != null) recipients.Add(recipient);
|
||||||
}
|
}
|
||||||
if (internalConnection != null) recipients.Add(internalConnection);
|
|
||||||
return recipients;
|
return recipients;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//another connection in the same connection panel
|
|
||||||
private Connection internalConnection;
|
|
||||||
public Connection InternalConnection
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return internalConnection;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (internalConnection != null) internalConnection.internalConnection = null;
|
|
||||||
|
|
||||||
internalConnection = value;
|
|
||||||
if (internalConnection != null) internalConnection.internalConnection = this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Item Item
|
public Item Item
|
||||||
{
|
{
|
||||||
get { return item; }
|
get { return item; }
|
||||||
|
|||||||
@@ -45,24 +45,13 @@ namespace Barotrauma.Items.Components
|
|||||||
IsActive = true;
|
IsActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnMapLoaded()
|
|
||||||
{
|
|
||||||
base.OnMapLoaded();
|
|
||||||
|
|
||||||
ConnectionPanel connectionPanel = item.GetComponent<ConnectionPanel>();
|
|
||||||
var powerIn = connectionPanel.Connections.Find(c => c.Name == "power_in");
|
|
||||||
var powerOut = connectionPanel.Connections.Find(c => c.Name == "power_out");
|
|
||||||
|
|
||||||
if (powerIn != null) powerIn.InternalConnection = powerOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
{
|
{
|
||||||
base.Update(deltaTime, cam);
|
base.Update(deltaTime, cam);
|
||||||
|
|
||||||
item.SendSignal(0, IsOn ? "1" : "0", "state_out", null);
|
item.SendSignal(0, IsOn ? "1" : "0", "state_out", null);
|
||||||
|
|
||||||
if (-currPowerConsumption > maxPower) item.Condition = 0.0f;
|
if (Math.Min(-currPowerConsumption, PowerLoad) > maxPower) item.Condition = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
|
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
|
||||||
@@ -82,7 +71,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (connectionNumber > 0) outConnection += connectionNumber;
|
if (connectionNumber > 0) outConnection += connectionNumber;
|
||||||
|
|
||||||
item.SendSignal(stepsTaken, signal, outConnection, sender, power);
|
item.SendSignal(stepsTaken, signal, outConnection, sender, power);
|
||||||
}
|
}
|
||||||
else if (connection.Name == "toggle")
|
else if (connection.Name == "toggle")
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user