1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
10 private float generatedAmount;
13 private List<(
Vent vent,
float hullVolume)> ventList;
15 private float totalHullVolume;
17 private float ventUpdateTimer;
18 const float VentUpdateInterval = 5.0f;
29 get {
return generatedAmount; }
30 set { generatedAmount = MathHelper.Clamp(value, -10000.0f, 10000.0f); }
37 ventUpdateTimer = Rand.Range(0.0f, VentUpdateInterval);
59 CurrFlow *= conditionMult * conditionMult;
77 item.GetComponent<
Repairable>()?.AdjustPowerConsumption(ref consumption);
83 base.UpdateBroken(deltaTime, cam);
87 private void GetVents()
89 totalHullVolume = 0.0f;
90 ventList ??=
new List<(Vent vent, float hullVolume)>();
94 if (entity is not
Item linkedItem) {
continue; }
96 Vent vent = linkedItem.GetComponent<Vent>();
99 totalHullVolume += vent.Item.CurrentHull.Volume;
100 ventList.Add((vent, vent.Item.CurrentHull.Volume));
103 for (
int i = 0; i < ventList.Count; i++)
105 Vent vent = ventList[i].vent;
106 foreach (Hull connectedHull
in vent.Item.CurrentHull.GetConnectedHulls(includingThis:
false, searchDepth: 3, ignoreClosedGaps:
true))
109 if (ventList.Any(v => v.vent != vent && v.vent.Item.CurrentHull == connectedHull)) {
continue; }
110 totalHullVolume += connectedHull.Volume;
111 ventList[i] = (ventList[i].vent, ventList[i].hullVolume + connectedHull.Volume);
116 private void UpdateVents(
float deltaOxygen,
float deltaTime)
118 if (ventList ==
null || ventUpdateTimer < 0.0f)
121 ventUpdateTimer = VentUpdateInterval;
123 ventUpdateTimer -= deltaTime;
125 if (!ventList.Any() || totalHullVolume <= 0.0f) {
return; }
127 foreach ((Vent vent,
float hullVolume) in ventList)
129 if (vent.Item.CurrentHull ==
null) {
continue; }
131 vent.OxygenFlow = deltaOxygen * (hullVolume / totalHullVolume);
132 vent.IsActive =
true;
138 if (ventList ==
null)
142 foreach ((
Vent vent,
float hullVolume) in ventList)
144 if (vent != targetVent) {
continue; }
145 return generatedAmount * 100.0f * (hullVolume / totalHullVolume);
OxygenGenerator(Item item, ContentXElement element)
override void Update(float deltaTime, Camera cam)
float GetVentOxygenFlow(Vent targetVent)
override float GetCurrentPowerConsumption(Connection connection=null)
Power consumption of the Oxygen Generator. Only consume power when active and adjust consumption base...
override void UpdateBroken(float deltaTime, Camera cam)
const float MaxOverVoltageFactor
Maximum voltage factor when the device is being overvolted. I.e. how many times more effectively the ...
float powerConsumption
The maximum amount of power the item can draw from connected items
void UpdateOnActiveEffects(float deltaTime)
readonly List< MapEntity > linkedTo