Example #1
0
        public static void ElectricityInput(VIRCurrent current,
                                            ElectricalOIinheritance sourceInstance,
                                            IntrinsicElectronicData comingFrom,
                                            IntrinsicElectronicData thiswire)
        {
            if (thiswire.Data.SupplyDependent.TryGetValue(sourceInstance, out ElectronicSupplyData supplyDep))
            {
                if (supplyDep.CurrentComingFrom.TryGetValue(comingFrom, out VIRCurrent currentComFrom))
                {
                    currentComFrom.addCurrent(current);
                }
                else
                {
                    supplyDep.CurrentComingFrom[comingFrom] = current;
                }

                if (!(supplyDep.ResistanceComingFrom.Count > 0))
                {
                    var sync = ElectricalManager.Instance.electricalSync;
                    sync.StructureChange = true;
                    sync.NUStructureChangeReact.Add(thiswire.ControllingDevice);
                    sync.NUResistanceChange.Add(thiswire.ControllingDevice);
                    sync.NUCurrentChange.Add(thiswire.ControllingDevice);
                    Logger.LogErrorFormat("Resistance isn't initialised on", Category.Electrical);
                    return;
                }

                supplyDep.SourceVoltage = (float)current.Current() * ElectricityFunctions.WorkOutResistance(supplyDep.ResistanceComingFrom);
            }

            //ELCurrent.CurrentWorkOnNextListADD(Thiswire);
            thiswire.ElectricityOutput(current, sourceInstance);
        }
Example #2
0
        public static void ElectricityOutput(VIRCurrent Current,
                                             ElectricalOIinheritance SourceInstance,
                                             IntrinsicElectronicData Thiswire)
        {
            //Logger.Log("4 > " + Current);
            //Logger.Log("poke > " + SourceInstance.InData.Data.SupplyDependent[SourceInstance].ToString());
            var        OutputSupplyingUsingData = Thiswire.Data.SupplyDependent[SourceInstance];
            VIRCurrent SupplyingCurrent         = null;
            float      Divider = (ElectricityFunctions.WorkOutResistance(OutputSupplyingUsingData.ResistanceComingFrom));

            foreach (KeyValuePair <IntrinsicElectronicData, VIRResistances> JumpTo in OutputSupplyingUsingData
                     .ResistanceComingFrom)
            {
                if (OutputSupplyingUsingData.ResistanceComingFrom.Count > 1)
                {
                    SupplyingCurrent = Current.SplitCurrent(Divider / JumpTo.Value.Resistance());
                }
                else
                {
                    SupplyingCurrent = Current;
                }

                OutputSupplyingUsingData.CurrentGoingTo[JumpTo.Key] = SupplyingCurrent;
                if (JumpTo.Key != null && JumpTo.Key.Categorytype != PowerTypeCategory.DeadEndConnection)
                {
                    JumpTo.Key.ElectricityInput(SupplyingCurrent, SourceInstance, Thiswire);
                }
            }
        }
Example #3
0
 ///// <summary>
 /////  Sets the upstream
 ///// </summary>
 public virtual void DirectionInput(ElectricalOIinheritance SourceInstance, IntrinsicElectronicData ComingFrom, CableLine PassOn = null)
 {
     if (Logall)
     {
         Logger.Log("this > " + this + "DirectionInput SourceInstance > " + SourceInstance + " ComingFrom > " + ComingFrom + "  PassOn > " + PassOn, Category.Electrical);
     }
     InputOutputFunctions.DirectionInput(SourceInstance, ComingFrom, InData);
 }
Example #4
0
 public override void ResistancyOutput(ResistanceWrap Resistance, ElectricalOIinheritance SourceInstance)
 {
     Resistance = InData.ControllingDevice.ModifyResistancyOutput(Resistance, SourceInstance);
     if (Logall)
     {
         Logger.Log("this > " + this + "ResistancyOutput, Resistance > " + Resistance + " SourceInstance  > " + SourceInstance, Category.Electrical);
     }
     InputOutputFunctions.ResistancyOutput(Resistance, SourceInstance, InData);
 }
Example #5
0
 public override void ElectricityOutput(VIRCurrent Current,
                                        ElectricalOIinheritance SourceInstance)
 {
     Current = InData.ControllingDevice.ModifyElectricityOutput(Current, SourceInstance);
     if (Logall)
     {
         Logger.Log("this > " + this + "ElectricityOutput, Current > " + Current + " SourceInstance  > " + SourceInstance, Category.Electrical);
     }
     InputOutputFunctions.ElectricityOutput(Current, SourceInstance, InData);
 }
 public static void CleanConnectedDevices(ElectricalOIinheritance Thiswire)
 {
     //Logger.Log ("CleanConnectedDevices" + Thiswire, Category.Electrical);
     foreach (var IsConnectedTo in Thiswire.InData.Data.ResistanceToConnectedDevices)
     {
         IsConnectedTo.Key.Data.connectedDevices.Remove(Thiswire.InData);
         IsConnectedTo.Key.Pool();
     }
     Thiswire.InData.Data.ResistanceToConnectedDevices.Clear();
 }
