Fire probability and the voltage required for a PowerTransfer item to take damage can be configured in the xml. Docking ports & hatches don't get broken by excess voltage. Closes #589

This commit is contained in:
Joonas Rikkonen
2018-08-11 17:09:36 +03:00
parent f99bec4ed2
commit d98de2c305
2 changed files with 35 additions and 26 deletions

View File

@@ -103,8 +103,7 @@
<Item
name="Docking Port"
linkable="true"
>
linkable="true">
<Sprite texture ="dockingport.png" sourcerect="0,0,112,208" depth="0.94" origin="0.5,0.5"/>
@@ -116,14 +115,8 @@
<sound file="Content/Items/Door/doorBreak2.ogg" range="3000"/>
</StatusEffect>
</DockingPort>
<fixrequirement name="Electrical repairs">
<skill name="Electrical Engineering" level="40"/>
<item name="Wire"/>
<item name="Screwdriver"/>
</fixrequirement>
<PowerTransfer/>
<PowerTransfer CanBeOverloaded="false" FireProbability="0.0"/>
<Wire/>
<fixrequirement name="Mechanical repairs">
@@ -143,8 +136,7 @@
<Item
name="Docking Hatch"
linkable="true"
>
linkable="true">
<Sprite texture ="dockingport2.png" sourcerect="0,0,128,112" depth="0.94" origin="0.5,0.5"/>
@@ -157,13 +149,7 @@
</StatusEffect>
</DockingPort>
<fixrequirement name="Electrical repairs">
<skill name="Electrical Engineering" level="40"/>
<item name="Wire"/>
<item name="Screwdriver"/>
</fixrequirement>
<PowerTransfer/>
<PowerTransfer CanBeOverloaded="false" FireProbability="0.0"/>
<Wire/>
<fixrequirement name="Mechanical repairs">
@@ -183,8 +169,7 @@
<Item
name="Duct Block"
linkable="true"
>
linkable="true">
<Sprite texture ="duct.png" sourcerect="0,0,33,33" depth="0.01" origin="0.5,0.5"/>

View File

@@ -11,9 +11,7 @@ namespace Barotrauma.Items.Components
static float fullLoad;
private int updateCount;
const float FireProbability = 0.15f;
//affects how fast changes in power/load are carried over the grid
static float inertia = 5.0f;
@@ -42,6 +40,29 @@ namespace Barotrauma.Items.Components
get { return powerLoad; }
}
[Serialize(true, true), Editable(ToolTip = "Can the item be damaged if too much power is supplied to the power grid.")]
public bool CanBeOverloaded
{
get;
set;
}
[Serialize(2.0f, true), Editable(MinValueFloat = 1.0f, ToolTip =
"How much power has to be supplied to the grid relative to the load before item starts taking damage. "
+"E.g. a value of 2 means that the grid has to be receiving twice as much power as the devices in the grid are consuming.")]
public float OverloadVoltage
{
get;
set;
}
[Serialize(0.15f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 1.0f, ToolTip = "The probability for a fire to start when the item breaks.")]
public float FireProbability
{
get;
set;
}
//can the component transfer power
private bool canTransfer;
public bool CanTransfer
@@ -147,10 +168,13 @@ namespace Barotrauma.Items.Components
//(except if running as a client)
if (GameMain.Client != null) continue;
//if the item can't be fixed, don't allow it to break
if (item.FixRequirements.Count == 0 || !CanBeOverloaded) continue;
//relays don't blow up if the power is higher than load, only if the output is high enough
//(i.e. enough power passing through the relay)
if (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, 200.0f) * OverloadVoltage) continue;
float prevCondition = pt.item.Condition;
pt.item.Condition -= deltaTime * 10.0f;
@@ -170,7 +194,7 @@ namespace Barotrauma.Items.Components
}
#endif
if (FireProbability > 0.0f && Rand.Int((int)(1.0f / FireProbability)) == 1)
if (FireProbability > 0.0f && FireProbability < Rand.Range(0.0f, 1.0f))
{
new FireSource(pt.item.WorldPosition);
}