- relaycomponent inherits from powertransfer, so that they're included when calculating the load/power for the grid

- deactivated powertransfer components don't carry power
- fixed reactor graph lines going over the graph if load > 10 000
This commit is contained in:
Regalis
2016-05-24 19:17:42 +03:00
parent 52f28f98a7
commit ed529052a2
6 changed files with 37 additions and 9 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 585 B

@@ -14,6 +14,12 @@ namespace Barotrauma.Items.Components
set set
{ {
if (value == TextBlock.Text || item.Rect.Width < 5) return; if (value == TextBlock.Text || item.Rect.Width < 5) return;
if (textBlock.Rect.Width != item.Rect.Width || textBlock.Rect.Height != item.Rect.Height)
{
textBlock = null;
}
TextBlock.Text = value; TextBlock.Text = value;
} }
} }
@@ -452,11 +452,17 @@ namespace Barotrauma.Items.Components
spriteBatch.DrawString(GUI.Font, "Grid load: " + (int)load + " kW", spriteBatch.DrawString(GUI.Font, "Grid load: " + (int)load + " kW",
new Vector2(x + 600, y + 30), Color.Yellow); new Vector2(x + 600, y + 30), Color.Yellow);
float maxLoad = 0.0f;
foreach (float loadVal in loadGraph)
{
maxLoad = Math.Max(maxLoad, loadVal);
}
DrawGraph(tempGraph, spriteBatch, DrawGraph(tempGraph, spriteBatch,
new Rectangle(x + 30, y + 30, 400, 250), 10000.0f, xOffset, Color.Red); new Rectangle(x + 30, y + 30, 400, 250), Math.Max(10000.0f, maxLoad), xOffset, Color.Red);
DrawGraph(loadGraph, spriteBatch, DrawGraph(loadGraph, spriteBatch,
new Rectangle(x + 30, y + 30, 400, 250), 10000.0f, xOffset, Color.Yellow); new Rectangle(x + 30, y + 30, 400, 250), Math.Max(10000.0f, maxLoad), xOffset, Color.Yellow);
spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + (int)shutDownTemp, new Vector2(x + 450, y + 80), Color.White); spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + (int)shutDownTemp, new Vector2(x + 450, y + 80), Color.White);
@@ -124,7 +124,7 @@ namespace Barotrauma.Items.Components
foreach (Connection c2 in c.Recipients) foreach (Connection c2 in c.Recipients)
{ {
PowerTransfer pt = c2.Item.GetComponent<PowerTransfer>(); PowerTransfer pt = c2.Item.GetComponent<PowerTransfer>();
if (pt == null) continue; if (pt == null || !pt.IsActive) continue;
gridLoad += pt.PowerLoad; gridLoad += pt.PowerLoad;
} }
@@ -130,7 +130,7 @@ namespace Barotrauma.Items.Components
//if (it.Updated) continue; //if (it.Updated) continue;
Powered powered = it.GetComponent<Powered>(); Powered powered = it.GetComponent<Powered>();
if (powered == null) continue; if (powered == null || !powered.IsActive) continue;
if (connectedList.Contains(powered)) continue; if (connectedList.Contains(powered)) continue;
@@ -3,7 +3,7 @@ using System.Xml.Linq;
namespace Barotrauma.Items.Components namespace Barotrauma.Items.Components
{ {
class RelayComponent : ItemComponent class RelayComponent : PowerTransfer
{ {
private float maxPower; private float maxPower;
@@ -17,27 +17,43 @@ namespace Barotrauma.Items.Components
} }
} }
private bool isOn;
[Editable, HasDefaultValue(false, true)] [Editable, HasDefaultValue(false, true)]
public bool IsOn public bool IsOn
{ {
get; set; get
{
return IsActive;
}
set
{
isOn = value;
IsActive = value;
if (!IsActive)
{
currPowerConsumption = 0.0f;
}
}
} }
public RelayComponent(Item item, XElement element) public RelayComponent(Item item, XElement element)
: base (item, element) : base (item, element)
{ {
IsActive = true; IsActive = isOn;
IsOn = true;
} }
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
base.Update(deltaTime, cam);
item.SendSignal(0, IsOn ? "1" : "0", "state_out"); item.SendSignal(0, IsOn ? "1" : "0", "state_out");
} }
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f) public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
{ {
if (connection.IsPower && connection.Name.Contains("_out")) return;
if (item.Condition <= 0.0f) return; if (item.Condition <= 0.0f) return;
if (power > maxPower) item.Condition = 0.0f; if (power > maxPower) item.Condition = 0.0f;