Exemplo n.º 1
0
 /// <summary>
 /// Clear  resistance and Calculate the resistance for everything
 /// </summary>
 private static void PowerUpdateResistanceChange()
 {
     //Logger.Log("PowerUpdateResistanceChange/InitialPowerUpdateResistance");
     foreach (PowerSupplyControlInheritance PoweredDevice in InitialiseResistanceChange)
     {
         PoweredDevice.InitialPowerUpdateResistance();
     }
     //Logger.Log("InitialiseResistanceChange");
     InitialiseResistanceChange.Clear();
     foreach (PowerSupplyControlInheritance PoweredDevice in ResistanceChange)
     {
         PoweredDevice.PowerUpdateResistanceChange();
     }
     ResistanceChange.Clear();
     for (int i = 0; i < OrderList.Count; i++)
     {
         foreach (PowerSupplyControlInheritance TheSupply in AliveSupplies[OrderList[i]])
         {
             if (NUResistanceChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)))
             {
                 TheSupply.PowerUpdateResistanceChange();
                 NUResistanceChange.Remove(TheSupply);
             }
         }
     }
     //Logger.Log("CircuitResistanceLoop");
     CircuitResistanceLoop();
 }
    /// <summary>
    /// Clear  resistance and Calculate the resistance for everything
    /// </summary>
    private static void PowerUpdateResistanceChange()
    {
//		Profiler.BeginSample("PowerUpdateResistanceChange");
        //Logger.Log("PowerUpdateResistanceChange/InitialPowerUpdateResistance", Category.Electrical);
        foreach (ElectricalNodeControl PoweredDevice in InitialiseResistanceChange)
        {
            PoweredDevice.InitialPowerUpdateResistance();
        }

        //Logger.Log("InitialiseResistanceChange");
        InitialiseResistanceChange.Clear();
        foreach (ElectricalNodeControl PoweredDevice in ResistanceChange)
        {
            PoweredDevice.PowerUpdateResistanceChange();
        }

        ResistanceChange.Clear();
        for (int i = 0; i < OrderList.Count; i++)
        {
            foreach (ElectricalNodeControl TheSupply in AliveSupplies[OrderList[i]])
            {
                if (NUResistanceChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)))
                {
                    TheSupply.PowerUpdateResistanceChange();
                    //Logger.Log("PowerUpdateResistanceChange " + TheSupply, Category.Electrical);
                    NUResistanceChange.Remove(TheSupply);
                }
            }
        }

        //Logger.Log("CircuitResistanceLoop");
        CircuitResistanceLoop();
//		Profiler.EndSample();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Clear  resistance and Calculate the resistance for everything
    /// </summary>
    private void PowerUpdateResistanceChange()
    {
        foreach (ElectricalNodeControl PoweredDevice in InitialiseResistanceChange)
        {
            PoweredDevice.InitialPowerUpdateResistance();
        }

        InitialiseResistanceChange.Clear();
        foreach (ElectricalNodeControl PoweredDevice in ResistanceChange)
        {
            PoweredDevice.PowerUpdateResistanceChange();
        }

        ResistanceChange.Clear();
        for (int i = 0; i < OrderList.Count; i++)
        {
            foreach (ElectricalNodeControl TheSupply in AliveSupplies[OrderList[i]])
            {
                if (NUResistanceChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)))
                {
                    TheSupply.PowerUpdateResistanceChange();
                    NUResistanceChange.Remove(TheSupply);
                }
            }
        }

        CircuitResistanceLoop();
    }
Exemplo n.º 4
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;
            }
        }
    }