Example #7
0
 public void SetUp(IntrinsicElectronicData indata)
 {
     Categorytype       = indata.Categorytype;
     ConnectionReaction = indata.ConnectionReaction;
     Present            = indata.Present;
     MetaDataPresent    = indata.MetaDataPresent;
     CanConnectTo       = indata.CanConnectTo;
     WireEndB           = indata.WireEndB;
     WireEndA           = indata.WireEndA;
 }
Example #8
0
 /// <summary>
 /// Passes it on to the next cable
 /// </summary>
 public virtual void ResistancyOutput(ResistanceWrap Resistance, ElectricalOIinheritance SourceInstance)
 {
     if (Logall)
     {
         Logger.Log("this > " + this
                    + "ResistancyOutput, Resistance > " + Resistance
                    + " SourceInstance  > " + SourceInstance, Category.Electrical);
     }
     InputOutputFunctions.ResistancyOutput(Resistance, SourceInstance, InData);
 }
Example #9
0
 /// <summary>
 /// Passes it on to the next cable
 /// </summary>
 public virtual void ResistancyOutput(ResistanceWrap Resistance, ElectricalOIinheritance SourceInstance)
 {
     if (Present != null)
     {
         Present.ResistancyOutput(Resistance, SourceInstance);
     }
     else
     {
         InputOutputFunctions.ResistancyOutput(Resistance, SourceInstance, this);
     }
 }
        public static float WorkOutVoltage(ElectricalOIinheritance ElectricItem)
        {
            float Voltage = 0;

            foreach (var Supply in ElectricItem.InData.Data.SupplyDependent)
            {
                Voltage += Supply.Value.SourceVoltage;
            }

            return(Voltage);
        }
Example #11
0
 /// <summary>
 /// Sets the downstream and pokes the next one along
 /// </summary>
 public virtual void DirectionOutput(ElectricalOIinheritance SourceInstance)
 {
     if (Present != null)
     {
         Present.DirectionOutput(SourceInstance);
     }
     else
     {
         InputOutputFunctions.DirectionOutput(SourceInstance, this);
     }
 }
Example #12
0
 /// <summary>
 ///  Sets the upstream
 /// </summary>
 public virtual void DirectionInput(ElectricalOIinheritance SourceInstance, IntrinsicElectronicData ComingFrom, CableLine PassOn = null)
 {
     if (Present != null)
     {
         Present.DirectionInput(SourceInstance, ComingFrom);
     }
     else
     {
         InputOutputFunctions.DirectionInput(SourceInstance, ComingFrom, this);
     }
 }
Example #13
0
 /// <summary>
 ///The function for out putting current into other nodes (Basically doing ElectricityInput On another one)
 /// </summary>
 public virtual void ElectricityOutput(VIRCurrent Current,
                                       ElectricalOIinheritance SourceInstance)
 {
     if (Logall)
     {
         Logger.Log("this > " + this
                    + "ElectricityOutput, Current > " + Current
                    + " SourceInstance  > " + SourceInstance, Category.Electrical);
     }
     InputOutputFunctions.ElectricityOutput(Current, SourceInstance, InData);
 }
Example #14
0
 /// <summary>
 ///The function for out putting current into other nodes (Basically doing ElectricityInput On another one)
 /// </summary>
 public virtual void ElectricityOutput(VIRCurrent Current,
                                       ElectricalOIinheritance SourceInstance)
 {
     if (Present != null)
     {
         Present.ElectricityOutput(Current, SourceInstance);
     }
     else
     {
         InputOutputFunctions.ElectricityOutput(Current, SourceInstance, this);
     }
 }
Example #15
0
 public void DestroyingThisNow()
 {
     if (Present != null)
     {
         Present.DestroyingThisNow();
         Present = null;
     }
     else
     {
         InternalDestroyingThisNow();
     }
 }
