Exemple #1
0
    public static void CircuitSearchLoop(IElectricityIO Thiswire, IProvidePower ProvidingPower)
    {
        InputOutputFunctions.DirectionOutput(Thiswire.GameObject(), Thiswire);
        bool Break = true;
        List <IElectricityIO> IterateDirectionWorkOnNextList = new List <IElectricityIO>();

        while (Break)
        {
            IterateDirectionWorkOnNextList = new List <IElectricityIO>(ProvidingPower.DirectionWorkOnNextList);
            ProvidingPower.DirectionWorkOnNextList.Clear();
            for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++)
            {
                IterateDirectionWorkOnNextList[i].DirectionOutput(Thiswire.GameObject());
            }
            if (ProvidingPower.DirectionWorkOnNextList.Count <= 0)
            {
                IterateDirectionWorkOnNextList = new List <IElectricityIO>(ProvidingPower.DirectionWorkOnNextListWait);
                ProvidingPower.DirectionWorkOnNextListWait.Clear();
                for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++)
                {
                    IterateDirectionWorkOnNextList[i].DirectionOutput(Thiswire.GameObject());
                }
            }
            if (ProvidingPower.DirectionWorkOnNextList.Count <= 0 && ProvidingPower.DirectionWorkOnNextListWait.Count <= 0)
            {
                //Logger.Log ("stop!");
                Break = false;
            }
        }
    }
Exemple #2
0
 public static void PowerUpdateCurrentChange(IElectricityIO Supply)
 {
     Supply.FlushSupplyAndUp(Supply.GameObject());
     if (Supply.connectedDevices.Count > 0)
     {
         if (Supply.Data.SupplyingCurrent != 0)
         {
             Supply.ElectricityOutput(Supply.Data.SupplyingCurrent, Supply.GameObject());
         }
         else if (Supply.Data.SupplyingVoltage != 0)
         {
             int SourceInstanceID = Supply.GameObject().GetInstanceID();
             Supply.ElectricityOutput((Supply.Data.SupplyingVoltage) / (Supply.Data.InternalResistance + ElectricityFunctions.WorkOutResistance(Supply.Data.ResistanceComingFrom[SourceInstanceID])), Supply.GameObject());
         }
     }
 }
    public static void ElectricityOutput(int tick, float Current, GameObject SourceInstance, IElectricityIO Thiswire)
    {
        int   SourceInstanceID = SourceInstance.GetInstanceID();
        float SimplyTimesBy    = 0;
        float SupplyingCurrent = 0;

        Dictionary <IElectricityIO, float> ThiswireResistance = new Dictionary <IElectricityIO, float>();

        if (Thiswire.ResistanceComingFrom.ContainsKey(SourceInstanceID))
        {
            ThiswireResistance = Thiswire.ResistanceComingFrom[SourceInstanceID];
            //Logger.Log ("It does", Category.Electrical);
        }
        else
        {
            Logger.LogError("now It doesn't" + SourceInstanceID.ToString() + " with this " + Thiswire.GameObject().name.ToString(), Category.Electrical);
        }

        float Voltage = Current * (ElectricityFunctions.WorkOutResistance(ThiswireResistance));

        if (Thiswire.ResistanceComingFrom[SourceInstanceID].Count > 1)
        {
            float CurrentAll = 0;
            foreach (KeyValuePair <IElectricityIO, float> JumpTo in Thiswire.ResistanceComingFrom[SourceInstanceID])
            {
                if (!(SourceInstance == Thiswire.GameObject()))
                {
                    CurrentAll += Voltage / JumpTo.Value;
                }
            }
            SimplyTimesBy = Current / CurrentAll;
        }
        foreach (KeyValuePair <IElectricityIO, float> JumpTo in Thiswire.ResistanceComingFrom[SourceInstanceID])
        {
            if (JumpTo.Key.Categorytype != PowerTypeCategory.DeadEndConnection)
            {
                //bool DirectionBool = ElectricityFunctions.CalculateDirectionBool (Thiswire, JumpTo.Key);
                if (SimplyTimesBy > 0)
                {
                    SupplyingCurrent = SimplyTimesBy * (Voltage / ElectricityFunctions.WorkOutResistance(JumpTo.Key.ResistanceComingFrom [SourceInstanceID]));
                }
                else
                {
                    SupplyingCurrent = Current;
                }
                if (!(Thiswire.CurrentGoingTo.ContainsKey(SourceInstanceID)))
                {
                    Thiswire.CurrentGoingTo [SourceInstanceID] = new Dictionary <IElectricityIO, float> ();
                }
                Thiswire.CurrentGoingTo [SourceInstanceID] [JumpTo.Key] = SupplyingCurrent;

                JumpTo.Key.ElectricityInput(tick, SupplyingCurrent, SourceInstance, Thiswire);
            }
        }
        //Thiswire.ActualCurrentChargeInWire = ElectricityFunctions.WorkOutActualNumbers (Thiswire); //Maybe something akin tos
    }
