Server LuaCsForBarotrauma
Powered.cs
1 using System;
2 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
4 using System.Linq;
5 #if CLIENT
6 using Barotrauma.Sounds;
7 #endif
8 
10 {
14  public enum PowerPriority
15  {
16  Default = 0, // Use for status effects and/or extraload
17  Reactor = 1,
18  Relay = 3,
19  Battery = 5
20  }
21 
22  readonly struct PowerRange
23  {
24  public readonly static PowerRange Zero = default;
25 
26  public readonly float Min;
27  public readonly float Max;
28 
32  public readonly float ReactorMaxOutput;
33 
34  public PowerRange(float min, float max) : this(min, max, 0.0f)
35  {
36  }
37 
38  public PowerRange(float min, float max, float reactorMaxOutput)
39  {
40  System.Diagnostics.Debug.Assert(max >= min);
41  System.Diagnostics.Debug.Assert(min >= 0);
42  System.Diagnostics.Debug.Assert(max >= 0);
43  Min = min;
44  Max = max;
45  ReactorMaxOutput = reactorMaxOutput;
46  }
47 
49  {
50  return new PowerRange(a.Min + b.Min, a.Max + b.Max, a.ReactorMaxOutput + b.ReactorMaxOutput);
51  }
53  {
54  return new PowerRange(a.Min - b.Min, a.Max - b.Max, a.ReactorMaxOutput - b.ReactorMaxOutput);
55  }
56  }
57 
58  partial class Powered : ItemComponent
59  {
60  //TODO: test sparser update intervals?
61  protected const float UpdateInterval = (float)Timing.Step;
62 
66  private static readonly List<Powered> poweredList = new List<Powered>();
67  public static IEnumerable<Powered> PoweredList
68  {
69  get { return poweredList; }
70  }
71 
72  public static readonly HashSet<Connection> ChangedConnections = new HashSet<Connection>();
73 
74  public readonly static Dictionary<int, GridInfo> Grids = new Dictionary<int, GridInfo>();
75 
79  protected float currPowerConsumption;
80 
84  private float voltage;
85 
89  private float minVoltage;
90 
94  protected float powerConsumption;
95 
96  protected Connection powerIn, powerOut;
97 
101  protected const float MaxOverVoltageFactor = 2.0f;
102 
103  protected virtual PowerPriority Priority { get { return PowerPriority.Default; } }
104 
105  [Header(localizedTextTag: "sp.powered.propertyheader")]
106  [Editable, Serialize(0.5f, IsPropertySaveable.Yes, description: "The minimum voltage required for the device to function. " +
107  "The voltage is calculated as power / powerconsumption, meaning that a device " +
108  "with a power consumption of 1000 kW would need at least 500 kW of power to work if the minimum voltage is set to 0.5.")]
109  public float MinVoltage
110  {
111  get { return powerConsumption <= 0.0f ? 0.0f : minVoltage; }
112  set { minVoltage = value; }
113  }
114 
115  [Editable, Serialize(0.0f, IsPropertySaveable.Yes, description: "How much power the device draws (or attempts to draw) from the electrical grid when active.")]
116  public float PowerConsumption
117  {
118  get { return powerConsumption; }
119  set { powerConsumption = value; }
120  }
121 
122  [Serialize(false, IsPropertySaveable.Yes, description: "Is the device currently active. Inactive devices don't consume power.")]
123  public override bool IsActive
124  {
125  get { return base.IsActive; }
126  set
127  {
128  base.IsActive = value;
129  if (!value)
130  {
131  currPowerConsumption = 0.0f;
132  }
133  }
134  }
135 
136  [Serialize(0.0f, IsPropertySaveable.Yes, description: "The current power consumption of the device. Intended to be used by StatusEffect conditionals (setting the value from XML is not recommended).")]
137  public float CurrPowerConsumption
138  {
139  get {return currPowerConsumption; }
140  set { currPowerConsumption = value; }
141  }
142 
143  [Serialize(0.0f, IsPropertySaveable.Yes, description: "The current voltage of the item (calculated as power consumption / available power). Intended to be used by StatusEffect conditionals (setting the value from XML is not recommended).")]
144  public float Voltage
145  {
146  get
147  {
148  if (PoweredByTinkering)
149  {
150  return 1.0f;
151  }
152  else if (powerIn != null)
153  {
154  if (powerIn?.Grid != null) { return powerIn.Grid.Voltage; }
155  }
156  else if (powerOut != null)
157  {
158  if (powerOut?.Grid != null) { return powerOut.Grid.Voltage; }
159  }
160  return PowerConsumption <= 0.0f ? 1.0f : voltage;
161  }
162  set
163  {
164  voltage = Math.Max(0.0f, value);
165  }
166  }
167 
172  public float RelativeVoltage => minVoltage <= 0.0f ? 1.0f : MathHelper.Clamp(Voltage / minVoltage, 0.0f, 1.0f);
173 
174  public virtual bool HasPower => Voltage >= MinVoltage;
175 
176  public bool PoweredByTinkering { get; set; }
177 
178  [Editable, Serialize(true, IsPropertySaveable.Yes, description: "Can the item be damaged by electomagnetic pulses.")]
179  public bool VulnerableToEMP
180  {
181  get;
182  set;
183  }
184 
185  public Powered(Item item, ContentXElement element)
186  : base(item, element)
187  {
188  poweredList.Add(this);
189  InitProjectSpecific(element);
190  }
191 
192  partial void InitProjectSpecific(ContentXElement element);
193 
194  protected void UpdateOnActiveEffects(float deltaTime)
195  {
196  if (currPowerConsumption <= 0.0f && PowerConsumption <= 0.0f)
197  {
198  //if the item consumes no power, ignore the voltage requirement and
199  //apply OnActive statuseffects as long as this component is active
200  ApplyStatusEffects(ActionType.OnActive, deltaTime);
201  return;
202  }
203 
204  if (Voltage > minVoltage)
205  {
206  ApplyStatusEffects(ActionType.OnActive, deltaTime);
207  }
208 #if CLIENT
209  if (Voltage > minVoltage)
210  {
211  if (!powerOnSoundPlayed && powerOnSound != null)
212  {
213  SoundPlayer.PlaySound(powerOnSound.Sound, item.WorldPosition, powerOnSound.Volume, powerOnSound.Range, hullGuess: item.CurrentHull, ignoreMuffling: powerOnSound.IgnoreMuffling, freqMult: powerOnSound.GetRandomFrequencyMultiplier());
214  powerOnSoundPlayed = true;
215  }
216  }
217  else if (Voltage < 0.1f)
218  {
219  powerOnSoundPlayed = false;
220  }
221 #endif
222  }
223 
224  public override void Update(float deltaTime, Camera cam)
225  {
226  UpdateOnActiveEffects(deltaTime);
227  }
228 
229  public override void OnItemLoaded()
230  {
231  if (item.Connections == null) { return; }
232  foreach (Connection c in item.Connections)
233  {
234  if (!c.IsPower) { continue; }
235  if (this is PowerTransfer pt)
236  {
237  if (c.Name == "power_in")
238  {
239  powerIn = c;
240  }
241  else if (c.Name == "power_out")
242  {
243  powerOut = c;
244  // Connection takes the lowest priority
245  if (Priority > powerOut.Priority)
246  {
247  powerOut.Priority = Priority;
248  }
249  }
250  else if (c.Name == "power")
251  {
252  powerIn = powerOut = c;
253  }
254  }
255  else
256  {
257  if (c.IsOutput)
258  {
259  if (c.Name == "power_in")
260  {
261 #if DEBUG
262  DebugConsole.ThrowError($"Item \"{item.Name}\" has a power output connection called power_in. If the item is supposed to receive power through the connection, change it to an input connection.");
263 #else
264  DebugConsole.NewMessage($"Item \"{item.Name}\" has a power output connection called power_in. If the item is supposed to receive power through the connection, change it to an input connection.", Color.Orange);
265 #endif
266  }
267  powerOut = c;
268  // Connection takes the lowest priority
269  if (Priority > powerOut.Priority)
270  {
271  powerOut.Priority = Priority;
272  }
273  }
274  else
275  {
276  if (c.Name == "power_out")
277  {
278 #if DEBUG
279  DebugConsole.ThrowError($"Item \"{item.Name}\" has a power input connection called power_out. If the item is supposed to output power through the connection, change it to an output connection.");
280 #else
281  DebugConsole.NewMessage($"Item \"{item.Name}\" has a power input connection called power_out. If the item is supposed to output power through the connection, change it to an output connection.", Color.Orange);
282 #endif
283  }
284  powerIn = c;
285  }
286  }
287  }
288  }
289 
290 
295  public static void UpdateGrids(bool useCache = true)
296  {
297  //don't use cache if there are no existing grids
298  if (Grids.Count > 0 && useCache)
299  {
300  //delete all grids that were affected
301  foreach (Connection c in ChangedConnections)
302  {
303  if (c.Grid != null)
304  {
305  Grids.Remove(c.Grid.ID);
306  c.Grid = null;
307  }
308  }
309 
310  foreach (Connection c in ChangedConnections)
311  {
312  //Make sure the connection grid hasn't been resolved by another connection update
313  //Ensure the connection has other connections
314  if (c.Grid == null && c.Recipients.Count > 0 && c.Item.Condition > 0.0f)
315  {
316  GridInfo grid = PropagateGrid(c);
317  Grids[grid.ID] = grid;
318  }
319  }
320  }
321  else
322  {
323  //Clear all grid IDs from connections
324  foreach (Powered powered in poweredList)
325  {
326  //Only check devices with connectors
327  if (powered.powerIn != null)
328  {
329  powered.powerIn.Grid = null;
330  }
331  if (powered.powerOut != null)
332  {
333  powered.powerOut.Grid = null;
334  }
335  }
336 
337  Grids.Clear();
338 
339  foreach (Powered powered in poweredList)
340  {
341  //Probe through all connections that don't have a gridID
342  if (powered.powerIn != null && powered.powerIn.Grid == null && powered.powerIn != powered.powerOut && powered.Item.Condition > 0.0f)
343  {
344  // Only create grids for networks with more than 1 device
345  if (powered.powerIn.Recipients.Count > 0)
346  {
347  GridInfo grid = PropagateGrid(powered.powerIn);
348  Grids[grid.ID] = grid;
349  }
350  }
351 
352  if (powered.powerOut != null && powered.powerOut.Grid == null && powered.Item.Condition > 0.0f)
353  {
354  //Only create grids for networks with more than 1 device
355  if (powered.powerOut.Recipients.Count > 0)
356  {
357  GridInfo grid = PropagateGrid(powered.powerOut);
358  Grids[grid.ID] = grid;
359  }
360  }
361  }
362  }
363 
364  //Clear changed connections after each update
365  ChangedConnections.Clear();
366  }
367 
368  private static GridInfo PropagateGrid(Connection conn)
369  {
370  //Generate unique Key
371  int id = Rand.Int(int.MaxValue, Rand.RandSync.Unsynced);
372  while (Grids.ContainsKey(id))
373  {
374  id = Rand.Int(int.MaxValue, Rand.RandSync.Unsynced);
375  }
376 
377  return PropagateGrid(conn, id);
378  }
379 
380  private static GridInfo PropagateGrid(Connection conn, int gridID)
381  {
382  Stack<Connection> probeStack = new Stack<Connection>();
383 
384  GridInfo grid = new GridInfo(gridID);
385 
386  probeStack.Push(conn);
387 
388  //Non recursive approach to traversing connection tree
389  while (probeStack.Count > 0)
390  {
391  Connection c = probeStack.Pop();
392  c.Grid = grid;
393  grid.AddConnection(c);
394 
395  //Add on recipients
396  foreach (Connection otherC in c.Recipients)
397  {
398  //Only add valid connections
399  if (otherC.Grid != grid && (otherC.Grid == null || !Grids.ContainsKey(otherC.Grid.ID)) && ValidPowerConnection(c, otherC))
400  {
401  otherC.Grid = grid; //Assigning ID early prevents unncessary adding to stack
402  probeStack.Push(otherC);
403  }
404  }
405  }
406 
407  return grid;
408  }
409 
425  public static void UpdatePower(float deltaTime)
426  {
427  //Don't update the power if the round is ending
429  {
430  return;
431  }
432 
433  //Only update the power at the given update interval
434  /*
435  //Not use currently as update interval of 1/60
436  if (updateTimer > 0.0f)
437  {
438  updateTimer -= deltaTime;
439  return;
440  }
441  updateTimer = UpdateInterval;
442  */
443 
444 #if CLIENT
445  System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
446  sw.Start();
447 #endif
448  //Ensure all grids are updated correctly and have the correct connections
449  UpdateGrids();
450 
451 #if CLIENT
452  sw.Stop();
453  GameMain.PerformanceCounter.AddElapsedTicks("Update:Power", sw.ElapsedTicks);
454  sw.Restart();
455 #endif
456 
457  //Reset all grids
458  foreach (GridInfo grid in Grids.Values)
459  {
460  //Wipe priority groups as connections can change to not be outputting -- Can be improved caching wise --
461  grid.PowerSourceGroups.Clear();
462  grid.Power = 0;
463  grid.Load = 0;
464  }
465 
466  //Determine if devices are adding a load or providing power, also resolve solo nodes
467  foreach (Powered powered in poweredList)
468  {
469  //Make voltage decay to ensure the device powers down.
470  //This only effects devices with no power input (whose voltage is set by other means, e.g. status effects from a contained battery)
471  //or devices that have been disconnected from the power grid - other devices use the voltage of the grid instead.
472  powered.Voltage -= deltaTime;
473 
474  //Handle the device if it's got a power connection
475  if (powered.powerIn != null && powered.powerOut != powered.powerIn)
476  {
477  //Get the new load for the connection
478  float currLoad = powered.GetCurrentPowerConsumption(powered.powerIn);
479 
480  //If its a load update its grid load
481  if (currLoad >= 0)
482  {
483  if (powered.PoweredByTinkering) { currLoad = 0.0f; }
484  powered.CurrPowerConsumption = currLoad;
485  if (powered.powerIn.Grid != null)
486  {
487  powered.powerIn.Grid.Load += currLoad;
488  }
489  }
490  else if (powered.powerIn.Grid != null)
491  {
492  //If connected to a grid add as a source to be processed
493  powered.powerIn.Grid.AddSrc(powered.powerIn);
494  }
495  else
496  {
497  powered.CurrPowerConsumption = -powered.GetConnectionPowerOut(powered.powerIn, 0, powered.MinMaxPowerOut(powered.powerIn, 0), 0);
498  powered.GridResolved(powered.powerIn);
499  }
500  }
501 
502  //Handle the device power depending on if its powerout
503  if (powered.powerOut != null)
504  {
505  //Get the connection's load
506  float currLoad = powered.GetCurrentPowerConsumption(powered.powerOut);
507 
508  //Update the device's output load to the correct variable
509  if (powered is PowerTransfer pt)
510  {
511  pt.PowerLoad = currLoad;
512  }
513  else if (powered is PowerContainer pc)
514  {
515  // PowerContainer handle its own output value
516  }
517  else
518  {
519  powered.CurrPowerConsumption = currLoad;
520  }
521 
522  if (currLoad >= 0)
523  {
524  //Add to the grid load if possible
525  if (powered.powerOut.Grid != null)
526  {
527  powered.powerOut.Grid.Load += currLoad;
528  }
529  }
530  else if (powered.powerOut.Grid != null)
531  {
532  //Add connection as a source to be processed
533  powered.powerOut.Grid.AddSrc(powered.powerOut);
534  }
535  else
536  {
537  //Perform power calculations for the singular connection
538  float loadOut = -powered.GetConnectionPowerOut(powered.powerOut, 0, powered.MinMaxPowerOut(powered.powerOut, 0), 0);
539  if (powered is PowerTransfer pt2)
540  {
541  pt2.PowerLoad = loadOut;
542  }
543  else if (powered is PowerContainer pc)
544  {
545  //PowerContainer handles its own output value
546  }
547  else
548  {
549  powered.CurrPowerConsumption = loadOut;
550  }
551 
552  //Indicate grid is resolved as it was the only device
553  powered.GridResolved(powered.powerOut);
554  }
555  }
556  }
557 
558  //Iterate through all grids to determine the power on the grid
559  foreach (GridInfo grid in Grids.Values)
560  {
561  //Iterate through the priority src groups lowest first
562  foreach (PowerSourceGroup scrGroup in grid.PowerSourceGroups.Values)
563  {
564  scrGroup.MinMaxPower = PowerRange.Zero;
565 
566  //Iterate through all connections in the group to get their minmax power and sum them
567  foreach (Connection c in scrGroup.Connections)
568  {
569  foreach (var device in c.Item.GetComponents<Powered>())
570  {
571  scrGroup.MinMaxPower += device.MinMaxPowerOut(c, grid.Load);
572  }
573  }
574 
575  //Iterate through all connections to get their final power out provided the min max information
576  float addedPower = 0;
577  foreach (Connection c in scrGroup.Connections)
578  {
579  foreach (var device in c.Item.GetComponents<Powered>())
580  {
581  addedPower += device.GetConnectionPowerOut(c, grid.Power, scrGroup.MinMaxPower, grid.Load);
582  }
583  }
584 
585  //Add the power to the grid
586  grid.Power += addedPower;
587  }
588 
589  //Calculate Grid voltage, limit between 0 - 1000
590  float newVoltage = MathHelper.Min(grid.Power / MathHelper.Max(grid.Load, 1E-10f), 1000);
591  if (float.IsNegative(newVoltage))
592  {
593  newVoltage = 0.0f;
594  }
595 
596  grid.Voltage = newVoltage;
597 
598  //Iterate through all connections on that grid and run their gridResolved function
599  foreach (Connection c in grid.Connections)
600  {
601  foreach (var device in c.Item.GetComponents<Powered>())
602  {
603  device?.GridResolved(c);
604  }
605  }
606  }
607 
608 #if CLIENT
609  sw.Stop();
610  GameMain.PerformanceCounter.AddElapsedTicks("Update:Power", sw.ElapsedTicks);
611 #endif
612  }
613 
618  public virtual float GetCurrentPowerConsumption(Connection connection = null)
619  {
620  // If a handheld device there is no consumption
621  if (powerIn == null && powerOut == null)
622  {
623  return 0;
624  }
625 
626  // Add extraload for PowerTransfer devices
627  if (this is PowerTransfer pt)
628  {
629  return PowerConsumption + pt.ExtraLoad;
630  }
631  else if (connection != this.powerIn || !IsActive)
632  {
633  //If not the power in connection or is inactive there is no draw
634  return 0;
635  }
636 
637  //Otherwise return the max powerconsumption of the device
638  return PowerConsumption;
639  }
640 
646  public virtual PowerRange MinMaxPowerOut(Connection conn, float load = 0)
647  {
648  return PowerRange.Zero;
649  }
650 
658  public virtual float GetConnectionPowerOut(Connection conn, float power, PowerRange minMaxPower, float load)
659  {
660  return conn == powerOut ? MathHelper.Max(-CurrPowerConsumption, 0) : 0;
661  }
662 
666  public virtual void GridResolved(Connection conn) { }
667 
668  public static bool ValidPowerConnection(Connection conn1, Connection conn2)
669  {
670  return
671  conn1.IsPower && conn2.IsPower &&
672  conn1.Item.Condition > 0.0f && conn2.Item.Condition > 0.0f &&
673  conn1.Item.GetComponent<PowerTransfer>() is not { CanTransfer: false } &&
674  conn2.Item.GetComponent<PowerTransfer>() is not { CanTransfer: false } &&
675  (conn1.Item.HasTag(Tags.JunctionBox) || conn2.Item.HasTag(Tags.JunctionBox) || conn1.Item.HasTag(Tags.DockingPort) || conn2.Item.HasTag(Tags.DockingPort) || conn1.IsOutput != conn2.IsOutput);
676  }
677 
682  {
683  if (item.Connections == null || powerIn == null) { return 0.0f; }
684  float availablePower = 0.0f;
685  var recipients = powerIn.Recipients;
686  foreach (Connection recipient in recipients)
687  {
688  if (!recipient.IsPower || !recipient.IsOutput) { continue; }
689  var battery = recipient.Item?.GetComponent<PowerContainer>();
690  if (battery == null || battery.Item.Condition <= 0.0f) { continue; }
691  if (battery.OutputDisabled) { continue; }
692  float maxOutputPerFrame = battery.MaxOutPut / 60.0f;
693  float framesPerMinute = 3600.0f;
694  availablePower += Math.Min(battery.Charge * framesPerMinute, maxOutputPerFrame);
695  }
696  return availablePower;
697  }
698 
699  protected IEnumerable<PowerContainer> GetDirectlyConnectedBatteries()
700  {
701  if (item.Connections != null && powerIn != null)
702  {
703  foreach (Connection recipient in powerIn.Recipients)
704  {
705  if (!recipient.IsPower || !recipient.IsOutput) { continue; }
706  if (recipient.Item?.GetComponent<PowerContainer>() is PowerContainer battery)
707  {
708  yield return battery;
709  }
710  }
711  }
712  }
713 
714  protected override void RemoveComponentSpecific()
715  {
716  //Flag power connections to be updated
717  if (item.Connections != null)
718  {
719  foreach (Connection c in item.Connections)
720  {
721  if (c.IsPower && c.Grid != null)
722  {
723  ChangedConnections.Add(c);
724  }
725  }
726  }
727 
728  base.RemoveComponentSpecific();
729  poweredList.Remove(this);
730  }
731  }
732 
733  partial class GridInfo
734  {
735  public readonly int ID;
736  public float Voltage = 0;
737  public float Load = 0;
738  public float Power = 0;
739 
740  public readonly List<Connection> Connections = new List<Connection>();
741  public readonly SortedList<PowerPriority, PowerSourceGroup> PowerSourceGroups = new SortedList<PowerPriority, PowerSourceGroup>();
742 
743  public GridInfo(int id)
744  {
745  ID = id;
746  }
747 
749  {
750  Connections.Remove(c);
751 
752  //Remove the grid if it has no devices
753  if (Connections.Count == 0 && Powered.Grids.ContainsKey(ID))
754  {
755  Powered.Grids.Remove(ID);
756  }
757  }
758 
759  public void AddConnection(Connection c)
760  {
761  Connections.Add(c);
762  }
763 
764  public void AddSrc(Connection c)
765  {
766  if (PowerSourceGroups.ContainsKey(c.Priority))
767  {
768  PowerSourceGroups[c.Priority].Connections.Add(c);
769  }
770  else
771  {
772  PowerSourceGroup group = new PowerSourceGroup();
773  group.Connections.Add(c);
774  PowerSourceGroups[c.Priority] = group;
775  }
776  }
777  }
778 
779  partial class PowerSourceGroup
780  {
782  public readonly List<Connection> Connections = new List<Connection>();
783 
785  {
786  }
787  }
788 }
static GameSession GameSession
Definition: GameMain.cs:45
void RemoveConnection(Connection c)
Definition: Powered.cs:748
void AddConnection(Connection c)
Definition: Powered.cs:759
readonly List< Connection > Connections
Definition: Powered.cs:740
readonly SortedList< PowerPriority, PowerSourceGroup > PowerSourceGroups
Definition: Powered.cs:741
The base class for components holding the different functionalities of the item
void ApplyStatusEffects(ActionType type, float deltaTime, Character character=null, Limb targetLimb=null, Entity useTarget=null, Character user=null, Vector2? worldPosition=null, float afflictionMultiplier=1.0f)
readonly List< Connection > Connections
Definition: Powered.cs:782
const float MaxOverVoltageFactor
Maximum voltage factor when the device is being overvolted. I.e. how many times more effectively the ...
Definition: Powered.cs:101
float RelativeVoltage
Essentially Voltage / MinVoltage (= how much of the minimum required voltage has been satisfied),...
Definition: Powered.cs:172
virtual float GetCurrentPowerConsumption(Connection connection=null)
Current power consumption of the device (or amount of generated power if negative)
Definition: Powered.cs:618
virtual PowerRange MinMaxPowerOut(Connection conn, float load=0)
Minimum and maximum power the connection can provide
Definition: Powered.cs:646
IEnumerable< PowerContainer > GetDirectlyConnectedBatteries()
Definition: Powered.cs:699
static readonly Dictionary< int, GridInfo > Grids
Definition: Powered.cs:74
Powered(Item item, ContentXElement element)
Definition: Powered.cs:185
float powerConsumption
The maximum amount of power the item can draw from connected items
Definition: Powered.cs:94
virtual void GridResolved(Connection conn)
Can be overridden to perform updates for the device after the connected grid has resolved its power c...
Definition: Powered.cs:666
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...
Definition: Powered.cs:229
virtual PowerPriority Priority
Definition: Powered.cs:103
static void UpdateGrids(bool useCache=true)
Allocate electrical devices into their grids based on connections
Definition: Powered.cs:295
float currPowerConsumption
The amount of power currently consumed by the item. Negative values mean that the item is providing p...
Definition: Powered.cs:79
float GetAvailableInstantaneousBatteryPower()
Returns the amount of power that can be supplied by batteries directly connected to the item
Definition: Powered.cs:681
override void Update(float deltaTime, Camera cam)
Definition: Powered.cs:224
virtual float GetConnectionPowerOut(Connection conn, float power, PowerRange minMaxPower, float load)
Finalize how much power the device will be outputting to the connection
Definition: Powered.cs:658
void UpdateOnActiveEffects(float deltaTime)
Definition: Powered.cs:194
static void UpdatePower(float deltaTime)
Update the power calculations of all devices and grids Updates grids in the order of ConnCurrConsumpt...
Definition: Powered.cs:425
static readonly HashSet< Connection > ChangedConnections
Definition: Powered.cs:72
static bool ValidPowerConnection(Connection conn1, Connection conn2)
Definition: Powered.cs:668
override void RemoveComponentSpecific()
Definition: Powered.cs:714
static IEnumerable< Powered > PoweredList
Definition: Powered.cs:68
PowerPriority
Order in which power sources will provide to a grid, lower number is higher priority
Definition: Powered.cs:15
ActionType
ActionTypes define when a StatusEffect is executed.
Definition: Enums.cs:26
PowerRange(float min, float max, float reactorMaxOutput)
Definition: Powered.cs:38
PowerRange(float min, float max)
Definition: Powered.cs:34
static PowerRange operator+(PowerRange a, PowerRange b)
Definition: Powered.cs:48
static readonly PowerRange Zero
Definition: Powered.cs:24
static PowerRange operator-(PowerRange a, PowerRange b)
Definition: Powered.cs:52
readonly float ReactorMaxOutput
Used by reactors to communicate their maximum output to each other so they can divide the grid load b...
Definition: Powered.cs:32