Example #16
0
 /// <summary>
 /// Pass resistance with GameObject of the Machine it is heading toward
 /// </summary>
 public virtual void ResistanceInput(ResistanceWrap Resistance,
                                     ElectricalOIinheritance SourceInstance,
                                     IntrinsicElectronicData ComingFrom)
 {
     if (Logall)
     {
         Logger.Log("this > " + this
                    + "ResistanceInput, Resistance > " + Resistance
                    + " SourceInstance  > " + SourceInstance
                    + " ComingFrom > " + ComingFrom, Category.Electrical);
     }
     InputOutputFunctions.ResistanceInput(Resistance, SourceInstance, ComingFrom, InData);
 }
Example #17
0
 /// <summary>
 /// Pass resistance with GameObject of the Machine it is heading toward
 /// </summary>
 public virtual void ResistanceInput(ResistanceWrap Resistance,
                                     ElectricalOIinheritance SourceInstance,
                                     IntrinsicElectronicData ComingFrom)
 {
     if (Present != null)
     {
         Present.ResistanceInput(Resistance, SourceInstance, ComingFrom);
     }
     else
     {
         InputOutputFunctions.ResistanceInput(Resistance, SourceInstance, ComingFrom, this);
     }
 }
Example #18
0
 /// <summary>
 /// Inputs a current from a device, with the supply
 /// </summary>
 public virtual void ElectricityInput(VIRCurrent Current,
                                      ElectricalOIinheritance SourceInstance,
                                      IntrinsicElectronicData ComingFrom)
 {
     if (Present != null)
     {
         Present.ElectricityInput(Current, SourceInstance, ComingFrom);
     }
     else
     {
         InputOutputFunctions.ElectricityInput(Current, SourceInstance, ComingFrom, this);
     }
 }
Example #19
0
 /// <summary>
 /// Inputs a current from a device, with the supply
 /// </summary>
 public virtual void ElectricityInput(VIRCurrent Current,
                                      ElectricalOIinheritance SourceInstance,
                                      IntrinsicElectronicData ComingFrom)
 {
     if (Logall)
     {
         Logger.Log("this > " + this
                    + "ElectricityInput, Current > " + Current
                    + " SourceInstance  > " + SourceInstance
                    + " ComingFrom > " + ComingFrom, Category.Electrical);
     }
     InputOutputFunctions.ElectricityInput(Current, SourceInstance, ComingFrom, InData);
 }
 public static void FlushResistanceAndUp(IntrinsicElectronicData Object, ElectricalOIinheritance SourceInstance = null)
 {
     if (SourceInstance == null)
     {
         bool pass = false;
         foreach (var Supply in Object.Data.SupplyDependent)
         {
             if (Supply.Value.ResistanceComingFrom.Count > 0)
             {
                 pass = true;
                 break;
             }
         }
         if (pass)
         {
             foreach (var Supply in Object.Data.SupplyDependent)
             {
                 Pool(Supply.Value.ResistanceComingFrom);
                 Pool(Supply.Value.ResistanceGoingTo);
                 Pool(Supply.Value.CurrentGoingTo);
                 Pool(Supply.Value.CurrentComingFrom);
                 Supply.Value.SourceVoltage = 0;
             }
             foreach (IntrinsicElectronicData JumpTo in Object.Data.connections)
             {
                 JumpTo.FlushResistanceAndUp();
             }
             Object.Data.CurrentInWire = 0;
             Object.Data.ActualVoltage = 0;
         }
     }
     else
     {
         ElectronicSupplyData supplyDep = Object.Data.SupplyDependent[SourceInstance];
         if (supplyDep.ResistanceComingFrom.Count > 0 || supplyDep.ResistanceGoingTo.Count > 0)
         {
             Pool(supplyDep.ResistanceComingFrom);
             Pool(supplyDep.ResistanceGoingTo);
             foreach (IntrinsicElectronicData JumpTo in Object.Data.connections)
             {
                 JumpTo.FlushResistanceAndUp(SourceInstance);
             }
             Pool(supplyDep.CurrentGoingTo);
             Pool(supplyDep.CurrentComingFrom);
             supplyDep.SourceVoltage   = 0;
             Object.Data.CurrentInWire = new float();
             Object.Data.ActualVoltage = new float();
         }
     }
 }
Example #21
0
        public static void ResistanceInput(ResistanceWrap Resistance,
                                           ElectricalOIinheritance SourceInstance,
                                           IntrinsicElectronicData ComingFrom,
                                           IntrinsicElectronicData Thiswire)
        {
            if (Thiswire.Data.SupplyDependent.TryGetValue(SourceInstance, out ElectronicSupplyData supplyDep))
            {
                if (!supplyDep.ResistanceComingFrom.TryGetValue(ComingFrom, out VIRResistances resComeFrom))
                {
                    resComeFrom = supplyDep.ResistanceComingFrom[ComingFrom] = ElectricalPool.GetVIRResistances();
                }

                resComeFrom.AddResistance(Resistance);
            }

            Thiswire.ResistancyOutput(Resistance, SourceInstance);
        }