Exemple #4
0
 public static void PowerUpdateStructureChangeReact(IElectricityIO Supply)
 {
     ElectricityFunctions.CircuitSearchLoop(Supply, Supply.GameObject().GetComponent <IProvidePower>());
     if (Supply.Data.ChangeToOff)
     {
         Supply.Data.ChangeToOff = false;
         TurnOffSupply(Supply);
         Supply.InData.ControllingDevice.TurnOffCleanup();
         ElectricalSynchronisation.RemoveSupply(Supply.InData.ControllingUpdate, Supply.InData.Categorytype);
     }
 }
 public static void PowerUpdateCurrentChange(IElectricityIO Supply)
 {
     Supply.FlushSupplyAndUp(Supply.GameObject());
     if (Supply.connectedDevices.Count > 0)
     {
         if (Supply.Data.SupplyingCurrent != 0)
         {
             Supply.ElectricityOutput(ElectricalSynchronisation.currentTick, Supply.Data.SupplyingCurrent, Supply.GameObject());
         }
     }
 }
Exemple #6
0
public static class PowerSupplyFunction {  //Responsible for keeping the update and day to clean up off the supply in check
    public static void TurnOffSupply(IElectricityIO Supply)
    {
        Supply.RemoveSupply(Supply.GameObject());
        ElectricalSynchronisation.NUCurrentChange.Add(Supply.InData.ControllingUpdate);
    }
    public static void ElectricityOutput(int tick, float Current, GameObject SourceInstance, IElectricityIO Thiswire)
    {
        int   SourceInstanceID = SourceInstance.GetInstanceID();
        float SimplyTimesBy    = 0;
        float SupplyingCurrent = 0;
        Dictionary <IElectricityIO, float> ThiswireResistance = new Dictionary <IElectricityIO, float>();

        if (Thiswire.Data.ResistanceComingFrom.ContainsKey(SourceInstanceID))
        {
            ThiswireResistance = Thiswire.Data.ResistanceComingFrom[SourceInstanceID];
        }
        else
        {
            Logger.LogError("now It doesn't" + SourceInstanceID.ToString() + " with this " + Thiswire.GameObject().name.ToString(), Category.Electrical);
        }
        float Voltage = Current * (ElectricityFunctions.WorkOutResistance(ThiswireResistance));

        foreach (KeyValuePair <IElectricityIO, float> JumpTo in Thiswire.Data.ResistanceComingFrom[SourceInstanceID])
        {
            if (Voltage > 0)
            {
                SupplyingCurrent = (Voltage / JumpTo.Value);
            }
            else
            {
                SupplyingCurrent = Current;
            }
            if (!(Thiswire.Data.CurrentGoingTo.ContainsKey(SourceInstanceID)))
            {
                Thiswire.Data.CurrentGoingTo [SourceInstanceID] = new Dictionary <IElectricityIO, float> ();
            }
            Thiswire.Data.CurrentGoingTo [SourceInstanceID] [JumpTo.Key] = SupplyingCurrent;
            JumpTo.Key.ElectricityInput(tick, SupplyingCurrent, SourceInstance, Thiswire);
        }
    }
 public static void RemoveSupply(IElectricityIO Object, GameObject SourceInstance = null)
 {
     if (SourceInstance == null)
     {
         if (Object.Data.Downstream.Count > 0 || Object.Data.Upstream.Count > 0)
         {
             Object.Data.Downstream.Clear();
             Object.Data.Upstream.Clear();
             Object.Data.FirstPresent = new int();
             foreach (IElectricityIO JumpTo in Object.Data.connections)
             {
                 JumpTo.RemoveSupply();
             }
             Object.Data.Upstream.Clear();
             Object.Data.SourceVoltages.Clear();
             Object.Data.ResistanceGoingTo.Clear();
             Object.Data.ResistanceComingFrom.Clear();
             Object.Data.CurrentGoingTo.Clear();
             Object.Data.CurrentComingFrom.Clear();
             Object.Data.SourceVoltages.Clear();
             Object.Data.CurrentInWire       = new float();
             Object.Data.ActualVoltage       = new float();
             Object.Data.EstimatedResistance = new float();
             Object.Data.UpstreamCount       = new int();
             Object.Data.DownstreamCount     = new int();
             Object.Data.ResistanceToConnectedDevices.Clear();
             Object.connectedDevices.Clear();
         }
     }
     else
     {
         int InstanceID = SourceInstance.GetInstanceID();
         if (Object.Data.Downstream.ContainsKey(InstanceID))
         {
             Object.Data.Downstream.Remove(InstanceID);
             if (Object.Data.FirstPresent == InstanceID)
             {
                 Object.Data.FirstPresent = new int();
             }
             foreach (IElectricityIO JumpTo in Object.Data.connections)
             {
                 JumpTo.RemoveSupply(SourceInstance);
             }
             if (InstanceID == Object.GameObject().GetInstanceID())
             {
                 CleanConnectedDevicesFromPower(Object);
                 Object.Data.ResistanceToConnectedDevices.Clear();
             }
             Object.Data.Upstream.Remove(InstanceID);
             Object.Data.SourceVoltages.Remove(InstanceID);
             Object.Data.ResistanceGoingTo.Remove(InstanceID);
             Object.Data.ResistanceComingFrom.Remove(InstanceID);
             Object.Data.CurrentGoingTo.Remove(InstanceID);
             Object.Data.CurrentComingFrom.Remove(InstanceID);
             Object.Data.SourceVoltages.Remove(InstanceID);
             Object.Data.ActualCurrentChargeInWire = ElectricityFunctions.WorkOutActualNumbers(Object);;
             Object.Data.CurrentInWire             = Object.Data.ActualCurrentChargeInWire.Current;
             Object.Data.ActualVoltage             = Object.Data.ActualCurrentChargeInWire.Voltage;
             Object.Data.EstimatedResistance       = Object.Data.ActualCurrentChargeInWire.EstimatedResistant;
             Object.Data.UpstreamCount             = new int();
             Object.Data.DownstreamCount           = new int();
         }
     }
 }
Exemple #9
0
    public static void CircuitResistanceLoop(IElectricityIO Thiswire, IProvidePower ProvidingPower)
    {
        bool Break = true;
        List <IElectricityIO> IterateDirectionWorkOnNextList = new List <IElectricityIO> ();

        while (Break)
        {
            IterateDirectionWorkOnNextList = new List <IElectricityIO> (ProvidingPower.ResistanceWorkOnNextList);
            ProvidingPower.ResistanceWorkOnNextList.Clear();
            for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++)
            {
                IterateDirectionWorkOnNextList [i].ResistancyOutput(ElectricalSynchronisation.currentTick, Thiswire.GameObject());
            }
            if (ProvidingPower.ResistanceWorkOnNextList.Count <= 0)
            {
                IterateDirectionWorkOnNextList = new List <IElectricityIO> (ProvidingPower.ResistanceWorkOnNextListWait);
                ProvidingPower.ResistanceWorkOnNextListWait.Clear();
                for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++)
                {
                    IterateDirectionWorkOnNextList [i].ResistancyOutput(ElectricalSynchronisation.currentTick, Thiswire.GameObject());
                }
            }
            if (ProvidingPower.ResistanceWorkOnNextList.Count <= 0 && ProvidingPower.ResistanceWorkOnNextListWait.Count <= 0)
            {
                Break = false;
            }
        }
    }
        public static void RemoveSupply(IElectricityIO Object, GameObject SourceInstance = null)
        {
            if (SourceInstance == null)
            {
                if (Object.Downstream.Count > 0 || Object.Upstream.Count > 0)
                {
                    Object.Downstream.Clear();
                    Object.Upstream.Clear();
                    Object.FirstPresent = new int();
                    foreach (IElectricityIO JumpTo in Object.connections)
                    {
                        JumpTo.RemoveSupply();
                    }
                    Object.Upstream.Clear();
                    Object.SourceVoltages.Clear();
                    Object.ResistanceGoingTo.Clear();
                    Object.ResistanceComingFrom.Clear();
                    Object.CurrentGoingTo.Clear();
                    Object.CurrentComingFrom.Clear();
                    Object.SourceVoltages.Clear();

                    Object.CurrentInWire       = new float();
                    Object.ActualVoltage       = new float();
                    Object.EstimatedResistance = new float();

                    //VisibleResistance = new float ();
                    Object.UpstreamCount   = new int();
                    Object.DownstreamCount = new int();
                    Object.ResistanceToConnectedDevices.Clear();
                    Object.connectedDevices.Clear();
                }
            }
            else
            {
                int InstanceID = SourceInstance.GetInstanceID();
                if (Object.Downstream.ContainsKey(InstanceID))
                {
                    Object.Downstream.Remove(InstanceID);
                    if (Object.FirstPresent == InstanceID)
                    {
                        Object.FirstPresent = new int();
                    }
                    foreach (IElectricityIO JumpTo in Object.connections)
                    {
                        JumpTo.RemoveSupply(SourceInstance);
                    }
                    if (InstanceID == Object.GameObject().GetInstanceID())
                    {
                        CleanConnectedDevicesFromPower(Object);
                        Object.ResistanceToConnectedDevices.Clear();
                        //Object.connectedDevices.Clear();
                    }
                    Object.Upstream.Remove(InstanceID);
                    Object.SourceVoltages.Remove(InstanceID);
                    Object.ResistanceGoingTo.Remove(InstanceID);
                    Object.ResistanceComingFrom.Remove(InstanceID);
                    Object.CurrentGoingTo.Remove(InstanceID);
                    Object.CurrentComingFrom.Remove(InstanceID);
                    //Logger.Log (SourceVoltages.Count.ToString() + "yes");
                    Object.SourceVoltages.Remove(InstanceID);

                    Object.ActualCurrentChargeInWire = ElectricityFunctions.WorkOutActualNumbers(Object);
                    //				foreach (KeyValuePair<int, Dictionary<IElectricityIO,float>> CurrentIDItem in CurrentComingFrom) {
                    //					Logger.Log (CurrentIDItem.Key.ToString() + " CurrentComingFrom sdd > " + InstanceID.ToString()  );
                    //				}
                    //				foreach (KeyValuePair<int, Dictionary<IElectricityIO,float>> CurrentIDItem in CurrentGoingTo) {
                    //					Logger.Log (CurrentIDItem.Key.ToString() + " CurrentGoingTo sdd > " + InstanceID.ToString() );
                    //					//foreach (KeyValuePair<IElectricityIO,float> CurrentItem in CurrentIDItem.Value) {
                    //					//}
                    //
                    //				}

                    //Logger.Log(ActualCurrentChargeInWire.Current.ToString()+ "yoyoyoyoyyoyoyooy");
                    Object.CurrentInWire       = Object.ActualCurrentChargeInWire.Current;
                    Object.ActualVoltage       = Object.ActualCurrentChargeInWire.Voltage;
                    Object.EstimatedResistance = Object.ActualCurrentChargeInWire.EstimatedResistant;

                    //VisibleResistance = new float ();
                    Object.UpstreamCount   = new int();
                    Object.DownstreamCount = new int();
                }
            }
        }