private static void IfStructureChange()
    {
//		Profiler.BeginSample("IfStructureChange");
        //Logger.Log("PowerUpdateStructureChange", Category.Electrical);
        foreach (CableInheritance cabel in NUCableStructureChange)
        {
            cabel.PowerUpdateStructureChange();             //so Destruction of cables won't trigger the entire thing to refresh saving a bit of performance since they have a bit of code for jumping onto different supplies and  , adding them to NUStructureChangeReact
        }

        NUCableStructureChange.Clear();
        if (!StructureChange)
        {
//			Profiler.EndSample();
            return;
        }

        //Logger.Log("StructureChange bool PowerUpdateStructureChange!",Category.Electrical);
        StructureChange = false;
        foreach (var category in OrderList)
        {
            foreach (ElectricalNodeControl TheSupply in AliveSupplies[category])
            {
                TheSupply.PowerUpdateStructureChange();
            }
        }

        foreach (ElectricalNodeControl ToWork in PoweredDevices)
        {
            ToWork.PowerUpdateStructureChange();
        }

//		Profiler.EndSample();
    }
    private static void IfStructureChange()
    {
        Profiler.BeginSample("IfStructureChange");
        if (!StructureChange)
        {
            return;
        }
        //Logger.Log("PowerUpdateStructureChange");
        StructureChange = false;
        foreach (CableInheritance cabel in NUCableStructureChange)
        {
            cabel.PowerUpdateStructureChange();
        }
        NUCableStructureChange.Clear();
        foreach (var category in OrderList)
        {
            foreach (PowerSupplyControlInheritance TheSupply in AliveSupplies[category])
            {
                TheSupply.PowerUpdateStructureChange();
            }
        }

        foreach (PowerSupplyControlInheritance ToWork in PoweredDevices)
        {
            ToWork.PowerUpdateStructureChange();
        }
        Profiler.EndSample();
    }
Beispiel #3
0
    private static void IfStructureChange()
    {
        if (!StructureChange)
        {
            return;
        }
        //Logger.Log("PowerUpdateStructureChange");
        StructureChange = false;
        foreach (var category in OrderList)
        {
            foreach (PowerSupplyControlInheritance TheSupply in AliveSupplies[category])
            {
                TheSupply.PowerUpdateStructureChange();
            }
        }

        foreach (PowerSupplyControlInheritance ToWork in PoweredDevices)
        {
            ToWork.PowerUpdateStructureChange();
        }
    }
    private void IfStructureChange()
    {
        if (!StructureChange)
        {
            return;
        }
        //Logger.Log("IfStructureChange");
        StructureChange = false;
        foreach (var category in OrderList)
        {
            foreach (ElectricalNodeControl TheSupply in AliveSupplies[category])
            {
                TheSupply.PowerUpdateStructureChange();
            }
        }

        foreach (ElectricalNodeControl ToWork in PoweredDevices)
        {
            ToWork.PowerUpdateStructureChange();
        }

        ElectricalPool.PoolsStatuses();
    }
Beispiel #5
0
    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()       //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;
         }
     }
 }