Example #22
0
        public void CircuitSearchLoop(ElectricalOIinheritance wire)
        {
            InputOutputFunctions.DirectionOutput(wire, wire.InData);
            while (true)
            {
                UesAlternativeDirectionWorkOnNextList = false;
                CircuitSearch(wire, _DirectionWorkOnNextList, _DirectionWorkOnNextListWait);

                UesAlternativeDirectionWorkOnNextList = true;
                CircuitSearch(wire, DirectionWorkOnNextList, DirectionWorkOnNextListWait);

                if (DirectionWorkOnNextList.Count <= 0 & DirectionWorkOnNextListWait.Count <= 0 &
                    _DirectionWorkOnNextList.Count <= 0 & _DirectionWorkOnNextListWait.Count <= 0)
                {
                    break;
                }
            }
        }
Example #23
0
        public static void ResistancyOutput(ResistanceWrap Resistance,
                                            ElectricalOIinheritance SourceInstance,
                                            IntrinsicElectronicData Thiswire)
        {
            if (Thiswire.Data.SupplyDependent.TryGetValue(SourceInstance, out ElectronicSupplyData supplyDep))
            {
                foreach (var JumpTo in supplyDep.Upstream)
                {
                    if (!supplyDep.ResistanceGoingTo.TryGetValue(JumpTo, out VIRResistances resGoTo))
                    {
                        resGoTo = supplyDep.ResistanceGoingTo[JumpTo] = ElectricalPool.GetVIRResistances();
                    }

                    resGoTo.AddResistance(Resistance);
                    JumpTo.ResistanceInput(Resistance, SourceInstance, Thiswire);
                }
            }
        }
Example #24
0
        private void CircuitSearch(ElectricalOIinheritance wire,
                                   List <IntrinsicElectronicData> iterateDirectionWorkOnNextList,
                                   List <IntrinsicElectronicData> directionWorkOnNextListWait)
        {
            foreach (var circuit in iterateDirectionWorkOnNextList)
            {
                circuit.DirectionOutput(wire);
            }

            iterateDirectionWorkOnNextList.Clear();
            if (DirectionWorkOnNextList.Count <= 0 && _DirectionWorkOnNextList.Count <= 0)
            {
                foreach (var circuit in directionWorkOnNextListWait)
                {
                    circuit.DirectionOutput(wire);
                }
                directionWorkOnNextListWait.Clear();
            }
        }
 public static void CleanConnectedDevicesFromPower(ElectricalOIinheritance Thiswire)
 {
     //Logger.Log ("CleanConnectedDevicesFromPower" + Thiswire, Category.Electrical);
     foreach (var IsConnectedTo in Thiswire.connectedDevices)
     {
         SupplyBool supplyBool = null;
         foreach (var KeysValleys in IsConnectedTo.Data.ResistanceToConnectedDevices)
         {
             if (KeysValleys.Key.Data == Thiswire)
             {
                 supplyBool = KeysValleys.Key;
                 break;
             }
         }
         if (supplyBool != null)
         {
             IsConnectedTo.Data.ResistanceToConnectedDevices.Remove(supplyBool);
             supplyBool.Pool();
         }
     }
     Thiswire.connectedDevices.Clear();
 }
        public static float WorkOutVoltageFromConnectors(ElectricalOIinheritance ElectricItem,
                                                         HashSet <PowerTypeCategory> SpecifiedDevices)
        {
            float Voltage = 0;

            foreach (var Supply in ElectricItem.InData.Data.SupplyDependent)
            {
                bool pass = false;
                foreach (var subcheck in Supply.Value.CurrentComingFrom)
                {
                    if (SpecifiedDevices.Contains(subcheck.Key.Categorytype))
                    {
                        pass = true;
                        break;
                    }
                }

                if (!pass)
                {
                    foreach (var subcheck in Supply.Value.CurrentGoingTo)
                    {
                        if (SpecifiedDevices.Contains(subcheck.Key.Categorytype))
                        {
                            pass = true;
                            break;
                        }
                    }
                }

                if (pass)
                {
                    Voltage += Supply.Value.SourceVoltage;
                }
            }

            return(Voltage);
        }
