/// <summary> /// Update the value supplied from a generator connected to the powernet /// </summary> public void UpdateGenerator(PowerGeneratorComponent generator) { if (Generatorlist.ContainsKey(generator)) { Supply -= Generatorlist[generator]; Generatorlist[generator] = generator.Supply; Supply += generator.Supply; } }
/// <summary> /// Remove a power supply from a generator connected to the powernet /// </summary> public void RemoveGenerator(PowerGeneratorComponent generator) { if (Generatorlist.ContainsKey(generator)) { Supply -= Generatorlist[generator]; Generatorlist.Remove(generator); } else { var name = generator.Owner.Prototype.Name; Logger.Log(String.Format("We tried to remove a device twice from the same power somehow, prototype {1}", name)); } }
/// <summary> /// Kills a powernet after it is marked dirty and its component have already been regenerated by the powernet system /// </summary> public void DirtyKill() { Wirelist.Clear(); while (Nodelist.Count != 0) { Nodelist[0].DisconnectFromPowernet(); } Generatorlist.Clear(); Deviceloadlist.Clear(); DepoweredDevices.Clear(); PowerStorageSupplierlist.Clear(); PowerStorageConsumerlist.Clear(); RemoveFromSystem(); }
/// <summary> /// Combines two powernets when they connect via powertransfer components /// </summary> public void MergePowernets(Powernet toMerge) { //TODO: load balance reconciliation between powernets on merge tick here foreach (var wire in toMerge.Wirelist) { wire.Parent = this; } Wirelist.AddRange(toMerge.Wirelist); toMerge.Wirelist.Clear(); foreach (var node in toMerge.Nodelist) { node.Parent = this; } Nodelist.AddRange(toMerge.Nodelist); toMerge.Nodelist.Clear(); foreach (var generator in toMerge.Generatorlist) { Generatorlist.Add(generator.Key, generator.Value); } toMerge.Generatorlist.Clear(); foreach (var device in toMerge.Deviceloadlist) { Deviceloadlist.Add(device); } toMerge.Deviceloadlist.Clear(); DepoweredDevices.AddRange(toMerge.DepoweredDevices); toMerge.DepoweredDevices.Clear(); PowerStorageSupplierlist.AddRange(toMerge.PowerStorageSupplierlist); toMerge.PowerStorageSupplierlist.Clear(); PowerStorageConsumerlist.AddRange(toMerge.PowerStorageConsumerlist); toMerge.PowerStorageConsumerlist.Clear(); toMerge.RemoveFromSystem(); }
/// <summary> /// Register a power supply from a generator connected to the powernet /// </summary> public void AddGenerator(PowerGeneratorComponent generator) { Generatorlist.Add(generator, generator.Supply); Supply += generator.Supply; }