/// <summary> /// Sends updates to things that might need it /// </summary> private static void PowerNetworkUpdate() { // Profiler.BeginSample("PowerNetworkUpdate"); for (int i = 0; i < OrderList.Count; i++) { foreach (ElectricalNodeControl TheSupply in AliveSupplies[OrderList[i]]) { TheSupply.PowerNetworkUpdate(); } } foreach (ElectricalNodeControl ToWork in PoweredDevices) { ToWork.PowerNetworkUpdate(); } WorkingCableUpdates = new HashSet <CableInheritance>(CableUpdates); CableUpdates.Clear(); foreach (CableInheritance ToWork in WorkingCableUpdates) { ToWork.PowerNetworkUpdate(); //This is used to update the cables if they have the current change to detect if there was an overcurrent } WorkingCableUpdates.Clear(); if (CableToDestroy != null) { CableToDestroy.toDestroy(); CableToDestroy = null; } // Profiler.EndSample(); }
/// <summary> /// Sends updates to things that might need it /// </summary> private static void PowerNetworkUpdate() { for (int i = 0; i < OrderList.Count; i++) { foreach (PowerSupplyControlInheritance TheSupply in AliveSupplies[OrderList[i]]) { TheSupply.PowerNetworkUpdate(); } } foreach (PowerSupplyControlInheritance ToWork in PoweredDevices) { ToWork.PowerNetworkUpdate(); } }
/// <summary> /// Sends updates to things that might need it /// </summary> public void PowerNetworkUpdate() { //Logger.Log("PowerNetworkUpdate"); for (int i = 0; i < SupplyToadd.Count; i++) { InternalAddSupply(SupplyToadd[i]); } SupplyToadd.Clear(); for (int i = 0; i < OrderList.Count; i++) { foreach (ElectricalNodeControl TheSupply in AliveSupplies[OrderList[i]]) { TheSupply.PowerNetworkUpdate(); } } foreach (ElectricalNodeControl ToWork in PoweredDevices) { ToWork.PowerNetworkUpdate(); } foreach (CableInheritance ToWork in CableUpdates) { ToWork.PowerNetworkUpdate(); } CableUpdates.Clear(); if (CableToDestroy != null) { CableToDestroy.wireConnect.DestroyThisPlease(); CableToDestroy = null; } //Structure change and stuff foreach (var Thing in NUElectricalObjectsToDestroy) { Thing.DestroyingThisNow(); } NUElectricalObjectsToDestroy.Clear(); }
public static void DoUpdate() { //The beating heart if (!DeadEndSet) { DeadEnd.Categorytype = PowerTypeCategory.DeadEndConnection; //yeah Class stuff DeadEndSet = true; } if (tickRate == 0) { tickRate = tickRateComplete / 5; } tickCount += Time.deltaTime; if (tickCount > tickRate) { tickCount = 0f; if (StructureChange && (currentTick == 0)) { StructureChange = false; for (int i = 0; i < OrderList.Count; i++) { if (!(ALiveSupplies.ContainsKey(OrderList[i]))) { ALiveSupplies[OrderList[i]] = new HashSet <IElectricalNeedUpdate>(); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[OrderList[i]]) { TheSupply.PowerUpdateStructureChange(); } } foreach (IElectricalNeedUpdate ToWork in PoweredDevices) { ToWork.PowerUpdateStructureChange(); } } else if (currentTick == 1) { //This will generate directions for (int i = 0; i < OrderList.Count; i++) { if (!(ALiveSupplies.ContainsKey(OrderList[i]))) { ALiveSupplies[OrderList[i]] = new HashSet <IElectricalNeedUpdate>(); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[OrderList[i]]) { if (NUStructureChangeReact.Contains(TheSupply)) { TheSupply.PowerUpdateStructureChangeReact(); NUStructureChangeReact.Remove(TheSupply); } } } } else if (currentTick == 2) { //Clear resistance and Calculate the resistance for everything foreach (IElectricalNeedUpdate PoweredDevice in InitialiseResistanceChange) { PoweredDevice.InitialPowerUpdateResistance(); } InitialiseResistanceChange.Clear(); foreach (IElectricalNeedUpdate PoweredDevice in ResistanceChange) { PoweredDevice.PowerUpdateResistanceChange(); } ResistanceChange.Clear(); for (int i = 0; i < OrderList.Count; i++) { if (!(ALiveSupplies.ContainsKey(OrderList[i]))) { ALiveSupplies[OrderList[i]] = new HashSet <IElectricalNeedUpdate>(); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[OrderList[i]]) { if (NUResistanceChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply))) { TheSupply.PowerUpdateResistanceChange(); NUResistanceChange.Remove(TheSupply); } } } CircuitResistanceLoop(); } else if (currentTick == 3) { // Clear currents and Calculate the currents And voltage for (int i = 0; i < OrderList.Count; i++) { if (!(ALiveSupplies.ContainsKey(OrderList[i]))) { ALiveSupplies[OrderList[i]] = new HashSet <IElectricalNeedUpdate>(); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[OrderList[i]]) { if (NUCurrentChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)) && !(NUResistanceChange.Contains(TheSupply))) { TheSupply.PowerUpdateCurrentChange(); NUCurrentChange.Remove(TheSupply); } } } } else if (currentTick == 4) { //Sends updates to things that might need it for (int i = 0; i < OrderList.Count; i++) { if (!(ALiveSupplies.ContainsKey(OrderList[i]))) { ALiveSupplies[OrderList[i]] = new HashSet <IElectricalNeedUpdate>(); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[OrderList[i]]) { TheSupply.PowerNetworkUpdate(); } } foreach (IElectricalNeedUpdate ToWork in PoweredDevices) { ToWork.PowerNetworkUpdate(); } } if (ToRemove.Count > 0) { while (ToRemove.Count > 0) { if (ALiveSupplies.ContainsKey(ToRemove[0].TheCategory)) { if (ALiveSupplies[ToRemove[0].TheCategory].Contains(ToRemove[0].device)) { ALiveSupplies[ToRemove[0].TheCategory].Remove(ToRemove[0].device); } } ToRemove.RemoveAt(0); } } currentTick++; if (currentTick > 4) { currentTick = 0; } } }
public static void Update() { if (tickRate == 0) { tickRate = tickRateComplete / 5; } tickCount += Time.deltaTime; if (tickCount > tickRate) { tickCount = 0f; //Logger.Log ("Start up" + currentTick.ToString()); if (StructureChange && (currentTick == 0)) { StructureChange = false; StructureChangeReact = true; foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateStructureChange(); } } // foreach (IElectricalNeedUpdate ToWork in PoweredDevices) { // ToWork.PowerUpdateStructureChange (); // } } else if (StructureChangeReact && (currentTick == 1) && (!StructureChange)) { StructureChangeReact = false; foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateStructureChangeReact(); } } } else if (ResistanceChange && (currentTick == 2) && (!(StructureChange || StructureChangeReact))) { ResistanceChange = false; foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateResistanceChange(); } } } else if (CurrentChange && (currentTick == 3) && (!(StructureChange || StructureChangeReact || ResistanceChange))) { CurrentChange = false; foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateCurrentChange(); } } } else if (currentTick == 4) { foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerNetworkUpdate(); } } foreach (IElectricalNeedUpdate ToWork in PoweredDevices) { ToWork.PowerNetworkUpdate(); } //currentTick = 0; if (ToRemove.Count > 0) { while (ToRemove.Count > 0) { if (ALiveSupplies.ContainsKey(ToRemove[0].TheCategory)) { if (ALiveSupplies [ToRemove[0].TheCategory].Contains(ToRemove[0].device)) { ALiveSupplies [ToRemove[0].TheCategory].Remove(ToRemove[0].device); } } ToRemove.RemoveAt(0); } } } currentTick++; if (currentTick > 4) { currentTick = 0; } } }
public static void Update() //The beating heart { if (!DeadEndSet) { DeadEnd.Categorytype = PowerTypeCategory.DeadEndConnection; //yeah Class stuff DeadEndSet = true; } if (tickRate == 0) { tickRate = tickRateComplete / 5; } tickCount += Time.deltaTime; if (tickCount > tickRate) { tickCount = 0f; if (StructureChange && (currentTick == 0)) { StructureChange = false; StructureChangeReact = true; foreach (PowerTypeCategory ToWork in OrderList) //deals with the connections this will clear them out only { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateStructureChange(); } } foreach (IElectricalNeedUpdate ToWork in PoweredDevices) { ToWork.PowerUpdateStructureChange(); } } else if (StructureChangeReact && (currentTick == 1) && (!StructureChange)) //This will generate directions { StructureChangeReact = false; foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateStructureChangeReact(); } } } else if (ResistanceChange && (currentTick == 2) && (!(StructureChange || StructureChangeReact))) //Clear resistance and Calculate the resistance for everything { ResistanceChange = false; foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateResistanceChange(); } } } else if (CurrentChange && (currentTick == 3) && (!(StructureChange || StructureChangeReact || ResistanceChange))) // Clear currents and Calculate the currents And voltage { CurrentChange = false; foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerUpdateCurrentChange(); } } } else if (currentTick == 4) //Sends updates to things that might need it { foreach (PowerTypeCategory ToWork in OrderList) { if (!(ALiveSupplies.ContainsKey(ToWork))) { ALiveSupplies [ToWork] = new HashSet <IElectricalNeedUpdate> (); } foreach (IElectricalNeedUpdate TheSupply in ALiveSupplies[ToWork]) { TheSupply.PowerNetworkUpdate(); } } foreach (IElectricalNeedUpdate ToWork in PoweredDevices) { ToWork.PowerNetworkUpdate(); } if (ToRemove.Count > 0) { while (ToRemove.Count > 0) { if (ALiveSupplies.ContainsKey(ToRemove[0].TheCategory)) { if (ALiveSupplies [ToRemove[0].TheCategory].Contains(ToRemove[0].device)) { ALiveSupplies [ToRemove[0].TheCategory].Remove(ToRemove[0].device); } } ToRemove.RemoveAt(0); } } } currentTick++; if (currentTick > 4) { currentTick = 0; } } }