Example #27
0
        public static void DirectionOutput(ElectricalOIinheritance SourceInstance,
                                           IntrinsicElectronicData Thiswire,
                                           CableLine RelatedLine = null)
        {
            if (Thiswire.Data.connections.Count == 0)
            {
                Thiswire.FindPossibleConnections();
            }

            if (!(Thiswire.Data.SupplyDependent.TryGetValue(SourceInstance,
                                                            out ElectronicSupplyData outputSupplyingUsingData)))
            {
                outputSupplyingUsingData =
                    Thiswire.Data.SupplyDependent[SourceInstance] = ElectricalPool.GetElectronicSupplyData();
            }

            foreach (IntrinsicElectronicData Relatedindata in Thiswire.Data.connections)
            {
                if (!(outputSupplyingUsingData.Upstream.Contains(Relatedindata)) && (Thiswire != Relatedindata))
                {
                    bool pass = true;
                    if (RelatedLine != null)
                    {
                        if (RelatedLine.Covering.Contains(Relatedindata))
                        {
                            pass = false;
                        }
                    }

                    if (outputSupplyingUsingData.Downstream.Contains(Relatedindata) == false && pass && Relatedindata.Present != SourceInstance)
                    {
                        outputSupplyingUsingData.Downstream.Add(Relatedindata);
                        Relatedindata.DirectionInput(SourceInstance, Thiswire);
                    }
                }
            }
        }
Example #28
0
 public virtual void RemoveSupply(ElectricalOIinheritance SourceInstance = null)
 {
     ElectricalDataCleanup.PowerSupplies.RemoveSupply(this, SourceInstance);
 }
Example #29
0
 /// <summary>
 /// Sets the downstream and pokes the next one along
 /// </summary>
 public virtual void DirectionOutput(ElectricalOIinheritance SourceInstance)
 {
     InputOutputFunctions.DirectionOutput(SourceInstance, InData);
 }
Example #30
0
        public static void DirectionInput(ElectricalOIinheritance SourceInstance,
                                          IntrinsicElectronicData ComingFrom,
                                          IntrinsicElectronicData Thiswire)
        {
            if (Thiswire.Data.connections.Count == 0)
            {
                Thiswire.FindPossibleConnections();                 //plz don't remove it is necessary for preventing incomplete cleanups when there has been multiple
            }

            if (!Thiswire.Data.SupplyDependent.TryGetValue(SourceInstance, out ElectronicSupplyData supplyDep))
            {
                supplyDep = Thiswire.Data.SupplyDependent[SourceInstance] = ElectricalPool.GetElectronicSupplyData();
            }

            if (ComingFrom != null)
            {
                supplyDep.Upstream.Add(ComingFrom);
            }

            if (Thiswire.ConnectionReaction.TryGetValue(ComingFrom.Categorytype, out PowerInputReactions reaction))
            {
                if (reaction.DirectionReaction || reaction.ResistanceReaction)
                {
                    if (SourceInstance != null)
                    {
                        SupplyBool SupplyBool = null;
                        foreach (var keysvasl in Thiswire.Data.ResistanceToConnectedDevices)
                        {
                            if (keysvasl.Key.Equals(SourceInstance))
                            {
                                SupplyBool = keysvasl.Key;
                            }
                        }

                        if (SupplyBool == null)
                        {
                            SupplyBool                = ElectricalPool.GetSupplyBool();
                            SupplyBool.Data           = SourceInstance;
                            SupplyBool.RequiresUpdate = true;
                            Thiswire.Data.ResistanceToConnectedDevices[SupplyBool] =
                                new Dictionary <Resistance, HashSet <IntrinsicElectronicData> >();
                        }

                        var resToConDev = Thiswire.Data.ResistanceToConnectedDevices[SupplyBool];

                        if (!resToConDev.TryGetValue(reaction.ResistanceReactionA.Resistance,
                                                     out HashSet <IntrinsicElectronicData> resToConDevHash))
                        {
                            resToConDevHash = resToConDev[reaction.ResistanceReactionA.Resistance] =
                                new HashSet <IntrinsicElectronicData>();
                        }

                        resToConDevHash.Add(ComingFrom);
                        SupplyBool.RequiresUpdate = true;
                        SourceInstance.connectedDevices.Add(Thiswire);
                        ElectricalManager.Instance.electricalSync.InitialiseResistanceChange
                        .Add(Thiswire.ControllingDevice);
                    }

                    if (reaction.DirectionReactionA.YouShallNotPass)
                    {
                        return;
                    }
                }
            }

            if (Thiswire.Data.connections.Count > 2)
            {
                ElectricalManager.Instance.electricalSync.DirectionWorkOnNextListWaitADD(Thiswire);
            }
            else
            {
                ElectricalManager.Instance.electricalSync.DirectionWorkOnNextListADD(Thiswire);
            }
        }