Release v0.15.12.0
This commit is contained in:
+31
-14
@@ -11,9 +11,12 @@ namespace Barotrauma.Items.Components
|
||||
private float generatedAmount;
|
||||
|
||||
//key = vent, float = total volume of the hull the vent is in and the hulls connected to it
|
||||
private Dictionary<Vent, float> ventList;
|
||||
private List<(Vent vent, float hullVolume)> ventList;
|
||||
|
||||
private float totalHullVolume;
|
||||
|
||||
private float ventUpdateTimer;
|
||||
const float VentUpdateInterval = 5.0f;
|
||||
|
||||
public float CurrFlow
|
||||
{
|
||||
@@ -31,6 +34,8 @@ namespace Barotrauma.Items.Components
|
||||
public OxygenGenerator(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
//randomize update timer so all oxygen generators don't update at the same time
|
||||
ventUpdateTimer = Rand.Range(0.0f, VentUpdateInterval);
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
@@ -64,7 +69,7 @@ namespace Barotrauma.Items.Components
|
||||
//20% condition = 4%
|
||||
CurrFlow *= conditionMult * conditionMult;
|
||||
|
||||
UpdateVents(CurrFlow);
|
||||
UpdateVents(CurrFlow, deltaTime);
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
@@ -75,7 +80,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private void GetVents()
|
||||
{
|
||||
ventList = new Dictionary<Vent, float>();
|
||||
totalHullVolume = 0.0f;
|
||||
ventList ??= new List<(Vent vent, float hullVolume)>();
|
||||
ventList.Clear();
|
||||
foreach (MapEntity entity in item.linkedTo)
|
||||
{
|
||||
if (!(entity is Item linkedItem)) { continue; }
|
||||
@@ -83,30 +90,40 @@ namespace Barotrauma.Items.Components
|
||||
Vent vent = linkedItem.GetComponent<Vent>();
|
||||
if (vent?.Item.CurrentHull == null) { continue; }
|
||||
|
||||
ventList.Add(vent, 0.0f);
|
||||
foreach (Hull connectedHull in vent.Item.CurrentHull.GetConnectedHulls(includingThis: true, searchDepth: 10, ignoreClosedGaps: true))
|
||||
{
|
||||
totalHullVolume += vent.Item.CurrentHull.Volume;
|
||||
ventList.Add((vent, vent.Item.CurrentHull.Volume));
|
||||
}
|
||||
|
||||
for (int i = 0; i < ventList.Count; i++)
|
||||
{
|
||||
Vent vent = ventList[i].vent;
|
||||
foreach (Hull connectedHull in vent.Item.CurrentHull.GetConnectedHulls(includingThis: false, searchDepth: 3, ignoreClosedGaps: true))
|
||||
{
|
||||
//another vent in the connected hull -> don't add it to this vent's total hull volume
|
||||
if (ventList.Any(v => v.vent != vent && v.vent.Item.CurrentHull == connectedHull)) { continue; }
|
||||
totalHullVolume += connectedHull.Volume;
|
||||
ventList[vent] += connectedHull.Volume;
|
||||
ventList[i] = (ventList[i].vent, ventList[i].hullVolume + connectedHull.Volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateVents(float deltaOxygen)
|
||||
|
||||
private void UpdateVents(float deltaOxygen, float deltaTime)
|
||||
{
|
||||
if (ventList == null)
|
||||
if (ventList == null || ventUpdateTimer < 0.0f)
|
||||
{
|
||||
GetVents();
|
||||
ventUpdateTimer = VentUpdateInterval;
|
||||
}
|
||||
ventUpdateTimer -= deltaTime;
|
||||
|
||||
if (!ventList.Any() || totalHullVolume <= 0.0f) { return; }
|
||||
|
||||
foreach (KeyValuePair<Vent, float> v in ventList)
|
||||
foreach ((Vent vent, float hullVolume) in ventList)
|
||||
{
|
||||
if (v.Key?.Item.CurrentHull == null) { continue; }
|
||||
if (vent.Item.CurrentHull == null) { continue; }
|
||||
|
||||
v.Key.OxygenFlow = deltaOxygen * (v.Value / totalHullVolume);
|
||||
v.Key.IsActive = true;
|
||||
vent.OxygenFlow = deltaOxygen * (hullVolume / totalHullVolume);
|
||||
vent.IsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user